You are here

public function MenuActiveTrailTest::testGetActiveTrailIds in Drupal 8

Same name and namespace in other branches
  1. 9 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 162

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) {
  $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')
      ->will($this
      ->returnValue($links));
    if ($expected_link !== NULL) {
      $this->menuLinkManager
        ->expects($this
        ->exactly(2))
        ->method('getParentIds')
        ->will($this
        ->returnValueMap([
        [
          $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));
}