user_role_grant_permissions example

$nid = $this->uploadNodeFiles($upload_files$field_name$type_name, TRUE, []);
    $node = $node_storage->loadUnchanged($nid);
    $this->assertCount($cardinality$node->{$field_name}, 'Node was successfully saved with maximum number of files.');
  }

  /** * Tests a file field with a "Private files" upload destination setting. */
  public function testPrivateFileSetting() {
    $node_storage = $this->container->get('entity_type.manager')->getStorage('node');
    // Grant the admin user required permissions.     user_role_grant_permissions($this->adminUser->roles[0]->target_id, ['administer node fields']);

    $type_name = 'article';
    $field_name = strtolower($this->randomMachineName());
    $this->createFileField($field_name, 'node', $type_name);
    $field = FieldConfig::loadByName('node', $type_name$field_name);
    $field_id = $field->id();

    $test_file = $this->getTestFile('text');

    // Change the field setting to make its files private, and upload a file.     $edit = ['settings[uri_scheme]' => 'private'];
    

  protected $defaultTheme = 'olivero';

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

    // Allow anonymous users to see comments.     user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
      'access comments',
      'access content',
    ]);
  }

  /** * Sets base fields to configurable display and check settings are respected. */
  public function testDisplayConfigurable() {
    // Add a comment.     $nid = $this->node->id();
    

  public function testFileAccess() {
    $this->installSchema('system', ['sequences']);
    $this->installEntitySchema('user');
    $this->installEntitySchema('file');
    $this->installSchema('file', ['file_usage']);
    $this->installConfig('user');

    $anonymous = User::create(['uid' => 0, 'name' => '']);
    $anonymous->save();
    user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, ['access content']);

    // Create an authenticated user to check file access.     $account = $this->createUser(['access site reports', 'access content'], NULL, FALSE, ['uid' => 2]);

    // Create a new file entity in the public:// stream wrapper.     $file_public = File::create([
      'uid' => 1,
      'filename' => 'drupal.txt',
      'uri' => 'public://drupal.txt',
      'status' => FileInterface::STATUS_PERMANENT,
    ]);
    
// Test denied access to the user's own contact form.     $this->drupalGet('user/' . $this->webUser->id() . '/contact');
    $this->assertSession()->statusCodeEquals(403);

    // Test always denied access to the anonymous user contact form.     $this->drupalGet('user/0/contact');
    $this->assertSession()->statusCodeEquals(403);

    // Test that anonymous users can access the contact form.     $this->drupalLogout();
    user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access user contact forms']);
    $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
    $this->assertSession()->statusCodeEquals(200);

    // Test that anonymous users can access admin user's contact form.     $this->drupalGet('user/' . $this->adminUser->id() . '/contact');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertCacheContext('user');

    // Revoke the personal contact permission for the anonymous user.     user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, ['access user contact forms']);
    $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
    

  protected $defaultTheme = 'stark';

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

    // Enable anonymous and authenticated user comments.     user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
      'access comments',
      'post comments',
      'skip comment approval',
    ]);
    user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, [
      'access comments',
      'post comments',
      'skip comment approval',
    ]);
  }

  

  protected function setUp(): void {
    parent::setUp();

    $filtered_html_format = FilterFormat::create([
      'format' => 'filtered_html',
      'name' => 'Filtered HTML',
    ]);
    $filtered_html_format->save();

    $filtered_html_permission = $filtered_html_format->getPermissionName();
    user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [$filtered_html_permission]);
  }

  /** * Check several empty values for required forms elements. * * Carriage returns, tabs, spaces, and unchecked checkbox elements are not * valid content for a required field. * * If the form field is found in $form_state->getErrors() then the test pass. */
  public function testRequiredFields() {
    
// Load the book and verify there is no printer-friendly version link.     $this->drupalGet('node/' . $this->book->id());
    $this->assertSession()->linkNotExists('Printer-friendly version', 'Anonymous user is not shown link to printer-friendly version.');

    // Try getting the URL directly, and verify it fails.     $this->drupalGet('book/export/html/' . $this->book->id());
    $this->assertSession()->statusCodeEquals(403);

    // Now grant anonymous users permission to view the printer-friendly     // version and verify that node access restrictions still prevent them from     // seeing it.     user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access printer-friendly version']);
    $this->drupalGet('book/export/html/' . $this->book->id());
    $this->assertSession()->statusCodeEquals(403);
  }

  /** * Tests the functionality of the book navigation block. */
  public function testBookNavigationBlock() {
    $this->drupalLogin($this->adminUser);

    // Enable the block.
$comments[$i] = $this->postComment($this->node, $this->randomMachineName()$subject);
      $comments[$i]->created->value = $timestamp--;
      $comments[$i]->save();
    }

    // Test that a user without the 'access comments' permission cannot see the     // block.     $this->drupalLogout();
    user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']);
    $this->drupalGet('');
    $this->assertSession()->pageTextNotContains('Recent comments');
    user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']);

    // Test that a user with the 'access comments' permission can see the     // block.     $this->drupalLogin($this->webUser);
    $this->drupalGet('');
    $this->assertSession()->pageTextContains('Recent comments');

    // Test the only the 10 latest comments are shown and in the proper order.     $this->assertSession()->pageTextNotContains($comments[10]->getSubject());
    for ($i = 0; $i < 10; $i++) {
      $this->assertSession()->pageTextContains($comments[$i]->getSubject());
      
'administer contact_message fields',
    ]);
    $this->drupalLogin($admin_user);
    // Create first valid contact form.     $mail = 'simpletest@example.com';
    $this->addContactForm($id = mb_strtolower($this->randomMachineName(16))$label = $this->randomMachineName(16)implode(',', [$mail]), '', TRUE, 'Your message has been sent.', [
      'send_a_pony' => 1,
    ]);
    $this->assertSession()->pageTextContains('Contact form ' . $label . ' has been added.');

    // Ensure that anonymous can submit site-wide contact form.     user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access site-wide contact form']);
    $this->drupalLogout();
    $this->drupalGet('contact');
    $this->assertSession()->pageTextContains('Your email address');
    $this->assertSession()->pageTextNotContains('Form');
    $this->submitContact($name = $this->randomMachineName(16)$mail$subject = $this->randomMachineName(16)$id$message = $this->randomMachineName(64));
    $this->assertSession()->pageTextContains('Your message has been sent.');

    $messages = Message::loadMultiple();
    /** @var \Drupal\contact\Entity\Message $message */
    $message = reset($messages);
    $this->assertEquals($id$message->getContactForm()->id());
    
