drupalLogout example

// Ensure that broken block configuration can be accessed.     $this->drupalGet('admin/structure/block/manage/' . $block->id());
    $assert_session->statusCodeEquals(200);

    // Login as an admin user to the site.     $this->drupalLogin($this->adminUser);
    $this->drupalGet('');
    $assert_session->statusCodeEquals(200);
    // Check that this user can view the Broken Block message.     $assert_session->pageTextContains('This block is broken or missing. You may be missing content or you might need to enable the original module.');
    $this->drupalLogout();

    // Visit the same page as anonymous.     $this->drupalGet('');
    $assert_session->statusCodeEquals(200);
    // Check that this user cannot view the Broken Block message.     $assert_session->pageTextNotContains('This block is broken or missing. You may be missing content or you might need to enable the original module.');

    // Visit same page as an authorized user that does not have access to     // administer blocks.     $this->drupalLogin($this->drupalCreateUser(['access administration pages']));
    $this->drupalGet('');
    

  public function testHookEntityFieldAccess() {
    // Create an admin user and do the login.     $user = $this->drupalCreateUser([], NULL, TRUE);
    $this->drupalLogin($user);

    // Assess the field is not visible.     $this->drupalGet('node/add/page');
    $this->assertSession()->fieldNotExists('langcode[0][value]');

    $this->drupalLogout();
  }

}
'direction' => LanguageInterface::DIRECTION_LTR,
    ];
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add custom language');
    // Add string.     t($name[]['langcode' => $langcode])->render();
    // Reset locale cache.     $this->container->get('string_translation')->reset();
    $this->assertSession()->responseContains('"edit-languages-' . $langcode . '-weight"');
    // Ensure that test language was added.     $this->assertSession()->pageTextContains($name);
    $this->drupalLogout();

    // Add a whitespace at the end of string to ensure it is found.     $name_ws = $name . " ";

    // Search for the name and translate it.     $this->drupalLogin($translate_user);
    $search = [
      'string' => $name_ws,
      'langcode' => $langcode,
      'translation' => 'untranslated',
    ];
    


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

    // Ensure that the CSRF token seed is reset on container rebuild.     if ($this->loggedInUser) {
      $current_user = $this->loggedInUser;
      $this->drupalLogout();
      $this->drupalLogin($current_user);
    }
  }

  /** * {@inheritdoc} */
  protected function drupalLogout() {
    parent::drupalLogout();
    $this->container->get('session_manager.metadata_bag')->stampNew();
  }

}
/** * Tests that threaded comments can be viewed. */
  public function testThreadedCommentView() {
    // Set comments to have subject required and preview disabled.     $this->drupalLogin($this->adminUser);
    $this->setCommentPreview(DRUPAL_DISABLED);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(TRUE);
    $this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
    $this->drupalLogout();

    // Post comment.     $this->drupalLogin($this->webUser);
    $comment_text = $this->randomMachineName();
    $comment_subject = $this->randomMachineName();
    $comment = $this->postComment($this->node, $comment_text$comment_subject);
    $this->assertTrue($this->commentExists($comment), 'Comment found.');

    // Check comment display.     $this->drupalGet('node/' . $this->node->id());
    $this->assertSession()->pageTextContains($comment_subject);
    
    $default_cache_contexts = [
      'languages:language_interface',
      'theme',
      'url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT,
    ];
    $cache_contexts = Cache::mergeContexts($default_cache_contexts$cache_contexts);

    // Assert contexts for user1 which has only default permissions.     $this->drupalLogin($this->adminUser);
    $this->drupalGet('test-page');
    $this->assertCacheContexts($cache_contexts$message);
    $this->drupalLogout();

    // Assert contexts for user2 which has some additional permissions.     $this->drupalLogin($this->adminUser2);
    $this->drupalGet('test-page');
    $this->assertCacheContexts($cache_contexts$message);
  }

  /** * Installs a given list of modules and rebuilds the cache. * * @param string[] $module_list * An array of module names. */
