Version 1
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Menu / MenuLinkTreeElementTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Menu;
4
5 use Drupal\Core\Menu\MenuLinkTreeElement;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * Tests the menu link tree element value object.
10  *
11  * @group Menu
12  *
13  * @coversDefaultClass \Drupal\Core\Menu\MenuLinkTreeElement
14  */
15 class MenuLinkTreeElementTest extends UnitTestCase {
16
17   /**
18    * Tests construction.
19    *
20    * @covers ::__construct
21    */
22   public function testConstruction() {
23     $link = MenuLinkMock::create(['id' => 'test']);
24     $item = new MenuLinkTreeElement($link, FALSE, 3, FALSE, []);
25     $this->assertSame($link, $item->link);
26     $this->assertSame(FALSE, $item->hasChildren);
27     $this->assertSame(3, $item->depth);
28     $this->assertSame(FALSE, $item->inActiveTrail);
29     $this->assertSame([], $item->subtree);
30   }
31
32   /**
33    * Tests count().
34    *
35    * @covers ::count
36    */
37   public function testCount() {
38     $link_1 = MenuLinkMock::create(['id' => 'test_1']);
39     $link_2 = MenuLinkMock::create(['id' => 'test_2']);
40     $child_item = new MenuLinkTreeElement($link_2, FALSE, 2, FALSE, []);
41     $parent_item = new MenuLinkTreeElement($link_1, FALSE, 2, FALSE, [$child_item]);
42     $this->assertSame(1, $child_item->count());
43     $this->assertSame(2, $parent_item->count());
44   }
45
46 }