1 admin_bar.test AdminBarPermissionsTestCase::testPermissionChanges()

Tests that user role and permission changes are properly taken up.

File

core/modules/admin_bar/tests/admin_bar.test, line 190
Tests for the Administration bar module.

Class

AdminBarPermissionsTestCase
Tests menu links depending on user permissions.

Code

function testPermissionChanges() {
  // Create a user who is able to change permissions.
  $permissions = $this->basePermissions + array(
    'administer permissions',
    'assign roles',
  );
  $admin_user = $this->backdropCreateUser($permissions);
  $this->backdropLogin($admin_user);

  // Extract the user role name that was created for above permissions.
  $roles = array_diff($admin_user->roles, array(BACKDROP_AUTHENTICATED_ROLE));
  $role_name = reset($roles);

  // Verify that Configuration does not appear.
  $this->assertNoLinkTrailByTitle(array(t('Configuration')));
  // Grant the 'administer site configuration' permission to ourselves.
  $edit = array(
    $role_name . '[administer site configuration]' => TRUE,
  );
  $this->backdropPost('admin/config/people/permissions', $edit, t('Save permissions'));
  // Verify that Configuration appears.
  $this->assertLinkTrailByTitle(array(t('Configuration')));

  // Verify that Structure » Content types does not appear.
  $this->assertNoLinkTrailByTitle(array(t('Structure'), t('Content types')));
  // Create a new role.
  $edit = array(
    'name' => 'test',
    'label' => 'Test',
  );
  $this->backdropPost('admin/config/people/roles', $edit, t('Add role'));

  // Grant the 'administer content types' permission for the role.
  $edit = array(
    'test[administer content types]' => TRUE,
  );
  $this->backdropPost('admin/config/people/permissions/test', $edit, t('Save permissions'));
  // Verify that Structure » Content types does not appear.
  $this->assertNoLinkTrailByTitle(array(t('Structure'), t('Content types')));

  // Assign the role to ourselves.
  $edit = array(
    'roles[test]' => TRUE,
  );
  $this->backdropPost('user/' . $admin_user->uid . '/edit', $edit, t('Save'));
  // Verify that Structure » Content types appears.
  $this->assertLinkTrailByTitle(array(t('Structure'), t('Content types')));

  // Delete the role.
  $this->backdropPost('admin/config/people/roles/delete/test', array(), t('Delete'));
  // Verify that Structure » Content types does not appear.
  $this->assertNoLinkTrailByTitle(array(t('Structure'), t('Content types')));
}