pageTextContainsOnce example

$assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    $this->drupalGet($path);
    $page->clickLink('Add section');
    $assert_session->waitForElementVisible('named', ['link', 'One column']);
    $assert_session->pageTextNotContains('You have unsaved changes.');
    $page->clickLink('One column');
    $assert_session->waitForElementVisible('named', ['button', 'Add section']);
    $page->pressButton('Add section');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->pageTextContainsOnce('You have unsaved changes.');

    // Reload the page.     $this->drupalGet($path);
    $assert_session->pageTextContainsOnce('You have unsaved changes.');
  }

  /** * Tests that elements that open the dialog are properly highlighted. */
  public function testAddHighlights() {
    $assert_session = $this->assertSession();
    
1 => 'AND',
        2 => 'OR',
      ],
    ];
    $view->save();

    $this->drupalGet('test-filter-taxonomy-index-tid');
    // We expect no nodes tagged with term 1.0 or 1.1. The node tagged with     // term 2.0 and the untagged node will be shown.     $this->assertSession()->pageTextNotContains($node_with_term_1_0->label());
    $this->assertSession()->pageTextNotContains($node_with_terms_1_0_and_1_1->label());
    $this->assertSession()->pageTextContainsOnce($node_with_term_2_0->label());
    $this->assertSession()->pageTextContainsOnce($node_no_term->label());

    // Case 2:     // - filter "tid" with multiple terms as "is one of"     // - filter "tid_2" with a single term as "is one of"     $view = View::load('test_filter_taxonomy_index_tid');
    $display =& $view->getDisplay('default');
    $display['display_options']['filters']['tid']['value'][0] = $this->terms[1][0]->id();
    $display['display_options']['filters']['tid']['value'][1] = $this->terms[1][1]->id();
    $display['display_options']['filters']['tid']['operator'] = 'or';
    $display['display_options']['filters']['tid']['group'] = 2;
    
// Hide the message field label.     $display_edit = [
      'fields[message][label]' => 'hidden',
    ];
    $this->drupalGet('admin/structure/contact/manage/' . $contact_form . '/display');
    $this->submitForm($display_edit, 'Save');

    $this->drupalGet($form->toUrl('canonical'));
    $this->submitForm($edit, 'Preview');
    // 'Message' should only be displayed once now with the actual message     // displayed twice.     $this->assertSession()->pageTextContainsOnce('Message');
    $this->assertSession()->pageTextMatchesCount(2, '/' . $message . '/');
    // Check for label and message in form element.     $this->assertSession()->elementTextEquals('css', 'label[for="edit-message-0-value"]', 'Message');
    $this->assertSession()->fieldValueEquals('edit-message-0-value', $message);
    // Check for message in preview but no label.     $this->assertSession()->elementTextNotContains('css', '#edit-preview', 'Message');
    $this->assertSession()->elementTextContains('css', '#edit-preview', $message);

    // Set the preview field to 'hidden' in the view mode and check that the     // field is hidden.     $edit = [
      
$this->assertSession()->pageTextMatchesCount(1, '/does-not-exist/');
  }

  /** * @covers ::pageTextContainsOnce */
  public function testPageTextContainsOnce() {
    $this->drupalLogin($this->drupalCreateUser());

    // Visit a Drupal page that requires login.     $this->drupalGet('test-page');
    $this->assertSession()->pageTextContainsOnce('Test page text.');

    $this->expectException(ResponseTextException::class);
    $this->expectExceptionMessage("Failed asserting that the page matches the pattern '/does\\-not\\-exist/ui' 1 time(s), 0 found.");
    $this->assertSession()->pageTextContainsOnce('does-not-exist');
  }

  /** * @covers ::elementTextEquals */
  public function testElementTextEquals(): void {
    $this->drupalGet('test-page');
    

  public function testAjaxCallMaintenanceMode(): void {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    \Drupal::state()->set('system.maintenance_mode', TRUE);

    $this->drupalGet('ajax-test/insert-inline-wrapper');
    $assert_session->pageTextContains('Target inline');
    $page->clickLink('Link html pre-wrapped-div');
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()->pageTextContainsOnce('Operating in maintenance mode');
  }

}
$session = $this->assertSession();
    /** @var \Drupal\Core\Entity\EntityTypeManager $entity_type_manager */
    $entity_type_manager = \Drupal::service('entity_type.manager');

    $session->pageTextContains('WARNING: Content may be overwritten on your new site.');
    $session->pageTextContains('There is conflicting content of these types:');
    $this->assertNotEmpty($entity_types);
    foreach ($entity_types as $entity_type) {
      $label = $entity_type_manager->getDefinition($entity_type)->getPluralLabel();
      $session->pageTextContains($label);
    }
    $session->pageTextContainsOnce('content items');
    $session->pageTextContains('There is translated content of these types:');
  }

  /** * Helper to assert content on the Review form. * * @param array|null $available_paths * An array of modules that will be upgraded. Defaults to * $this->getAvailablePaths(). * @param array|null $missing_paths * An array of modules that will not be upgraded. Defaults to * $this->getMissingPaths(). * * @throws \Behat\Mink\Exception\ExpectationException */
