You are here

public function AccessRoleUITest::testAccessRoleUI in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/user/src/Tests/Views/AccessRoleUITest.php \Drupal\user\Tests\Views\AccessRoleUITest::testAccessRoleUI()

Tests the role access plugin UI.

File

core/modules/user/src/Tests/Views/AccessRoleUITest.php, line 47
Contains \Drupal\user\Tests\Views\AccessRoleUITest.

Class

AccessRoleUITest
Tests views role access plugin UI.

Namespace

Drupal\user\Tests\Views

Code

public function testAccessRoleUI() {
  $entity_manager = $this->container
    ->get('entity.manager');
  $entity_manager
    ->getStorage('user_role')
    ->create(array(
    'id' => 'custom_role',
    'label' => 'Custom role',
  ))
    ->save();
  $access_url = "admin/structure/views/nojs/display/test_access_role/default/access_options";
  $this
    ->drupalPostForm($access_url, array(
    'access_options[role][custom_role]' => 1,
  ), t('Apply'));
  $this
    ->assertResponse(200);
  $this
    ->drupalPostForm(NULL, array(), t('Save'));
  $view = $entity_manager
    ->getStorage('view')
    ->load('test_access_role');
  $display = $view
    ->getDisplay('default');
  $this
    ->assertEqual($display['display_options']['access']['options']['role'], array(
    'custom_role' => 'custom_role',
  ));

  // Test changing access plugin from role to none.
  $this
    ->drupalPostForm('admin/structure/views/nojs/display/test_access_role/default/access', [
    'access[type]' => 'none',
  ], t('Apply'));
  $this
    ->drupalPostForm(NULL, array(), t('Save'));

  // Verify that role option is not set.
  $view = $entity_manager
    ->getStorage('view')
    ->load('test_access_role');
  $display = $view
    ->getDisplay('default');
  $this
    ->assertFalse(isset($display['display_options']['access']['options']['role']));
}