DefaultAccessCheckTest.php in Drupal 8
File
core/tests/Drupal/Tests/Core/Access/DefaultAccessCheckTest.php
View source
<?php
namespace Drupal\Tests\Core\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Access\DefaultAccessCheck;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
class DefaultAccessCheckTest extends UnitTestCase {
protected $accessChecker;
protected $account;
protected function setUp() {
parent::setUp();
$this->account = $this
->createMock('Drupal\\Core\\Session\\AccountInterface');
$this->accessChecker = new DefaultAccessCheck();
}
public function testAccess() {
$request = new Request([]);
$route = new Route('/test-route', [], [
'_access' => 'NULL',
]);
$this
->assertEquals(AccessResult::neutral(), $this->accessChecker
->access($route, $request, $this->account));
$route = new Route('/test-route', [], [
'_access' => 'FALSE',
]);
$this
->assertEquals(AccessResult::forbidden(), $this->accessChecker
->access($route, $request, $this->account));
$route = new Route('/test-route', [], [
'_access' => 'TRUE',
]);
$this
->assertEquals(AccessResult::allowed(), $this->accessChecker
->access($route, $request, $this->account));
}
}