'new_mapping[browser_langcode]' => 'fr',
      'new_mapping[drupal_langcode]' => 'fr',
    ], 'Save configuration');
    $this->drupalGet('/admin/config/regional/language/detection/browser');
    $this->submitForm([
      'new_mapping[browser_langcode]' => 'en',
      'new_mapping[drupal_langcode]' => 'en',
    ], 'Save configuration');
    $this->drupalGet('/admin/config/regional/language/detection/selected');
    $this->submitForm(['edit-selected-langcode' => 'en'], 'Save configuration');

    $this->drupalLogout();
  }

  /** * Tests with browsers with and without Accept-Language header. */
  public function testAcceptLanguageEmptyDefault() {

    // Check correct headers.     $this->drupalGet('/en/system-test/echo/language test', []['Accept-Language' => 'en']);
    $this->assertSession()->responseHeaderEquals('Content-Language', 'en');
    $this->assertSession()->responseHeaderEquals('X-Drupal-Cache', 'MISS');

    
// Node 3.     $nodes[] = $this->createBookNode($book->id()$nodes[2]->book['nid']);
    // Node 4.     $nodes[] = $this->createBookNode($book->id()$nodes[3]->book['nid']);
    // Node 5.     $nodes[] = $this->createBookNode($book->id()$nodes[4]->book['nid']);
    // Node 6.     $nodes[] = $this->createBookNode($book->id()$nodes[5]->book['nid']);
    // Node 7.     $nodes[] = $this->createBookNode($book->id()$nodes[6]->book['nid']);

    $this->drupalLogout();

    return $nodes;
  }

  /** * Creates a book node. * * @param int|string $book_nid * A book node ID or set to 'new' to create a new book. * @param int|null $parent * (optional) Parent book reference ID. Defaults to NULL. * * @return \Drupal\node\NodeInterface * The book node. */
    $config->set('url.prefixes.' . $langcodes[0]$langcodes[0]);
    $config->save();

    $this->rebuildContainer();

    $languages = [];
    foreach ($langcodes as $langcode) {
      $languages[$langcode] = ConfigurableLanguage::load($langcode);
    }

    // Use a UI form submission to make the node type and menu link content entity translatable.     $this->drupalLogout();
    $this->drupalLogin($this->rootUser);
    $edit = [
      'entity_types[node]' => TRUE,
      'entity_types[menu_link_content]' => TRUE,
      'settings[node][page][settings][language][language_alterable]' => TRUE,
      'settings[node][page][translatable]' => TRUE,
      'settings[node][page][fields][title]' => TRUE,
      'settings[menu_link_content][menu_link_content][translatable]' => TRUE,
    ];
    $this->drupalGet('admin/config/regional/content-language');
    $this->submitForm($edit, 'Save configuration');

    
    $langcode = 'xx';
    // The English name for the language.     $name = $this->randomMachineName(16);
    $edit = [
      'predefined_langcode' => 'custom',
      'langcode' => $langcode,
      'label' => $name,
      'direction' => LanguageInterface::DIRECTION_LTR,
    ];
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add custom language');
    $this->drupalLogout();

    // Log in as normal user and edit account settings.     $this->drupalLogin($web_user);
    $path = 'user/' . $web_user->id() . '/edit';
    $this->drupalGet($path);
    // Ensure language settings widget is available.     $this->assertSession()->pageTextContains('Language');
    // Ensure custom language is present.     $this->assertSession()->pageTextContains($name);
    // Switch to our custom language.     $edit = [
      

    $file->setTemporary();
    $file->setOwner($author);
    // Create the file itself.     file_put_contents($file->getFileUri()$this->randomString());
    $file->save();

    // The image should be visible for its author.     $this->drupalGet($src);
    $this->assertSession()->statusCodeEquals(200);
    // The not-yet-permanent image should NOT be visible for anonymous.     $this->drupalLogout();
    $this->drupalGet($src);
    $this->assertSession()->statusCodeEquals(403);

    // Resave the file to be permanent.     $file->setPermanent();
    $file->save();

    // Create some nodes to ensure file usage count does not match the ID's     // of the nodes we are going to check.     for ($i = 0; $i < 5; $i++) {
      $this->drupalCreateNode([
        
// Verify that the history metadata is updated.     $this->drupalGet('activity');
    $this->assertHistoryMetadata($node->id()$node->getChangedTime()$node->get('comment')->last_comment_timestamp);
    $this->drupalGet('activity/' . $this->user->id());
    $this->assertHistoryMetadata($node->id()$node->getChangedTime()$node->get('comment')->last_comment_timestamp);
    $this->drupalGet('user/' . $this->user->id() . '/activity');
    $this->assertHistoryMetadata($node->id()$node->getChangedTime()$node->get('comment')->last_comment_timestamp);

    // Log out, now verify that the metadata is still there, but the library is     // not.     $this->drupalLogout();
    $this->drupalGet('activity');
    $this->assertHistoryMetadata($node->id()$node->getChangedTime()$node->get('comment')->last_comment_timestamp, FALSE);
    $this->drupalGet('user/' . $this->user->id() . '/activity');
    $this->assertHistoryMetadata($node->id()$node->getChangedTime()$node->get('comment')->last_comment_timestamp, FALSE);
  }

  /** * Tests for ordering on a users tracker listing when comments are posted. */
  public function testTrackerOrderingNewComments() {
    $this->drupalLogin($this->user);

    
$this->drupalGet('/entity_test_with_bundle/add');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->linkExists('Test label');
    $this->assertSession()->linkExists('Test2 label');
    $this->assertSession()->linkNotExists('Forbidden to create bundle');
    $this->assertSession()->linkNotExists('Test3 label');
    $this->clickLink('Test label');
    $this->assertSession()->statusCodeEquals(200);

    // Without any permissions, access must be denied.     $this->drupalLogout();
    $this->drupalGet('/entity_test_with_bundle/add');
    $this->assertSession()->statusCodeEquals(403);

    // Create a new user that has bundle create permissions.     $user = $this->drupalCreateUser([
      'administer entity_test_bundle content',
    ]);
    $this->drupalLogin($user);

    // User has access to the add page but no bundles are shown because the user     // does not have bundle specific permissions. The add bundle message is
