class AccessTest
Same name in this branch
- 9 core/modules/file/tests/src/Kernel/AccessTest.php \Drupal\Tests\file\Kernel\AccessTest
Same name and namespace in other branches
- 11.x core/modules/file/tests/src/Kernel/AccessTest.php \Drupal\Tests\file\Kernel\AccessTest
- 11.x core/modules/views/tests/src/Functional/Plugin/AccessTest.php \Drupal\Tests\views\Functional\Plugin\AccessTest
- 10 core/modules/file/tests/src/Kernel/AccessTest.php \Drupal\Tests\file\Kernel\AccessTest
- 10 core/modules/views/tests/src/Functional/Plugin/AccessTest.php \Drupal\Tests\views\Functional\Plugin\AccessTest
- 8.9.x core/modules/file/tests/src/Kernel/AccessTest.php \Drupal\Tests\file\Kernel\AccessTest
- 8.9.x core/modules/views/tests/src/Functional/Plugin/AccessTest.php \Drupal\Tests\views\Functional\Plugin\AccessTest
Tests pluggable access for views.
@group views @todo It probably make sense to split the test up by one for role/perm/none and the two generic ones.
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\views\Functional\Plugin\AccessTest extends \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of AccessTest
File
-
core/
modules/ views/ tests/ src/ Functional/ Plugin/ AccessTest.php, line 16
Namespace
Drupal\Tests\views\Functional\PluginView source
class AccessTest extends ViewTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_access_none',
'test_access_static',
'test_access_dynamic',
];
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'node',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Web user for testing.
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
/**
* Normal user for testing.
*
* @var \Drupal\user\UserInterface
*/
protected $normalUser;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE, $modules = [
'views_test_config',
]) : void {
parent::setUp($import_test_views, $modules);
$this->enableViewsTestModule();
ViewTestData::createTestViews(static::class, [
'views_test_data',
]);
$this->webUser = $this->drupalCreateUser();
$normal_role = $this->drupalCreateRole([]);
$this->normalUser = $this->drupalCreateUser([
'views_test_data test permission',
]);
$this->normalUser
->addRole($normal_role);
// @todo when all the plugin information is cached make a reset function and
// call it here.
}
/**
* Tests none access plugin.
*/
public function testAccessNone() {
$view = Views::getView('test_access_none');
$view->setDisplay();
$this->assertTrue($view->display_handler
->access($this->webUser));
$this->assertTrue($view->display_handler
->access($this->normalUser));
}
/**
* @todo Test abstract access plugin.
*/
/**
* Tests static access check.
*
* @see \Drupal\views_test\Plugin\views\access\StaticTest
*/
public function testStaticAccessPlugin() {
$view = Views::getView('test_access_static');
$view->setDisplay();
$access_plugin = $view->display_handler
->getPlugin('access');
$this->assertFalse($access_plugin->access($this->normalUser));
$this->drupalGet('test_access_static');
$this->assertSession()
->statusCodeEquals(403);
$display =& $view->storage
->getDisplay('default');
$display['display_options']['access']['options']['access'] = TRUE;
$access_plugin->options['access'] = TRUE;
$view->save();
// Saving a view will cause the router to be rebuilt when the kernel
// termination event fires. Simulate that here.
$this->container
->get('router.builder')
->rebuildIfNeeded();
$this->assertTrue($access_plugin->access($this->normalUser));
$this->drupalGet('test_access_static');
$this->assertSession()
->statusCodeEquals(200);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.