MenuLinkTreeElement example


class MenuLinkTreeElementTest extends UnitTestCase {

  /** * Tests construction. * * @covers ::__construct */
  public function testConstruction() {
    $link = MenuLinkMock::create(['id' => 'test']);
    $item = new MenuLinkTreeElement($link, FALSE, 3, FALSE, []);
    $this->assertSame($link$item->link);
    $this->assertFalse($item->hasChildren);
    $this->assertSame(3, $item->depth);
    $this->assertFalse($item->inActiveTrail);
    $this->assertSame([]$item->subtree);
  }

  /** * Tests count(). * * @covers ::count */
1 => MenuLinkMock::create(['id' => 'test.example1', 'route_name' => 'example1', 'title' => 'foo', 'parent' => '']),
      2 => MenuLinkMock::create(['id' => 'test.example2', 'route_name' => 'example2', 'title' => 'bar', 'parent' => 'test.example1', 'route_parameters' => ['foo' => 'bar']]),
      3 => MenuLinkMock::create(['id' => 'test.example3', 'route_name' => 'example3', 'title' => 'baz', 'parent' => 'test.example2', 'route_parameters' => ['baz' => 'qux']]),
      4 => MenuLinkMock::create(['id' => 'test.example4', 'route_name' => 'example4', 'title' => 'qux', 'parent' => 'test.example3']),
      5 => MenuLinkMock::create(['id' => 'test.example5', 'route_name' => 'example5', 'title' => 'foofoo', 'parent' => '']),
      6 => MenuLinkMock::create(['id' => 'test.example6', 'route_name' => '', 'url' => 'https://www.drupal.org/', 'title' => 'barbar', 'parent' => '']),
      7 => MenuLinkMock::create(['id' => 'test.example7', 'route_name' => 'example7', 'title' => 'bazbaz', 'parent' => '']),
      8 => MenuLinkMock::create(['id' => 'test.example8', 'route_name' => 'example8', 'title' => 'quxqux', 'parent' => '']),
      9 => DynamicMenuLinkMock::create(['id' => 'test.example9', 'parent' => ''])->setCurrentUser($this->currentUser),
    ];
    $this->originalTree = [];
    $this->originalTree[1] = new MenuLinkTreeElement($this->links[1], FALSE, 1, FALSE, []);
    $this->originalTree[2] = new MenuLinkTreeElement($this->links[2], TRUE, 1, FALSE, [
      3 => new MenuLinkTreeElement($this->links[3], TRUE, 2, FALSE, [
        4 => new MenuLinkTreeElement($this->links[4], FALSE, 3, FALSE, []),
      ]),
    ]);
    $this->originalTree[5] = new MenuLinkTreeElement($this->links[5], TRUE, 1, FALSE, [
      7 => new MenuLinkTreeElement($this->links[7], FALSE, 2, FALSE, []),
    ]);
    $this->originalTree[6] = new MenuLinkTreeElement($this->links[6], FALSE, 1, FALSE, []);
    $this->originalTree[8] = new MenuLinkTreeElement($this->links[8], FALSE, 1, FALSE, []);
    $this->originalTree[9] = new MenuLinkTreeElement($this->links[9], FALSE, 1, FALSE, []);
  }
'access_cache_contexts' => [],
    ];

    for ($i = 0; $i < count($access_scenarios)$i++) {
      [$access$access_cache_contexts] = $access_scenarios[$i];

      for ($j = 0; $j < count($links_scenarios)$j++) {
        $links = $links_scenarios[$j];

        // Single-element tree.         $tree = [
          new MenuLinkTreeElement($links[0], FALSE, 0, FALSE, []),
        ];
        $tree[0]->access = $access;
        if ($access === NULL || $access->isAllowed()) {
          $expected_build = $base_expected_build;
          $expected_build['#items']['test.example1'] = $get_built_element($tree[0]);
        }
        else {
          $expected_build = $base_expected_build_empty;
        }
        $expected_build['#cache']['contexts'] = array_merge($expected_build['#cache']['contexts']$access_cache_contexts$links[0]->getCacheContexts());
        $data[] = [
          

  protected function createInstances(array $data_tree) {
    $tree = [];
    foreach ($data_tree as $key => $element) {
      $subtree = $this->createInstances($element['subtree']);
      // Build a MenuLinkTreeElement out of the menu tree link definition:       // transform the tree link definition into a link definition and store       // tree metadata.       $tree[$key] = new MenuLinkTreeElement(
        $this->menuLinkManager->createInstance($element['definition']['id']),
        (bool) $element['has_children'],
        (int) $element['depth'],
        (bool) $element['in_active_trail'],
        $subtree
      );
    }
    return $tree;
  }

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.