drupalCreateRole example


  protected function setUp($import_test_views = TRUE, $modules = ['views_test_config']): void {
    parent::setUp($import_test_views$modules);

    $this->enableViewsTestModule();

    ViewTestData::createTestViews(static::class['views_test_data']);

    $this->webUser = $this->drupalCreateUser();

    $normal_role = $this->drupalCreateRole([]);
    $this->normalUser = $this->drupalCreateUser([
      'views_test_data test permission',
    ]);
    $this->normalUser->addRole($normal_role);
    // @todo when all the plugin information is cached make a reset function and     // call it here.   }

  /** * Tests none access plugin. */
  
foreach ($entity_type as $entity) {
            // Verify that usage count is found on usage page.             $this->assertSession()->pageTextContains($entity);
          }
        }
      }
      $this->assertSession()->linkByHrefExists('node/' . $node->id(), 0, 'Link to registering entity found on usage page.');
    }

    // Log in as another user that has access to the file list but cannot delete     // files.     $role_id = $this->drupalCreateRole([
      'access files overview',
      'bypass node access',
    ]);
    $this->drupalLogin($this->drupalCreateUser(values: ['roles' => [$role_id]]));

    $this->drupalGet('admin/content/files');
    foreach ($nodes as $node) {
      $file = File::load($node->file->target_id);
      $this->assertSession()->pageTextContains($file->getFilename());
      $this->assertSession()->linkByHrefExists($file->createFileUrl());
      $this->assertSession()->linkByHrefExists('admin/content/files/usage/' . $file->id());
      
// Log in the first admin user again.     $this->drupalLogin($this->adminUser);
    $this->drupalGet('test-page');
    $this->assertSession()->statusCodeEquals(200);

    // Assert that the toolbar is present in the HTML.     $this->assertSession()->responseContains('id="toolbar-administration"');

    $this->hash = $this->getSubtreesHash();

    $rid = $this->drupalCreateRole(['administer content types']);

    // Assign the role to the user.     $this->drupalGet('user/' . $this->adminUser->id() . '/edit');
    $this->submitForm(["roles[{$rid}]" => $rid], 'Save');
    $this->assertSession()->pageTextContains('The changes have been saved.');

    // Assert that the subtrees hash has been altered because the subtrees     // structure changed.     $this->assertDifferentHash();

    // Log in the second user again and assert that their subtrees hash did not

  public function testAccessUnpublished($allowed_to_view_unpublished$expected_rendered, CacheableMetadata $expected_cacheability, array $expected_attachments) {
    // Unpublish the embedded entity so we can test variations in behavior.     $this->embeddedEntity->setUnpublished()->save();

    // Are we testing as a user who is allowed to view the embedded entity?     if ($allowed_to_view_unpublished) {
      $this->container->get('current_user')
        ->addRole($this->drupalCreateRole(['view own unpublished media']));
    }

    $content = $this->createEmbedCode([
      'data-entity-type' => 'media',
      'data-entity-uuid' => static::EMBEDDED_ENTITY_UUID,
    ]);
    $result = $this->applyFilter($content);

    if (!$expected_rendered) {
      $this->assertEmpty($this->getRawContent());
    }
    


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

  /** * Test that user can be assigned role and that the role can be removed again. */
  public function testAssignAndRemoveRole() {
    $rid = $this->drupalCreateRole(['administer users']);
    $account = $this->drupalCreateUser();

    // Assign the role to the user.     $this->drupalGet('user/' . $account->id() . '/edit');
    $this->submitForm(["roles[{$rid}]" => $rid], 'Save');
    $this->assertSession()->pageTextContains('The changes have been saved.');
    $this->assertSession()->checkboxChecked('edit-roles-' . $rid);
    $this->userLoadAndCheckRoleAssigned($account$rid);

    // Remove the role from the user.     $this->drupalGet('user/' . $account->id() . '/edit');
    
$account->block();
    $account->save();
    $accounts[$account->label()] = $account;

    // Create a user at a certain timestamp.     $account = $this->drupalCreateUser();
    $account->created = 1363219200;
    $account->save();
    $accounts[$account->label()] = $account;
    $timestamp_user = $account->label();

    $rid_1 = $this->drupalCreateRole([], 'custom_role_1', 'custom_role_1');
    $rid_2 = $this->drupalCreateRole([], 'custom_role_2', 'custom_role_2');

    $account = $this->drupalCreateUser();
    $account->addRole($rid_1);
    $account->addRole($rid_2);
    $account->save();
    $accounts[$account->label()] = $account;
    $role_account_name = $account->label();

    // Create an admin user and look at the listing.     $admin_user = $this->drupalCreateUser(['administer users']);
    

  protected function setUp($import_test_views = TRUE, $modules = []): void {
    parent::setUp($import_test_views$modules);
    $this->drupalPlaceBlock('system_breadcrumb_block');

    $this->enableViewsTestModule();

    $this->webUser = $this->drupalCreateUser();
    $roles = $this->webUser->getRoles();
    $this->webRole = $roles[0];

    $this->normalRole = $this->drupalCreateRole([]);
    $this->normalUser = $this->drupalCreateUser([
      'views_test_data test permission',
    ]);
    $this->normalUser->addRole($this->normalRole);
    $this->normalUser->save();
    // @todo when all the plugin information is cached make a reset function and     // call it here.   }

}

  public static $testViews = ['test_views_handler_field_role'];

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

  public function testRole() {
    // Create a couple of roles for the view.     $rolename_a = 'a' . $this->randomMachineName(8);
    $this->drupalCreateRole(['access content']$rolename_a, '<em>' . $rolename_a . '</em>', 9);

    $rolename_b = 'b' . $this->randomMachineName(8);
    $this->drupalCreateRole(['access content']$rolename_b$rolename_b, 8);

    $rolename_not_assigned = $this->randomMachineName(8);
    $this->drupalCreateRole(['access content']$rolename_not_assigned$rolename_not_assigned);

    // Add roles to user 1.     $user = User::load(1);
    $user->addRole($rolename_a);
    $user->addRole($rolename_b);
    

  public $role2;

  /** * {@inheritdoc} */
  protected function setUp($import_test_views = TRUE, $modules = ['views_test_config']): void {
    parent::setUp($import_test_views$modules);

    // Create Roles and users.     $this->role1 = $this->drupalCreateRole(['access content'], 'editor', 'Editor');
    $this->role2 = $this->drupalCreateRole(['access content'], 'publisher', 'Publisher');

    $this->createUser([], 'user1', FALSE, ['roles' => [$this->role1]]);
    $this->createUser([], 'user2', FALSE, ['roles' => [$this->role2]]);
    $this->createUser([], 'user3', FALSE, ['roles' => [$this->role1, $this->role2]]);
    $this->createUser([], 'user4', FALSE, ['roles' => [$this->role2]]);
    $this->createUser([], 'user5', FALSE, ['roles' => [$this->role1, $this->role2]]);

    $this->drupalLogin($this->rootUser);
  }

  
// Test that the cancel user page has admin fields.     $cancel_user = $this->createUser();
    $this->drupalGet('user/' . $cancel_user->id() . '/cancel');
    $this->assertSession()->responseContains('Are you sure you want to cancel the account ' . $cancel_user->getAccountName() . '?');
    $this->assertSession()->responseContains('Disable the account and keep its content.');

    // Test that cancel confirmation gives an admin style message.     $this->submitForm([], 'Confirm');
    $this->assertSession()->pageTextContains('Account ' . $cancel_user->getAccountName() . ' has been disabled.');

    // Repeat with permission to select account cancellation method.     $user->addRole($this->drupalCreateRole(['select account cancellation method']));
    $user->save();
    $cancel_user = $this->createUser();
    $this->drupalGet('user/' . $cancel_user->id() . '/cancel');
    $this->assertSession()->pageTextContains('Cancellation method');
  }

}
/** * The CKEditor Widget must load a preview generated using the default theme. */
  public function testPreviewUsesDefaultThemeAndIsClientCacheable() {
    // Make the node edit form use the admin theme, like on most Drupal sites.     $this->config('node.settings')
      ->set('use_admin_theme', TRUE)
      ->save();

    // Allow the test user to view the admin theme.     $this->adminUser->addRole($this->drupalCreateRole(['view the administration theme']));
    $this->adminUser->save();

    // Configure a different default and admin theme, like on most Drupal sites.     $this->config('system.theme')
      ->set('default', 'stable9')
      ->set('admin', 'starterkit_theme')
      ->save();

    // Assert that when looking at an embedded entity in the CKEditor Widget,     // the preview is generated using the default theme, not the admin theme.     // @see media_test_embed_entity_view_alter()
    $this->drupalLogin($this->drupalCreateUser([
      'access toolbar',
      'access shortcuts',
    ]));
    $this->verifyDynamicPageCache($test_page_url, 'MISS');
    $this->verifyDynamicPageCache($test_page_url, 'HIT');
    $this->assertSession()->linkExists('Shortcuts');
    $this->assertSession()->linkNotExists('Cron');

    // Create a role with access to shortcuts as well as the necessary     // permissions to see specific shortcuts.     $site_configuration_role = $this->drupalCreateRole([
      'access toolbar',
      'access shortcuts',
      'administer site configuration',
      'access administration pages',
    ]);

    // Create two different users with the same role to assert that the second     // user has a cache hit despite the user cache context, as     // the returned cache contexts include those from lazy-builder content.     $site_configuration_user1 = $this->drupalCreateUser();
    $site_configuration_user1->addRole($site_configuration_role);
    