$this->assertSession()->statusCodeEquals(200);
    // Make sure comment_body field is shown.     $this->assertSession()->pageTextContains('comment_body');
    // Rest from here on in is field_ui.   }

  /** * Tests editing a comment as an admin. */
  public function testEditComment() {
    // Enable anonymous user comments.     user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
      'access comments',
      'post comments',
      'skip comment approval',
    ]);

    // Log in as a web user.     $this->drupalLogin($this->webUser);
    // Post a comment.     $comment = $this->postComment($this->node, $this->randomMachineName());

    $this->drupalLogout();

    
// Create test user.     $this->adminUser = $this->drupalCreateUser([
      'administer comments',
      'skip comment approval',
      'post comments',
      'access comments',
      'view test entity',
      'administer entity_test content',
    ]);

    // Enable anonymous and authenticated user comments.     user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
      'access comments',
      'post comments',
      'skip comment approval',
    ]);
    user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, [
      'access comments',
      'post comments',
      'skip comment approval',
    ]);

    // Create a test entity.
// Next iteration should expect this tag as parent link.       // Note: Term name, not link name, due to taxonomy_term_page().       $trail += [
        $link_path => $term->getName(),
      ];
    }

    // Verify breadcrumbs on user and user/%.     // We need to log back in and out below, and cannot simply grant the     // 'administer users' permission, since user_page() makes your head explode.     user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, [
      'access user profiles',
    ]);

    // Verify breadcrumb on front page.     $this->assertBreadcrumb('<front>', []);

    // Verify breadcrumb on user pages (without menu link) for anonymous user.     $trail = $home;
    $this->assertBreadcrumb('user', $trail, 'Log in');
    $this->assertBreadcrumb('user/' . $this->adminUser->id()$trail$this->adminUser->getAccountName());

    

  protected function setUp(): void {
    parent::setUp();

    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page']);

    $permissions = ['access comments', 'create page content', 'post comments', 'skip comment approval'];
    $this->user = $this->drupalCreateUser($permissions);
    $this->otherUser = $this->drupalCreateUser($permissions);
    $this->addDefaultCommentField('node', 'page');
    user_role_grant_permissions(AccountInterface::ANONYMOUS_ROLE, [
      'access content',
      'access user profiles',
    ]);
    $this->drupalPlaceBlock('local_tasks_block', ['id' => 'page_tabs_block']);
    $this->drupalPlaceBlock('local_actions_block', ['id' => 'page_actions_block']);
  }

  /** * Tests for the presence of nodes on the global tracker listing. */
  public function testTrackerAll() {
    
protected function setUp(): void {
    parent::setUp();

    // Create an administrative user.     $this->adminUser = $this->drupalCreateUser([
      'administer site configuration',
      'link to any page',
    ]);
    $this->adminUser->roles[] = 'administrator';
    $this->adminUser->save();

    user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access user profiles']);
    user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access user profiles']);
  }

  public function testPageNotFound() {
    $this->drupalLogin($this->adminUser);
    $this->drupalGet($this->randomMachineName(10));
    $this->assertSession()->pageTextContains('Page not found');

    // Set a custom 404 page without a starting slash.     $edit = [
      'site_404' => 'user/' . $this->adminUser->id(),
    ];
// Create an administrative user.     $this->adminUser = $this->drupalCreateUser([
      'access administration pages',
      'administer site configuration',
      'link to any page',
      'administer blocks',
    ]);
    $this->adminUser->roles[] = 'administrator';
    $this->adminUser->save();

    user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access user profiles']);
    user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access user profiles']);
  }

  public function testAccessDenied() {
    $this->drupalGet('admin');
    $this->assertSession()->pageTextContains('Access denied');
    $this->assertSession()->statusCodeEquals(403);

    // Ensure that users without permission are denied access and have the     // correct path information in drupalSettings.     $this->drupalLogin($this->createUser([]));
    
Home | Imprint | This part of the site doesn't use cookies.