function LocalActionManagerTest::testGetActionsForRoute

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

@covers ::getActionsForRoute

@dataProvider getActionsForRouteProvider

File

core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php, line 159

Class

LocalActionManagerTest
@coversDefaultClass \Drupal\Core\Menu\LocalActionManager @group Menu

Namespace

Drupal\Tests\Core\Menu

Code

public function testGetActionsForRoute($route_appears, array $plugin_definitions, array $expected_actions) {
    $this->discovery
        ->expects($this->any())
        ->method('getDefinitions')
        ->willReturn($plugin_definitions);
    $map = [];
    foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
        $plugin = $this->createMock('Drupal\\Core\\Menu\\LocalActionInterface');
        $plugin->expects($this->any())
            ->method('getRouteName')
            ->willReturn($plugin_definition['route_name']);
        $plugin->expects($this->any())
            ->method('getRouteParameters')
            ->willReturn($plugin_definition['route_parameters'] ?? []);
        $plugin->expects($this->any())
            ->method('getTitle')
            ->willReturn($plugin_definition['title']);
        $this->argumentResolver
            ->expects($this->any())
            ->method('getArguments')
            ->with($this->request, [
            $plugin,
            'getTitle',
        ])
            ->willReturn([]);
        $plugin->expects($this->any())
            ->method('getWeight')
            ->willReturn($plugin_definition['weight']);
        $this->argumentResolver
            ->expects($this->any())
            ->method('getArguments')
            ->with($this->request, [
            $plugin,
            'getTitle',
        ])
            ->willReturn([]);
        $map[] = [
            $plugin_id,
            [],
            $plugin,
        ];
    }
    $this->factory
        ->expects($this->any())
        ->method('createInstance')
        ->willReturnMap($map);
    $this->assertEquals($expected_actions, $this->localActionManager
        ->getActionsForRoute($route_appears));
}

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