function MenuActiveTrailTest::testGetActiveTrailIds

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Menu/MenuActiveTrailTest.php \Drupal\Tests\Core\Menu\MenuActiveTrailTest::testGetActiveTrailIds()
  2. 8.9.x core/tests/Drupal/Tests/Core/Menu/MenuActiveTrailTest.php \Drupal\Tests\Core\Menu\MenuActiveTrailTest::testGetActiveTrailIds()
  3. 10 core/tests/Drupal/Tests/Core/Menu/MenuActiveTrailTest.php \Drupal\Tests\Core\Menu\MenuActiveTrailTest::testGetActiveTrailIds()

Tests getActiveTrailIds().

@covers ::getActiveTrailIds @dataProvider provider

File

core/tests/Drupal/Tests/Core/Menu/MenuActiveTrailTest.php, line 165

Class

MenuActiveTrailTest
Tests the active menu trail service.

Namespace

Drupal\Tests\Core\Menu

Code

public function testGetActiveTrailIds(Request $request, $links, $menu_name, $expected_link, $expected_trail) : void {
    $expected_trail_ids = array_combine($expected_trail, $expected_trail);
    $this->requestStack
        ->push($request);
    if ($links !== FALSE) {
        // We expect exactly two calls, one for the first call, and one after the
        // cache clearing below.
        $this->menuLinkManager
            ->expects($this->exactly(2))
            ->method('loadLinksByRoute')
            ->with('baby_llama')
            ->willReturn($links);
        if ($expected_link !== NULL) {
            $this->menuLinkManager
                ->expects($this->exactly(2))
                ->method('getParentIds')
                ->willReturnMap([
                [
                    $expected_link->getPluginId(),
                    $expected_trail_ids,
                ],
            ]);
        }
    }
    // Call out the same twice in order to ensure that static caching works.
    $this->assertSame($expected_trail_ids, $this->menuActiveTrail
        ->getActiveTrailIds($menu_name));
    $this->assertSame($expected_trail_ids, $this->menuActiveTrail
        ->getActiveTrailIds($menu_name));
    $this->menuActiveTrail
        ->clear();
    $this->assertSame($expected_trail_ids, $this->menuActiveTrail
        ->getActiveTrailIds($menu_name));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.