class ModuleRouteSubscriberTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/EventSubscriber/ModuleRouteSubscriberTest.php \Drupal\Tests\Core\EventSubscriber\ModuleRouteSubscriberTest
@coversDefaultClass \Drupal\Core\EventSubscriber\ModuleRouteSubscriber @group EventSubscriber
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\EventSubscriber\ModuleRouteSubscriberTest
Expanded class hierarchy of ModuleRouteSubscriberTest
File
- core/
tests/ Drupal/ Tests/ Core/ EventSubscriber/ ModuleRouteSubscriberTest.php, line 20 - Contains \Drupal\Tests\Core\EventSubscriber\ModuleRouteSubscriberTest.
Namespace
Drupal\Tests\Core\EventSubscriberView source
class ModuleRouteSubscriberTest extends UnitTestCase {
/**
* The mock module handler.
*
* @var Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $moduleHandler;
protected function setUp() {
$this->moduleHandler = $this
->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
$value_map = array(
array(
'enabled',
TRUE,
),
array(
'disabled',
FALSE,
),
);
$this->moduleHandler
->expects($this
->any())
->method('moduleExists')
->will($this
->returnValueMap($value_map));
}
/**
* Tests that removeRoute() removes routes when the module is not enabled.
*
* @dataProvider providerTestRemoveRoute
* @covers ::onAlterRoutes
*
* @param string $route_name
* The machine name for the route.
* @param array $requirements
* An array of requirements to use for the route.
* @param bool $removed
* Whether or not the route is expected to be removed from the collection.
*/
public function testRemoveRoute($route_name, array $requirements, $removed) {
$collection = new RouteCollection();
$route = new Route('', array(), $requirements);
$collection
->add($route_name, $route);
$event = new RouteBuildEvent($collection, 'test');
$route_subscriber = new ModuleRouteSubscriber($this->moduleHandler);
$route_subscriber
->onAlterRoutes($event);
if ($removed) {
$this
->assertNull($collection
->get($route_name));
}
else {
$this
->assertInstanceOf('Symfony\\Component\\Routing\\Route', $collection
->get($route_name));
}
}
/**
* Data provider for testRemoveRoute().
*/
public function providerTestRemoveRoute() {
return array(
array(
'enabled',
array(
'_module_dependencies' => 'enabled',
),
FALSE,
),
array(
'disabled',
array(
'_module_dependencies' => 'disabled',
),
TRUE,
),
array(
'enabled_or',
array(
'_module_dependencies' => 'disabled,enabled',
),
FALSE,
),
array(
'enabled_or',
array(
'_module_dependencies' => 'enabled,disabled',
),
FALSE,
),
array(
'disabled_or',
array(
'_module_dependencies' => 'disabled,disabled',
),
TRUE,
),
array(
'enabled_and',
array(
'_module_dependencies' => 'enabled+enabled',
),
FALSE,
),
array(
'enabled_and',
array(
'_module_dependencies' => 'enabled+disabled',
),
TRUE,
),
array(
'enabled_and',
array(
'_module_dependencies' => 'disabled+enabled',
),
TRUE,
),
array(
'disabled_and',
array(
'_module_dependencies' => 'disabled+disabled',
),
TRUE,
),
array(
'no_dependencies',
array(),
FALSE,
),
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ModuleRouteSubscriberTest:: |
protected | property | The mock module handler. | |
ModuleRouteSubscriberTest:: |
public | function | Data provider for testRemoveRoute(). | |
ModuleRouteSubscriberTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ModuleRouteSubscriberTest:: |
public | function | Tests that removeRoute() removes routes when the module is not enabled. | |
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. |