3 namespace Drupal\user\Tests\Views;
5 use Drupal\views\Tests\ViewTestData;
6 use Drupal\views_ui\Tests\UITestBase;
9 * Tests views role access plugin UI.
12 * @see Drupal\user\Plugin\views\access\Role
14 class AccessRoleUITest extends UITestBase {
17 * Views used by this test.
21 public static $testViews = ['test_access_role'];
28 public static $modules = ['user', 'user_test_views'];
33 protected function setUp() {
36 ViewTestData::createTestViews(get_class($this), ['user_test_views']);
40 * Tests the role access plugin UI.
42 public function testAccessRoleUI() {
43 $entity_manager = $this->container->get('entity.manager');
44 $entity_manager->getStorage('user_role')->create(['id' => 'custom_role', 'label' => 'Custom role'])->save();
45 $access_url = "admin/structure/views/nojs/display/test_access_role/default/access_options";
46 $this->drupalPostForm($access_url, ['access_options[role][custom_role]' => 1], t('Apply'));
47 $this->assertResponse(200);
49 $this->drupalPostForm(NULL, [], t('Save'));
50 $view = $entity_manager->getStorage('view')->load('test_access_role');
52 $display = $view->getDisplay('default');
53 $this->assertEqual($display['display_options']['access']['options']['role'], ['custom_role' => 'custom_role']);
55 // Test changing access plugin from role to none.
56 $this->drupalPostForm('admin/structure/views/nojs/display/test_access_role/default/access', ['access[type]' => 'none'], t('Apply'));
57 $this->drupalPostForm(NULL, [], t('Save'));
58 // Verify that role option is not set.
59 $view = $entity_manager->getStorage('view')->load('test_access_role');
60 $display = $view->getDisplay('default');
61 $this->assertFalse(isset($display['display_options']['access']['options']['role']));