$this->submitForm($edit, 'Save content type');

    // Create a node.     $edit = [];
    $edit['title[0][value]'] = $this->randomMachineName(8);
    $edit['body[0][value]'] = $this->randomMachineName(16);
    $this->drupalGet('node/add/page');
    $this->submitForm($edit, 'Save');

    // Check that the post information is displayed.     $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
    $this->assertSession()->pageTextContainsOnce('Submitted by');
    $node->delete();

    // Set "Basic page" content type to display post information.     $edit = [];
    $edit['display_submitted'] = FALSE;
    $this->drupalGet('admin/structure/types/manage/page');
    $this->submitForm($edit, 'Save content type');

    // Create a node.     $edit = [];
    $edit['title[0][value]'] = $this->randomMachineName(8);
    
$this->drupalGet('tabledrag_test');

    // By default no text is visible.     $this->assertSession()->pageTextNotContains('You have unsaved changes.');
    // Try to make a non-allowed action, like moving further down the last row.     // No changes happen, so no message should be shown.     $this->moveRowWithKeyboard($this->findRowById(5), 'down');
    $this->assertSession()->pageTextNotContains('You have unsaved changes.');

    // Make a change. The message will appear.     $this->moveRowWithKeyboard($this->findRowById(5), 'right');
    $this->assertSession()->pageTextContainsOnce('You have unsaved changes.');

    // Make another change, the text will stay visible and appear only once.     $this->moveRowWithKeyboard($this->findRowById(2), 'up');
    $this->assertSession()->pageTextContainsOnce('You have unsaved changes.');
  }

  /** * Asserts that several pieces of markup are in a given order in the page. * * @param string[] $items * An ordered list of strings. * * @throws \Behat\Mink\Exception\ExpectationException * When any of the given string is not found. * * @todo Remove this and use the WebAssert method when #2817657 is done. * * @internal */
    // hope that 'Up to date' is not unique.     $this->assertSession()->pageTextMatchesCount(3, '/Up to date/');
    // It should say we failed to get data, not that we're missing an update.     $this->assertSession()->pageTextNotContains('Update available');

    // We need to check that this string is found as part of a project row, not     // just in the "Failed to get available update data" message at the top of     // the page.     $this->assertSession()->responseContains('<div class="project-update__status">Failed to get available update data');

    // We should see the output messages from fetching manually.     $this->assertSession()->pageTextContainsOnce('Checked available update data for 3 projects.');
    $this->assertSession()->pageTextContainsOnce('Failed to get available update data for one project.');

    // The other two should be listed as projects.     $this->assertSession()->linkExists('AAA Update test');
    $this->assertSession()->linkByHrefExists('http://example.com/project/aaa_update_test');
    $this->assertSession()->linkNotExists('BBB Update test');
    $this->assertSession()->linkByHrefNotExists('http://example.com/project/bbb_update_test');
    $this->assertSession()->linkExists('CCC Update test');
    $this->assertSession()->linkByHrefExists('http://example.com/project/ccc_update_test');
  }

  
protected function doTestMenuLinksDiscoveredAlter() {
    // Check that machine name does not need to be defined since it is already     // set as the key of each menu link.     /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
    $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
    $menu_links = $menu_link_manager->loadLinksByRoute('menu_test.custom');
    $menu_link = reset($menu_links);
    $this->assertEquals('menu_test.custom', $menu_link->getPluginId(), 'Menu links added at hook_menu_links_discovered_alter() obtain the machine name from the $links key.');
    // Make sure that rebuilding the menu tree does not produce duplicates of     // links added by hook_menu_links_discovered_alter().     $this->drupalGet('menu-test');
    $this->assertSession()->pageTextContainsOnce('Custom link');
  }

  /** * Tests for menu hierarchy. */
  protected function doTestMenuHierarchy() {
    /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
    $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
    $menu_links = $menu_link_manager->loadLinksByRoute('menu_test.hierarchy_parent');
    $parent_link = reset($menu_links);
    $menu_links = $menu_link_manager->loadLinksByRoute('menu_test.hierarchy_parent_child');
    
$this->drupalGet('admin/modules');
    $this->assertSession()->pageTextNotContains('There are updates available for your version of Drupal.');
    $this->assertSession()->pageTextContains('There is a security update available for your version of Drupal.');

    // Make sure admin/appearance warns you you're missing a security update.     $this->drupalGet('admin/appearance');
    $this->assertSession()->pageTextNotContains('There are updates available for your version of Drupal.');
    $this->assertSession()->pageTextContains('There is a security update available for your version of Drupal.');

    // Make sure duplicate messages don't appear on Update status pages.     $this->drupalGet('admin/reports/status');
    $this->assertSession()->pageTextContainsOnce('There is a security update available for your version of Drupal.');

    $this->drupalGet('admin/reports/updates');
    $this->assertSession()->pageTextNotContains('There is a security update available for your version of Drupal.');

    $this->drupalGet('admin/reports/updates/settings');
    $this->assertSession()->pageTextNotContains('There is a security update available for your version of Drupal.');
  }

  /** * Tests the Update Manager module when the update server returns 503 errors. */
  
