titleEquals example



  /** * Tests the page title of render arrays. * * @see \Drupal\test_page_test\Controller\Test */
  public function testRoutingTitle() {
    // Test the '#title' render array attribute.     $this->drupalGet('test-render-title');

    $this->assertSession()->titleEquals('Foo | Drupal');
    $this->assertSession()->elementTextEquals('xpath', '//h1[@class="page-title"]', 'Foo');

    // Test forms     $this->drupalGet('form-test/object-builder');

    $this->assertSession()->titleEquals('Test dynamic title | Drupal');
    $this->assertSession()->elementTextEquals('xpath', '//h1[@class="page-title"]', 'Test dynamic title');

    // Set some custom translated strings.     $settings_key = 'locale_custom_strings_en';

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

  /** * Tests the views UI. */
  public function testViewsUI() {
    $this->drupalGet('admin/structure/views/view/test_view/edit');
    $this->assertSession()->titleEquals('Test view (Views test data) | Drupal');
  }

}

    $this->resetAll();
    $this->rebuildContainer();
  }

  public function testTranslatedStrings() {
    $translation_url = 'admin/structure/views/view/files/translate/fr/add';
    $edit_url = 'admin/structure/views/view/files';

    // Check the original string.     $this->drupalGet($edit_url);
    $this->assertSession()->titleEquals('Files (File) | Drupal');

    // Translate the label of the view.     $this->drupalGet($translation_url);
    $edit = [
      'translation[config_names][views.view.files][label]' => 'Fichiers',
    ];
    $this->submitForm($edit, 'Save translation');

    // Check if the label is translated.     $this->drupalGet($edit_url['language' => \Drupal::languageManager()->getLanguage('fr')]);
    $this->assertSession()->titleEquals('Files (File) | Drupal');
    
// Check that the default value in user name field     // is the raw value and not a formatted one.     \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE);
    \Drupal::service('module_installer')->install(['user_hooks_test']);
    Cache::invalidateTags(['rendered']);
    $this->drupalGet('user/' . $user1->id() . '/edit');
    $this->assertSession()->fieldValueEquals('name', $user1->getAccountName());

    // Ensure the formatted name is displayed when expected.     $this->drupalGet('user/' . $user1->id());
    $this->assertSession()->responseContains($user1->getDisplayName());
    $this->assertSession()->titleEquals(strip_tags($user1->getDisplayName()) . ' | Drupal');

    // Check that filling out a single password field does not validate.     $edit = [];
    $edit['pass[pass1]'] = '';
    $edit['pass[pass2]'] = $this->randomMachineName();
    $this->drupalGet("user/" . $user1->id() . "/edit");
    $this->submitForm($edit, 'Save');
    $this->assertSession()->pageTextContains("The specified passwords do not match.");

    $edit['pass[pass1]'] = $this->randomMachineName();
    $edit['pass[pass2]'] = '';
    
// Add a user picture.     $image = current($this->drupalGetTestFiles('image'));
    $user_edit['files[user_picture_0]'] = \Drupal::service('file_system')->realpath($image->uri);
    $this->drupalGet('user/' . $this->webUser->id() . '/edit');
    $this->submitForm($user_edit, 'Save');

    // As the web user, fill in the comment form and preview the comment.     $this->drupalGet('node/' . $this->node->id());
    $this->submitForm($edit, 'Preview');

    // Check that the preview is displaying the title and body.     $this->assertSession()->titleEquals('Preview comment | Drupal');
    $this->assertSession()->pageTextContains($edit['subject[0][value]']);
    $this->assertSession()->pageTextContains($edit['comment_body[0][value]']);

    // Check that the title and body fields are displayed with the correct values.     $this->assertSession()->fieldValueEquals('subject[0][value]', $edit['subject[0][value]']);
    $this->assertSession()->fieldValueEquals('comment_body[0][value]', $edit['comment_body[0][value]']);

    // Check that the user picture is displayed.     $this->assertSession()->elementExists('xpath', "//article[contains(@class, 'preview')]//div[contains(@class, 'user-picture')]//img");

    // Ensure that preview node is displayed after the submit buttons of the form.


  /** * Tests the content block listing page with different permissions. */
  public function testListing() {
    // Test with the admin user.     $this->drupalLogin($this->drupalCreateUser(['access block library', 'administer block content']));
    $this->drupalGet('admin/content/block');

    // Test for the page title.     $this->assertSession()->titleEquals('Content blocks | Drupal');

    // Test for the table.     $this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//table');

    // Test the table header, two cells should be present.     $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/thead/tr/th', 2);

    // Test the contents of each th cell.     $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[1]', 'Block description');
    $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[2]', 'Operations');

    


  /** * Tests the content block listing page. */
  public function testListing() {
    // Test with an admin user.     $this->drupalLogin($this->adminUser);
    $this->drupalGet('admin/content/block');

    // Test for the page title.     $this->assertSession()->titleEquals('Content blocks | Drupal');

    // Test for the exposed filters.     $this->assertSession()->fieldExists('info');
    $this->assertSession()->fieldExists('type');

    // Test for the table.     $this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//table');

    // Test the table header, four cells should be present.     $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/thead/tr/th', 4);

    

  protected function verifyHelp($response = 200) {
    // Verify access to help topic pages.     foreach ($this->getTopicList() as $topic => $info) {
      // View help topic page.       $this->drupalGet('admin/help/topic/' . $topic);
      $session = $this->assertSession();
      $session->statusCodeEquals($response);
      if ($response == 200) {
        // Verify page information.         $name = $info['name'];
        $session->titleEquals($name . ' | Drupal');
        $session->responseContains('<h1>' . $name . '</h1>');
        foreach ($info['tags'] as $tag) {
          $session->responseHeaderContains('X-Drupal-Cache-Tags', $tag);
        }
      }
    }
  }

  /** * Verifies links on various topic pages. */
  
/** * Tests that analyze works in general. */
  public function testAnalyzeBasic() {
    $this->drupalLogin($this->adminUser);

    $this->drupalGet('admin/structure/views/view/test_view/edit');
    $this->assertSession()->linkExists('Analyze view');

    // This redirects the user to the analyze form.     $this->clickLink('Analyze view');
    $this->assertSession()->titleEquals('View analysis | Drupal');

    foreach (['ok', 'warning', 'error'] as $type) {
      // Check that analyse messages with the expected type found.       $this->assertSession()->elementExists('css', 'div.' . $type);
    }

    // This redirects the user back to the main views edit page.     $this->submitForm([], 'Ok');
  }

}
$this->assertSession()->pageTextContains('This page shows you all available administration tasks for each module.');
    }
    else {
      $this->assertSession()->pageTextNotContains('This page shows you all available administration tasks for each module.');
    }

    foreach ($this->getModuleList() as $module => $name) {
      // View module help page.       $this->drupalGet('admin/help/' . $module);
      $this->assertSession()->statusCodeEquals($response);
      if ($response == 200) {
        $this->assertSession()->titleEquals("$name | Drupal");
        $this->assertEquals($name$this->cssSelect('h1.page-title')[0]->getText(), "$module heading was displayed");
        $info = \Drupal::service('extension.list.module')->getExtensionInfo($module);
        $admin_tasks = system_get_module_admin_tasks($module$info);
        if (!empty($admin_tasks)) {
          $this->assertSession()->pageTextContains($name . ' administration pages');
        }
        foreach ($admin_tasks as $task) {
          $this->assertSession()->linkExists($task['title']);
          // Ensure there are no double escaped '&' or '<' characters.           $this->assertSession()->assertNoEscaped('&amp;');
          $this->assertSession()->assertNoEscaped('&lt;');
          
protected function verifyTopic($id$definitions$response = 200) {
    $definition = $definitions[$id];
    HelpTestTwigNodeVisitor::setStateValue('manner', 0);

    // Visit the URL for the topic.     $this->drupalGet('admin/help/topic/' . $id);

    // Verify the title and response.     $session = $this->assertSession();
    $session->statusCodeEquals($response);
    if ($response == 200) {
      $session->titleEquals($definition['label'] . ' | Drupal');
    }

    // Verify that all the related topics exist. Also check to see if any of     // them are top-level (we will need that in the next section).     $has_top_level_related = FALSE;
    if (isset($definition['related'])) {
      foreach ($definition['related'] as $related_id) {
        $this->assertArrayHasKey($related_id$definitions, 'Topic ' . $id . ' is only related to topics that exist: ' . $related_id);
        $has_top_level_related = $has_top_level_related || !empty($definitions[$related_id]['top_level']);
      }
    }

    
/** * {@inheritdoc} */
  protected function setUpSite() {
    // This form will never be reached.   }

  /** * Tests the expected requirements problem. */
  public function testRequirementsProblem() {
    $this->assertSession()->titleEquals('Requirements problem | Drupal');
    $this->assertSession()->pageTextContains('Database settings');
    $this->assertSession()->pageTextContains('Resolve all issues below to continue the installation. For help configuring your database server,');
    $this->assertSession()->pageTextContains('The database server version 10.2.31-MariaDB-1:10.2.31+maria~bionic-log is less than the minimum required version');
  }

}
$this->drupalGet('user/register');
    $this->submitForm($edit, 'Create new account');
    $this->assertSession()->pageTextContains('A welcome message with further instructions has been sent to your email address.');

    /** @var EntityStorageInterface $storage */
    $storage = $this->container->get('entity_type.manager')->getStorage('user');
    $accounts = $storage->loadByProperties(['name' => $name, 'mail' => $mail]);
    $new_user = reset($accounts);
    $this->assertTrue($new_user->isActive(), 'New account is active after registration.');
    $resetURL = user_pass_reset_url($new_user);
    $this->drupalGet($resetURL);
    $this->assertSession()->titleEquals('Set password | Drupal');

    // Allow registration by site visitors, but require administrator approval.     $config->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save();
    $edit = [];
    $edit['name'] = $name = $this->randomMachineName();
    $edit['mail'] = $mail = $edit['name'] . '@example.com';
    $this->drupalGet('user/register');
    $this->submitForm($edit, 'Create new account');
    $this->container->get('entity_type.manager')->getStorage('user')->resetCache();
    $accounts = $storage->loadByProperties(['name' => $name, 'mail' => $mail]);
    $new_user = reset($accounts);
    
/** * {@inheritdoc} */
  protected function setUpSite() {
    // This form will never be reached.   }

  /** * Tests the expected requirements problem. */
  public function testRequirementsProblem() {
    $this->assertSession()->titleEquals('Requirements problem | Drupal');
    $this->assertSession()->pageTextContains('Database settings');
    $this->assertSession()->pageTextContains('Resolve all issues below to continue the installation. For help configuring your database server,');
    $this->assertSession()->pageTextContains('[Tip: Drupal was attempting to connect to the database server via a socket, but the socket file could not be found. A Unix socket file is used if you do not specify a host name or if you specify the special host name localhost. To connect via TPC/IP use an IP address (127.0.0.1 for IPv4) instead of "localhost". This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.]');
  }

}
$this->assertSession()->pageTextContains('The machine-readable name must contain only lowercase letters, numbers, and underscores.');

    // Ensure that vocabulary titles are escaped properly.     $edit = [];
    $edit['name'] = 'Don\'t Panic';
    $edit['description'] = $this->randomMachineName();
    $edit['vid'] = 'don_t_panic';
    $this->drupalGet('admin/structure/taxonomy/add');
    $this->submitForm($edit, 'Save');

    $site_name = $this->config('system.site')->get('name');
    $this->assertSession()->titleEquals("Don't Panic | $site_name");

    // Delete the vocabulary.     $this->drupalGet('admin/structure/taxonomy');
    $href = Url::fromRoute('entity.taxonomy_vocabulary.delete_form', ['taxonomy_vocabulary' => $edit['vid']])->toString();
    $xpath = $this->assertSession()->buildXPathQuery('//a[contains(@href, :href)]', [':href' => $href]);
    $link = $this->assertSession()->elementExists('xpath', $xpath);
    $this->assertEquals('Delete vocabulary', $link->getText());
    $link->click();

    // Confirm deletion.     $this->assertSession()->responseContains(new FormattableMarkup('Are you sure you want to delete the vocabulary %name?', ['%name' => $edit['name']]));
    
Home | Imprint | This part of the site doesn't use cookies.