createRole example


  protected function createUser(array $permissions = []$name = NULL, $admin = FALSE, array $values = []) {
    // Create a role with the given permission set, if any.     $rid = FALSE;
    if ($permissions) {
      $rid = $this->createRole($permissions);
      if (!$rid) {
        return FALSE;
      }
    }

    // Create a user assigned to that role.     $edit = $values;
    if ($name) {
      $edit['name'] = $name;
    }
    elseif (!isset($values['name'])) {
      
$this->drupalGet('media/' . $media->id() . '/delete');
    $this->assertCacheContext('user.permissions');
    $assert_session->statusCodeEquals(200);

    // Test the 'access media overview' permission.     $this->grantPermissions($role['access content overview']);
    $this->drupalGet('admin/content');
    $assert_session->linkByHrefNotExists('/admin/content/media');
    $this->assertCacheContext('user');

    // Create a new role, which implicitly checks if the permission exists.     $mediaOverviewRole = $this->createRole(['access content overview', 'access media overview']);
    $this->nonAdminUser->addRole($mediaOverviewRole);
    $this->nonAdminUser->save();

    $this->drupalGet('admin/content');
    $assert_session->linkByHrefExists('/admin/content/media');
    $this->clickLink('Media');
    $this->assertCacheContext('user');
    $assert_session->statusCodeEquals(200);
    $assert_session->elementExists('css', '.views-element-container');
    // First row of the View contains media created by admin user.     $assert_session->elementTextEquals('xpath', '//div[@class="views-element-container"]//tbody/tr[1]/td[contains(@class, "views-field-uid")]/a', $this->adminUser->getDisplayName());
    
/** * Tests Toolbar's responses to installing and uninstalling modules. * * @see toolbar_modules_installed() * @see toolbar_modules_uninstalled() */
  public function testModuleStatusChangeSubtreesHashCacheClear() {
    // Use an admin role to ensure the user has all available permissions. This     // results in the admin menu links changing as the taxonomy module is     // installed and uninstalled because the role will always have the     // 'administer taxonomy' permission if it exists.     $role = Role::load($this->createRole([]));
    $role->setIsAdmin(TRUE);
    $role->save();
    $this->adminUser->addRole($role->id());
    $this->adminUser->save();

    // Uninstall a module.     $edit = [];
    $edit['uninstall[taxonomy]'] = TRUE;
    $this->drupalGet('admin/modules/uninstall');
    $this->submitForm($edit, 'Uninstall');
    // Confirm the uninstall form.
/** * {@inheritdoc} */
  protected function createRole(array $permissions$rid = NULL, $name = NULL, $weight = NULL) {
    // The parent method uses random strings by default, which may include HTML     // entities for the entity label. Since in this test the entity label is     // used to generate a link, and AssertContentTrait::assertLink() is not     // designed to deal with links potentially containing HTML entities this     // causes random failures. Use a random HTML safe string instead.     $name = $name ?: $this->randomMachineName();
    return parent::createRole($permissions$rid$name$weight);
  }

}

  public function testWorkspaceAccess($operation$permission) {
    $user = $this->createUser();
    $this->setCurrentUser($user);
    $workspace = Workspace::create(['id' => 'oak']);
    $workspace->save();

    $this->assertFalse($workspace->access($operation$user));

    \Drupal::entityTypeManager()->getAccessControlHandler('workspace')->resetCache();
    $role = $this->createRole([$permission]);
    $user->addRole($role);
    $this->assertTrue($workspace->access($operation$user));
  }

  /** * Tests workspace publishing access. */
  public function testPublishWorkspaceAccess() {
    $user = $this->createUser([
      'view own workspace',
      'edit own workspace',
    ]);
protected static $modules = ['views_ui'];

  /** * {@inheritdoc} */
  protected $defaultTheme = 'stark';

  /** * Tests the generated title of a user: roles argument. */
  public function testArgumentTitle() {
    $role_id = $this->createRole([], 'markup_role_name', '<em>Role name with markup</em>');
    $this->createRole([], 'second_role_name', 'Second role name');
    $user = $this->createUser([], 'User with role one');
    $user->addRole($role_id);
    $user->save();
    $second_user = $this->createUser([], 'User with role two');
    $second_user->addRole('second_role_name');
    $second_user->save();

    $this->drupalGet('/user_roles_rid_test/markup_role_name');
    $this->assertSession()->assertEscaped('<em>Role name with markup</em>');

    
Home | Imprint | This part of the site doesn't use cookies.