// @see media_test_embed_entity_view_alter()     'media_test_embed',
  ];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->container->get('current_user')
      ->addRole($this->drupalCreateRole([
        'access contextual links',
      ]));
  }

  /** * @covers ::renderMedia * @covers ::disableContextualLinks */
  public function testDisabledIntegrations() {
    $text = $this->createEmbedCode([
      'data-entity-type' => 'media',
      
$this->assertSame(201, $response->getStatusCode());
  }

  /** * Tests that collections can be filtered by an entity reference target_id. * * @see https://www.drupal.org/project/drupal/issues/3036593 */
  public function testFilteringEntitiesByEntityReferenceTargetId() {
    // Create two config entities to be the config targets of an entity     // reference. In this case, the `roles` field.     $role_llamalovers = $this->drupalCreateRole([], 'llamalovers', 'Llama Lovers');
    $role_catcuddlers = $this->drupalCreateRole([], 'catcuddlers', 'Cat Cuddlers');

    /** @var \Drupal\user\UserInterface[] $users */
    for ($i = 0; $i < 3; $i++) {
      // Create 3 users, one with the first role and two with the second role.       $users[$i] = $this->drupalCreateUser();
      $users[$i]->addRole($i === 0 ? $role_llamalovers : $role_catcuddlers);
      $users[$i]->save();
      // For each user, create a node that is owned by that user. The node's       // `uid` field will be used to test filtering by a content entity ID.       Node::create([
        
    $this->drupalGet($translate_link);
    $this->assertSession()->responseContains('<th>Language</th>');
  }

  /** * Tests the role listing for the translate operation. */
  public function doUserRoleListTest() {
    // Create a test role to decouple looking for translate operations     // link so this does not test more than necessary.     $role_id = mb_strtolower($this->randomMachineName(16));
    $this->drupalCreateRole([]$role_id);

    // Get the role listing.     $this->drupalGet('admin/people/roles');

    $translate_link = 'admin/people/roles/manage/' . $role_id . '/translate';
    // Test if the link to translate the role is on the page.     $this->assertSession()->linkByHrefExists($translate_link);

    // Test if the link to translate actually goes to the translate page.     $this->drupalGet($translate_link);
    $this->assertSession()->responseContains('<th>Language</th>');
  }
Home | Imprint | This part of the site doesn't use cookies.