$stats_path = $base_url . '/' . $this->getModulePath('statistics') . '/statistics.php';
    $client = $this->getHttpClient();
    $client->post($stats_path['form_params' => ['nid' => $this->node->id()]]);
    $this->drupalGet('test_statistics_integration');

    /** @var \Drupal\statistics\StatisticsViewsResult $statistics */
    $statistics = \Drupal::service('statistics.storage.node')->fetchView($this->node->id());
    $this->assertSession()->pageTextContains('Total views: 1');
    $this->assertSession()->pageTextContains('Views today: 1');
    $this->assertSession()->pageTextContains('Most recent view: ' . date('Y', $statistics->getTimestamp()));

    $this->drupalLogout();
    $this->drupalLogin($this->deniedUser);
    $this->drupalGet('test_statistics_integration');
    $this->assertSession()->statusCodeEquals(200);

    $this->assertSession()->pageTextNotContains('Total views:');
    $this->assertSession()->pageTextNotContains('Views today:');
    $this->assertSession()->pageTextNotContains('Most recent view:');
  }

}
$archiver->extract($temp_directory['system.maintenance.yml']);
    $file_contents = file_get_contents($temp_directory . '/' . 'system.maintenance.yml');
    $exported = Yaml::decode($file_contents);
    $this->assertNotSame('Foo', $exported['message']);

    // Check the single export form doesn't have "form-required" elements.     $this->drupalGet('admin/config/development/configuration/single/export');
    $this->assertSession()->responseNotContains('js-form-required form-required');

    // Ensure the temporary file is not available to users without the     // permission.     $this->drupalLogout();
    $this->drupalGet('system/temporary', ['query' => ['file' => 'config.tar.gz']]);
    $this->assertSession()->statusCodeEquals(403);
  }

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