$this->submitForm($search, 'Filter');

    // Save complete translations for the string in langcode fr.     $edit = [
      "strings[$lid][translations][0]" => '1 seconde updated',
      "strings[$lid][translations][1]" => '@count secondes updated',
    ];
    $this->drupalGet($path);
    $this->submitForm($edit, 'Save translations');

    // User interface input for translating seconds should not be duplicated     $this->assertSession()->pageTextContainsOnce('@count seconds');

    // Member for time should be translated. Change the created time to ensure     // that the we're dealing in multiple seconds and it can't be exactly 1     // second or minute.     $this->adminUser->set('created', time() - 2)->save();
    $this->drupalGet('user');
    $this->assertSession()->pageTextContains("secondes updated");
  }

  /** * Tests plural editing and export functionality. */
/** * Tests the upgrade report with the view enabled, disabled and uninstalled. */
  public function testUpgradeReport() {
    $session = $this->assertSession();

    $this->assertTrue(View::load('watchdog')->status(), 'Watchdog view is enabled');
    // Tests redirection to report page when the watchdog view is enabled.     $this->drupalGet('admin/reports/upgrade');
    $session->optionExists('type[]', 'migrate_drupal_ui')->isSelected();
    $session->pageTextContainsOnce('A test message');

    // Disable the watchdog view.     $this->drupalGet('admin/structure/views');
    $this->assertTrue($this->clickViewsOperationsLink('Disable', '/watchdog/'));
    $session->statusCodeEquals(200);

    // Tests redirection to report page when the watchdog view is disabled.     $this->drupalGet('admin/reports/upgrade');
    $session->optionExists('type[]', 'migrate_drupal_ui')->isSelected();
    $session->pageTextContainsOnce('A test message');

    


  /** * Tests that errors messages are displayed for exposed filters via ajax. */
  public function testExposedFilterErrorMessages(): void {
    $this->drupalGet('test_user_name');
    // Submit an invalid name, triggering validation errors.     $name = $this->randomMachineName();
    $this->submitForm(['uid' => $name], 'Apply');
    $this->assertSession()->waitForElement('css', 'div[aria-label="Error message"]');
    $this->assertSession()->pageTextContainsOnce(sprintf('There are no users matching "%s"', $name));

    \Drupal::service('module_installer')->install(['inline_form_errors']);

    $this->drupalGet('test_user_name');
    // Submit an invalid name, triggering validation errors.     $name = $this->randomMachineName();
    $this->submitForm(['uid' => $name], 'Apply');
    $this->assertSession()->waitForElement('css', 'div[aria-label="Error message"]');
    $this->assertSession()->pageTextContainsOnce(sprintf('There are no users matching "%s"', $name));
  }

}
    $edit[$this->field->getName() . '[]'] = $term2->id();
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->submitForm($edit, 'Save');

    $this->drupalGet('node/' . $node->id());
    $this->assertSession()->pageTextContains($term2->getName());

    // Preview the node.     $this->drupalGet('node/' . $node->id() . '/edit');
    $this->submitForm($edit, 'Preview');
    // Ensure that term is displayed when previewing the node.     $this->assertSession()->pageTextContainsOnce($term2->getName());
    $this->drupalGet('node/' . $node->id() . '/edit');
    $this->submitForm([], 'Preview');
    // Ensure that term is displayed when previewing the node again.     $this->assertSession()->pageTextContainsOnce($term2->getName());
  }

  /** * Tests term creation with a free-tagging vocabulary from the node form. */
  public function testNodeTermCreationAndDeletion() {
    // Enable tags in the vocabulary.
Home | Imprint | This part of the site doesn't use cookies.