class CustomAccessCheckTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Access/CustomAccessCheckTest.php \Drupal\Tests\Core\Access\CustomAccessCheckTest
@coversDefaultClass \Drupal\Core\Access\CustomAccessCheck @group Access
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Access\CustomAccessCheckTest
Expanded class hierarchy of CustomAccessCheckTest
File
- core/
tests/ Drupal/ Tests/ Core/ Access/ CustomAccessCheckTest.php, line 19 - Contains \Drupal\Tests\Core\Access\CustomAccessCheckTest.
Namespace
Drupal\Tests\Core\AccessView source
class CustomAccessCheckTest extends UnitTestCase {
/**
* The access checker to test.
*
* @var \Drupal\Core\Access\CustomAccessCheck
*/
protected $accessChecker;
/**
* The mocked controller resolver.
*
* @var \Drupal\Core\Controller\ControllerResolverInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $controllerResolver;
/**
* The mocked arguments resolver.
*
* @var \Drupal\Core\Access\AccessArgumentsResolverFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $argumentsResolverFactory;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->controllerResolver = $this
->getMock('Drupal\\Core\\Controller\\ControllerResolverInterface');
$this->argumentsResolverFactory = $this
->getMock('Drupal\\Core\\Access\\AccessArgumentsResolverFactoryInterface');
$this->accessChecker = new CustomAccessCheck($this->controllerResolver, $this->argumentsResolverFactory);
}
/**
* Test the access method.
*/
public function testAccess() {
$route_match = $this
->getMock('Drupal\\Core\\Routing\\RouteMatchInterface');
$this->controllerResolver
->expects($this
->at(0))
->method('getControllerFromDefinition')
->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessDeny')
->will($this
->returnValue(array(
new TestController(),
'accessDeny',
)));
$resolver0 = $this
->getMock('Drupal\\Component\\Utility\\ArgumentsResolverInterface');
$resolver0
->expects($this
->once())
->method('getArguments')
->will($this
->returnValue(array()));
$this->argumentsResolverFactory
->expects($this
->at(0))
->method('getArgumentsResolver')
->will($this
->returnValue($resolver0));
$this->controllerResolver
->expects($this
->at(1))
->method('getControllerFromDefinition')
->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessAllow')
->will($this
->returnValue(array(
new TestController(),
'accessAllow',
)));
$resolver1 = $this
->getMock('Drupal\\Component\\Utility\\ArgumentsResolverInterface');
$resolver1
->expects($this
->once())
->method('getArguments')
->will($this
->returnValue(array()));
$this->argumentsResolverFactory
->expects($this
->at(1))
->method('getArgumentsResolver')
->will($this
->returnValue($resolver1));
$this->controllerResolver
->expects($this
->at(2))
->method('getControllerFromDefinition')
->with('\\Drupal\\Tests\\Core\\Access\\TestController::accessParameter')
->will($this
->returnValue(array(
new TestController(),
'accessParameter',
)));
$resolver2 = $this
->getMock('Drupal\\Component\\Utility\\ArgumentsResolverInterface');
$resolver2
->expects($this
->once())
->method('getArguments')
->will($this
->returnValue(array(
'parameter' => 'TRUE',
)));
$this->argumentsResolverFactory
->expects($this
->at(2))
->method('getArgumentsResolver')
->will($this
->returnValue($resolver2));
$route = new Route('/test-route', array(), array(
'_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessDeny',
));
$account = $this
->getMock('Drupal\\Core\\Session\\AccountInterface');
$this
->assertEquals(AccessResult::neutral(), $this->accessChecker
->access($route, $route_match, $account));
$route = new Route('/test-route', array(), array(
'_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessAllow',
));
$this
->assertEquals(AccessResult::allowed(), $this->accessChecker
->access($route, $route_match, $account));
$route = new Route('/test-route', array(
'parameter' => 'TRUE',
), array(
'_custom_access' => '\\Drupal\\Tests\\Core\\Access\\TestController::accessParameter',
));
$this
->assertEquals(AccessResult::allowed(), $this->accessChecker
->access($route, $route_match, $account));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CustomAccessCheckTest:: |
protected | property | The access checker to test. | |
CustomAccessCheckTest:: |
protected | property | The mocked arguments resolver. | |
CustomAccessCheckTest:: |
protected | property | The mocked controller resolver. | |
CustomAccessCheckTest:: |
protected | function |
Overrides UnitTestCase:: |
|
CustomAccessCheckTest:: |
public | function | Test the access method. | |
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. |