You are here

public function LocalActionManagerTest::testGetActionsForRoute in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 148
Contains \Drupal\Tests\Core\Menu\LocalActionManagerTest.

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')
    ->will($this
    ->returnValue($plugin_definitions));
  $map = array();
  foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
    $plugin = $this
      ->getMock('Drupal\\Core\\Menu\\LocalActionInterface');
    $plugin
      ->expects($this
      ->any())
      ->method('getRouteName')
      ->will($this
      ->returnValue($plugin_definition['route_name']));
    $plugin
      ->expects($this
      ->any())
      ->method('getRouteParameters')
      ->will($this
      ->returnValue(isset($plugin_definition['route_parameters']) ? $plugin_definition['route_parameters'] : array()));
    $plugin
      ->expects($this
      ->any())
      ->method('getTitle')
      ->will($this
      ->returnValue($plugin_definition['title']));
    $this->controllerResolver
      ->expects($this
      ->any())
      ->method('getArguments')
      ->with($this->request, array(
      $plugin,
      'getTitle',
    ))
      ->will($this
      ->returnValue(array()));
    $plugin
      ->expects($this
      ->any())
      ->method('getWeight')
      ->will($this
      ->returnValue($plugin_definition['weight']));
    $this->controllerResolver
      ->expects($this
      ->any())
      ->method('getArguments')
      ->with($this->request, array(
      $plugin,
      'getTitle',
    ))
      ->will($this
      ->returnValue(array()));
    $map[] = array(
      $plugin_id,
      array(),
      $plugin,
    );
  }
  $this->factory
    ->expects($this
    ->any())
    ->method('createInstance')
    ->will($this
    ->returnValueMap($map));
  $this
    ->assertEquals($expected_actions, $this->localActionManager
    ->getActionsForRoute($route_appears));
}