class LocalActionManagerTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Menu/LocalActionManagerTest.php \Drupal\Tests\Core\Menu\LocalActionManagerTest
@coversDefaultClass \Drupal\Core\Menu\LocalActionManager @group Menu
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Menu\LocalActionManagerTest
Expanded class hierarchy of LocalActionManagerTest
File
- core/
tests/ Drupal/ Tests/ Core/ Menu/ LocalActionManagerTest.php, line 31 - Contains \Drupal\Tests\Core\Menu\LocalActionManagerTest.
Namespace
Drupal\Tests\Core\MenuView source
class LocalActionManagerTest extends UnitTestCase {
/**
* The mocked controller resolver.
*
* @var \Drupal\Core\Controller\ControllerResolverInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $controllerResolver;
/**
* The mocked request.
*
* @var \Symfony\Component\HttpFoundation\Request|\PHPUnit_Framework_MockObject_MockObject
*/
protected $request;
/**
* The mocked module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $moduleHandler;
/**
* The mocked router provider.
*
* @var \Drupal\Core\Routing\RouteProviderInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $routeProvider;
/**
* The mocked cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $cacheBackend;
/**
* The mocked access manager.
*
* @var \Drupal\Core\Access\AccessManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $accessManager;
/**
* The mocked account.
*
* @var \Drupal\Core\Session\AccountInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $account;
/**
* The mocked factory.
*
* @var \Drupal\Component\Plugin\Factory\FactoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $factory;
/**
* The mocked plugin discovery.
*
* @var \Drupal\Component\Plugin\Discovery\DiscoveryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $discovery;
/**
* The tested local action manager
*
* @var \Drupal\Tests\Core\Menu\TestLocalActionManager
*/
protected $localActionManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->controllerResolver = $this
->getMock('Drupal\\Core\\Controller\\ControllerResolverInterface');
$this->request = $this
->getMock('Symfony\\Component\\HttpFoundation\\Request');
$this->routeProvider = $this
->getMock('Drupal\\Core\\Routing\\RouteProviderInterface');
$this->moduleHandler = $this
->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
$this->cacheBackend = $this
->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$access_result = new AccessResultForbidden();
$this->accessManager = $this
->getMock('Drupal\\Core\\Access\\AccessManagerInterface');
$this->accessManager
->expects($this
->any())
->method('checkNamedRoute')
->willReturn($access_result);
$this->account = $this
->getMock('Drupal\\Core\\Session\\AccountInterface');
$this->discovery = $this
->getMock('Drupal\\Component\\Plugin\\Discovery\\DiscoveryInterface');
$this->factory = $this
->getMock('Drupal\\Component\\Plugin\\Factory\\FactoryInterface');
$route_match = $this
->getMock('Drupal\\Core\\Routing\\RouteMatchInterface');
$this->localActionManager = new TestLocalActionManager($this->controllerResolver, $this->request, $route_match, $this->routeProvider, $this->moduleHandler, $this->cacheBackend, $this->accessManager, $this->account, $this->discovery, $this->factory);
}
/**
* @covers ::getTitle
*/
public function testGetTitle() {
$local_action = $this
->getMock('Drupal\\Core\\Menu\\LocalActionInterface');
$local_action
->expects($this
->once())
->method('getTitle')
->with('test');
$this->controllerResolver
->expects($this
->once())
->method('getArguments')
->with($this->request, array(
$local_action,
'getTitle',
))
->will($this
->returnValue(array(
'test',
)));
$this->localActionManager
->getTitle($local_action);
}
/**
* @covers ::getActionsForRoute
*
* @dataProvider getActionsForRouteProvider
*/
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));
}
public function getActionsForRouteProvider() {
// Single available and single expected plugins.
$data[] = array(
'test_route',
array(
'plugin_id_1' => array(
'appears_on' => array(
'test_route',
),
'route_name' => 'test_route_2',
'title' => 'Plugin ID 1',
'weight' => 0,
),
),
array(
'plugin_id_1' => array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => 'Plugin ID 1',
'url' => Url::fromRoute('test_route_2'),
'localized_options' => '',
),
'#access' => AccessResult::forbidden(),
'#weight' => 0,
),
),
);
// Multiple available and single expected plugins.
$data[] = array(
'test_route',
array(
'plugin_id_1' => array(
'appears_on' => array(
'test_route',
),
'route_name' => 'test_route_2',
'title' => 'Plugin ID 1',
'weight' => 0,
),
'plugin_id_2' => array(
'appears_on' => array(
'test_route2',
),
'route_name' => 'test_route_3',
'title' => 'Plugin ID 2',
'weight' => 0,
),
),
array(
'plugin_id_1' => array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => 'Plugin ID 1',
'url' => Url::fromRoute('test_route_2'),
'localized_options' => '',
),
'#access' => AccessResult::forbidden(),
'#weight' => 0,
),
),
);
// Multiple available and multiple expected plugins and specified weight.
$data[] = array(
'test_route',
array(
'plugin_id_1' => array(
'appears_on' => array(
'test_route',
),
'route_name' => 'test_route_2',
'title' => 'Plugin ID 1',
'weight' => 1,
),
'plugin_id_2' => array(
'appears_on' => array(
'test_route',
),
'route_name' => 'test_route_3',
'title' => 'Plugin ID 2',
'weight' => 0,
),
),
array(
'plugin_id_1' => array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => 'Plugin ID 1',
'url' => Url::fromRoute('test_route_2'),
'localized_options' => '',
),
'#access' => AccessResult::forbidden(),
'#weight' => 1,
),
'plugin_id_2' => array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => 'Plugin ID 2',
'url' => Url::fromRoute('test_route_3'),
'localized_options' => '',
),
'#access' => AccessResult::forbidden(),
'#weight' => 0,
),
),
);
// Two plugins with the same route name but different route parameters.
$data[] = array(
'test_route',
array(
'plugin_id_1' => array(
'appears_on' => array(
'test_route',
),
'route_name' => 'test_route_2',
'route_parameters' => array(
'test1',
),
'title' => 'Plugin ID 1',
'weight' => 1,
),
'plugin_id_2' => array(
'appears_on' => array(
'test_route',
),
'route_name' => 'test_route_2',
'route_parameters' => array(
'test2',
),
'title' => 'Plugin ID 2',
'weight' => 0,
),
),
array(
'plugin_id_1' => array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => 'Plugin ID 1',
'url' => Url::fromRoute('test_route_2', [
'test1',
]),
'localized_options' => '',
),
'#access' => AccessResult::forbidden(),
'#weight' => 1,
),
'plugin_id_2' => array(
'#theme' => 'menu_local_action',
'#link' => array(
'title' => 'Plugin ID 2',
'url' => Url::fromRoute('test_route_2', [
'test2',
]),
'localized_options' => '',
),
'#access' => AccessResult::forbidden(),
'#weight' => 0,
),
),
);
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LocalActionManagerTest:: |
protected | property | The mocked access manager. | |
LocalActionManagerTest:: |
protected | property | The mocked account. | |
LocalActionManagerTest:: |
protected | property | The mocked cache backend. | |
LocalActionManagerTest:: |
protected | property | The mocked controller resolver. | |
LocalActionManagerTest:: |
protected | property | The mocked plugin discovery. | |
LocalActionManagerTest:: |
protected | property | The mocked factory. | |
LocalActionManagerTest:: |
protected | property | The tested local action manager | |
LocalActionManagerTest:: |
protected | property | The mocked module handler. | |
LocalActionManagerTest:: |
protected | property | The mocked request. | |
LocalActionManagerTest:: |
protected | property | The mocked router provider. | |
LocalActionManagerTest:: |
public | function | ||
LocalActionManagerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
LocalActionManagerTest:: |
public | function | @covers ::getActionsForRoute | |
LocalActionManagerTest:: |
public | function | @covers ::getTitle | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |