AccessRoleUITest.php in Drupal 10
File
core/modules/user/tests/src/Functional/AccessRoleUITest.php
View source
<?php
namespace Drupal\Tests\user\Functional;
use Drupal\Tests\views_ui\Functional\UITestBase;
class AccessRoleUITest extends UITestBase {
public static $testViews = [
'test_access_role',
];
protected static $modules = [
'user',
'user_test_views',
];
protected $defaultTheme = 'stark';
protected function setUp($import_test_views = TRUE, $modules = [
'user_test_views',
]) : void {
parent::setUp($import_test_views, $modules);
}
public function testAccessRoleUI() {
$entity_type_manager = $this->container
->get('entity_type.manager');
$entity_type_manager
->getStorage('user_role')
->create([
'id' => 'custom_role',
'label' => 'Custom role',
])
->save();
$access_url = "admin/structure/views/nojs/display/test_access_role/default/access_options";
$this
->drupalGet($access_url);
$this
->submitForm([
'access_options[role][custom_role]' => 1,
], 'Apply');
$this
->assertSession()
->statusCodeEquals(200);
$this
->submitForm([], 'Save');
$view = $entity_type_manager
->getStorage('view')
->load('test_access_role');
$display = $view
->getDisplay('default');
$this
->assertEquals([
'custom_role' => 'custom_role',
], $display['display_options']['access']['options']['role']);
$this
->drupalGet('admin/structure/views/nojs/display/test_access_role/default/access');
$this
->submitForm([
'access[type]' => 'none',
], 'Apply');
$this
->submitForm([], 'Save');
$view = $entity_type_manager
->getStorage('view')
->load('test_access_role');
$display = $view
->getDisplay('default');
$this
->assertFalse(isset($display['display_options']['access']['options']['role']));
}
}