elementTextContains example

$dangerous = 'Bad html <script>alert(123);</script>';
    $sanitized = Html::escape($dangerous);
    $this->assertSession()->responseNotContains($dangerous);
    $this->assertSession()->responseContains($sanitized);
  }

  /** * Tests legacy field asserts which use xpath directly. */
  public function testXpathAsserts() {
    $this->drupalGet('test-field-xpath');
    $this->assertSession()->elementTextContains('xpath', '//table/tbody/tr[2]/td[1]', 'one');

    $this->assertSession()->fieldValueEquals('edit-name', 'Test name');
    $this->assertSession()->fieldValueEquals('edit-options', '2');

    $this->assertSession()->elementNotExists('xpath', '//notexisting');
    $this->assertSession()->fieldValueNotEquals('edit-name', 'wrong value');

    // Test that the assertion fails correctly.     try {
      $this->assertSession()->fieldExists('notexisting');
      $this->fail('The "notexisting" field was found.');
    }
$view['id'] = strtolower($this->randomMachineName());
    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view, 'Save and edit');

    // Verify that the views sql is shown.     $this->submitForm([], 'Update preview');
    $this->assertSession()->elementExists('xpath', '//div[@class="views-query-info"]//pre');
    // Verify that no placeholders are shown in the views sql.     $this->assertSession()->elementTextNotContains('xpath', '//div[@class="views-query-info"]//pre', 'db_condition_placeholder');
    // Verify that the placeholders in the views sql are replaced by the actual     // values.     $this->assertSession()->elementTextContains('xpath', '//div[@class="views-query-info"]//pre', Database::getConnection()->escapeField("node_field_data.status") . " = '1'");

    // Test the advanced settings form.
    // Test the confirmation message.     $this->drupalGet('admin/structure/views/settings/advanced');
    $this->submitForm([], 'Save configuration');
    $this->assertSession()->pageTextContains('The configuration options have been saved.');

    $edit = [
      'skip_cache' => TRUE,
      'sql_signature' => TRUE,
    ];
    $password_confirm_widget->fillField('Password', 'o');
    $this->assertFalse($password_confirm_item->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')->isVisible());
    $this->assertTrue($password_confirm_item->find('css', "$password_confirm_selector + .password-suggestions > ul > li")->isVisible());
    $this->assert->elementContains('css', "$password_confirm_widget_selector $password_parent_selector", '<div aria-live="polite" aria-atomic="true" class="password-strength__title">Password strength: <span class="password-strength__text" data-drupal-selector="password-strength-text">Weak</span></div>');

    // Now fill both the main and confirm input.     $password_confirm_widget->fillField('Password', 'oooooooooO0∘');
    $password_confirm_widget->fillField('Confirm password', 'oooooooooO0∘');

    // Bar should be 100% wide.     $this->assert->elementAttributeContains('css', 'input.js-password-field + .password-strength > [data-drupal-selector="password-strength-meter"] [data-drupal-selector="password-strength-indicator"]', 'style', 'width: 100%;');
    $this->assert->elementTextContains('css', "$password_confirm_widget_selector $password_parent_selector [data-drupal-selector='password-strength-text']", 'Strong');

    // Password match message must be visible.     $this->assertTrue($password_confirm_item->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')->isVisible());
    $this->assertTrue($password_confirm_item->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"] > [data-drupal-selector="password-match-status-text"]')->hasClass('ok'));
    $this->assert->elementTextContains('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"] > [data-drupal-selector="password-match-status-text"]', 'yes');

    // Password suggestions should get invisible.     $this->assertFalse($password_confirm_item->find('css', "$password_confirm_selector + .password-suggestions")->isVisible());
  }

  /** * Ensures that password match message is visible when widget is initialized. */
$page = $this->getSession()->getPage();

    $this->drupalLogin($this->drupalCreateUser(['configure any layout']));

    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    $this->drupalGet('node/1');
    $page->clickLink('Layout');
    $assert_session->elementTextContains('css', '.layout-builder__message.layout-builder__message--overrides', 'You are editing the layout for this Bundle with section field content item.');
    $assert_session->linkNotExists('Edit the template for all Bundle with section field content items instead.');
  }

  /** * Tests Layout Builder overrides without Field UI installed. */
  public function testOverridesWithoutFieldUi() {
    $this->container->get('module_installer')->uninstall(['field_ui']);

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

    
'view the administration theme',
    ]));
  }

  /** * Tests an entity type that has fields shown by default. */
  public function testNodeView() {
    // By default, the one-column layout is used.     $this->drupalGet('node/1');
    $this->assertSession()->elementExists('css', '.layout--onecol');
    $this->assertSession()->elementTextContains('css', '.layout__region--content', 'The node body');

    $this->drupalGet('admin/structure/types/manage/article/display');
    $this->assertEquals(['Content', 'Disabled']$this->getRegionTitles());
    $this->assertSession()->optionExists('fields[body][region]', 'content');
  }

  /** * Tests that changes to the regions still leave the fields visible. */
  public function testRegionChanges() {
    $this->drupalGet('admin/structure/types/manage/article/display');
    


  /** * Tests the status message when enabling one or more modules. */
  public function testModulesListFormStatusMessage() {
    $this->drupalGet('admin/modules');

    // Enable a module that does not define permissions.     $edit = ['modules[layout_discovery][enable]' => 'layout_discovery'];
    $this->submitForm($edit, 'Install');
    $this->assertSession()->elementTextContains('xpath', "//div[@role='contentinfo' and h2[text()='Status message']]", 'Module Layout Discovery has been enabled.');
    $this->assertSession()->elementNotExists('xpath', "//div[@role='contentinfo' and h2[text()='Status message']]//a");

    // Enable a module that defines permissions.     $edit = ['modules[action][enable]' => 'action'];
    $this->submitForm($edit, 'Install');
    $this->assertSession()->elementTextContains('xpath', "//div[@role='contentinfo' and h2[text()='Status message']]", 'Module Actions UI has been enabled.');
    $this->assertSession()->elementExists('xpath', "//div[@role='contentinfo' and h2[text()='Status message']]//a[contains(@href, '/admin/people/permissions/module/action')]");

    // Enable a module that has dependencies and both define permissions.     $edit = ['modules[content_moderation][enable]' => 'content_moderation'];
    $this->submitForm($edit, 'Install');
    
$assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();
    $this->standardTests();
    $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Not supported');
    $all_security_release_urls = array_map(function D$link) {
      return $link->getAttribute('href');
    }$page->findAll('css', "$update_element_css_locator .version-security a[href$='-release']"));
    if ($expected_security_releases) {
      $expected_release_urls = [];
      if ($expected_update_message_type === static::SECURITY_UPDATE_REQUIRED) {
        $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Update available');
        $assert_session->elementTextContains('css', $update_element_css_locator, 'Security update required!');
        // Verify that the error icon is found.         $assert_session->responseContains('error.svg');
      }
      else {
        $assert_session->elementTextContains('css', $update_element_css_locator, 'Update available');
        $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Security update required!');
      }
      $assert_session->elementTextNotContains('css', $update_element_css_locator, 'Up to date');
      foreach ($expected_security_releases as $expected_security_release) {
        $expected_url_version = str_replace('.', '-', $expected_security_release);
        $release_url = "http://example.com/$project_path_part-$expected_url_version-release";
        
$this->assertEquals(['default', 'page']$options, 'Make sure all displays appears as expected.');

    // Post and save this and check the output.     $this->drupalGet('admin/structure/views/nojs/display/' . $view_name . '/feed_1/displays');
    $this->submitForm(['displays[page]' => 'page'], 'Apply');
    // Options summary should be escaped.     $this->assertSession()->assertEscaped('<em>Page</em>');
    $this->assertSession()->responseNotContains('<em>Page</em>');

    $this->drupalGet('admin/structure/views/view/' . $view_name . '/edit/feed_1');
    $this->assertSession()->elementTextContains('xpath', '//*[@id="views-feed-1-displays"]', 'Page');

    // Add the default display, so there should now be multiple displays.     $this->drupalGet('admin/structure/views/nojs/display/' . $view_name . '/feed_1/displays');
    $this->submitForm(['displays[default]' => 'default'], 'Apply');
    $this->drupalGet('admin/structure/views/view/' . $view_name . '/edit/feed_1');
    $this->assertSession()->elementTextContains('xpath', '//*[@id="views-feed-1-displays"]', 'Multiple displays');
  }

}
$this->assertCurrentMessages($current_messages$messagesSelector);
    $this->click('[id="remove-type"]');
    $this->assertCurrentMessages([$last_message]$messagesSelector);
    $this->click('[id="clear-all"]');
    $this->assertCurrentMessages([]$messagesSelector);

    // Confirm that when adding a message with an "id" specified but no status     // that it receives the default status.     $this->click('[id="id-no-status"]');
    $no_status_msg = 'Msg-id-no-status';
    $this->assertCurrentMessages([$no_status_msg]$messagesSelector);
    $web_assert->elementTextContains('css', "$messagesSelector .messages--status[data-drupal-message-id=\"my-special-id\"]", $no_status_msg);

  }

  /** * Asserts that currently shown messages match expected messages. * * @param array $expected_messages * Expected messages. * @param string $messagesSelector * The css selector for the containing messages element. * * @internal */
      $this->drupalGet('/node/add/blog');
      $this->waitForEditor();
      $this->pressEditorButton('Insert Media');

      $assert_session = $this->assertSession();
      $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-modal #media-library-wrapper'));

      if (empty($allowed_media_types) || count($allowed_media_types) === 2) {
        $menu = $assert_session->elementExists('css', '.js-media-library-menu');
        $assert_session->elementExists('named', ['link', 'Image']$menu);
        $assert_session->elementExists('named', ['link', 'Arrakis']$menu);
        $assert_session->elementTextContains('css', '.js-media-library-item', 'Fear is the mind-killer');
      }
      elseif (count($allowed_media_types) === 1 && !empty($allowed_media_types['image'])) {
        // No tabs should appear if there's only one media type available.         $assert_session->elementNotExists('css', '.js-media-library-menu');
        $assert_session->elementTextContains('css', '.js-media-library-item', 'Fear is the mind-killer');
      }
      elseif (count($allowed_media_types) === 1 && !empty($allowed_media_types['arrakis'])) {
        // No tabs should appear if there's only one media type available.         $assert_session->elementNotExists('css', '.js-media-library-menu');
        $assert_session->elementTextContains('css', '.js-media-library-item', 'Le baron Vladimir Harkonnen');
      }
    }
$this->drupalGet('entity_test/add');
    $edit = [
      "{$field_name}[0][value]" => $integer_value,
    ];
    $this->submitForm($edit, 'Save');
    preg_match('|entity_test/manage/(\d+)|', $this->getUrl()$match);
    $id = $match[1];
    $this->assertSession()->pageTextContains('entity_test ' . $id . ' has been created.');
    $this->drupalGet('entity_test/' . $id);
    // Verify that the "content" attribute has been set to the value of the     // field, and the prefix is being displayed.     $this->assertSession()->elementTextContains('xpath', '//div[@content="' . $integer_value . '"]', 'ThePrefix' . $integer_value);
  }

  /** * Tests float field. */
  public function testNumberFloatField() {
    // Create a field with settings to validate.     $field_name = mb_strtolower($this->randomMachineName());
    FieldStorageConfig::create([
      'field_name' => $field_name,
      'entity_type' => 'entity_test',
      
// Create a media item.     $media = Media::create([
      'bundle' => $media_type->id(),
      'name' => 'Fantastic!',
    ]);
    $media->save();

    $this->drupalGet('media/' . $media->id());
    // Verify the "name" field is really not present. The name should be in the     // h1 with no additional markup in the h1.     $assert_session->elementTextContains('css', 'h1', $media->getName());
    $assert_session->elementNotExists('css', 'h1 div');

    // Enable the field on the display and verify it becomes visible on the UI.     $this->drupalGet("/admin/structure/media/manage/{$media_type->id()}/display");
    $assert_session->buttonExists('Show row weights')->press();
    $this->assertSession()->waitForElementVisible('css', '[name="fields[name][region]"]');
    $page->selectFieldOption('fields[name][region]', 'content');
    $assert_session->waitForElementVisible('css', '#edit-fields-name-settings-edit');
    $page->pressButton('Save');
    $this->drupalGet('media/' . $media->id());
    // Verify the name is present, and its text matches what is expected. Now
    $page->findField('settings[handler_settings][target_bundles][' . $this->targetType . ']')->uncheck();
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertFalse($sort_by->isVisible(), 'The "sort by" options are hidden yet again.');
    $this->assertFieldSelectOptions('settings[handler_settings][sort][field]', ['_none']);

    // Third step: confirm.     $page->findField('settings[handler_settings][target_bundles][' . $this->targetType . ']')->setValue($this->targetType);
    $assert_session->assertWaitOnAjaxRequest();
    $this->submitForm(['required' => '1'], 'Save settings');

    // Check that the field appears in the overview form.     $this->assertSession()->elementTextContains('xpath', '//table[@id="field-overview"]//tr[@id="field-test"]/td[1]', "Test");

    // Check that the field settings form can be submitted again, even when the     // field is required.     // The first 'Edit' link is for the Body field.     $this->clickLink('Edit', 1);
    $this->submitForm([], 'Save settings');

    // Switch the target type to 'taxonomy_term' and check that the settings     // specific to its selection handler are displayed.     $field_name = 'node.' . $this->type . '.field_test';
    $edit = [
      
$page->clickLink("Install $theme_name theme");
    $assert_session->addressEquals('admin/appearance');
    $assert_session->pageTextContains("The $theme_name theme has been installed");

    // Confirm that the dependee modules can't be uninstalled because an enabled     // theme depends on them.     $this->drupalGet('admin/modules/uninstall');
    foreach ($all_dependent_modules as $attribute) {
      $assert_session->elementExists('css', "[name=\"uninstall[$attribute]\"][disabled]");
    }
    foreach ($required_by_messages as $selector => $message) {
      $assert_session->elementTextContains('css', $selector$message);
    }

    // Uninstall the theme that depends on the modules, and confirm the modules     // can now be uninstalled.     $this->uninstallTheme($theme_name);
    $this->drupalGet('admin/modules/uninstall');

    // Only attempt to uninstall modules not required by the base theme.     $modules_to_uninstall = array_diff($all_dependent_modules$base_theme_module_names);
    $this->uninstallModules($modules_to_uninstall);

    
$this->refreshUpdateStatus(['drupal' => $core_fixture, 'aaa_update_test' => $a_fixture, 'bbb_update_test' => $b_fixture]);
    $this->drupalGet('admin/reports/updates/update');

    if ($compatible) {
      // Verify the number of rows in the table.       $assert_session->elementsCount('css', "$compatible_table_locator tbody tr", count($compatible));
      // We never want to see a compatibility range in the compatible table.       $assert_session->elementTextNotContains('css', $compatible_table_locator, 'Requires Drupal core');
      foreach ($compatible as $module => $version) {
        $compatible_row = "$compatible_table_locator tbody tr:contains('$module Update test')";
        // First <td> is the checkbox, so start with td #2.         $assert_session->elementTextContains('css', "$compatible_row td:nth-of-type(2)", "$module Update test");
        // Both contrib modules use 8.x-1.0 as the currently installed version.         $assert_session->elementTextContains('css', "$compatible_row td:nth-of-type(3)", '8.x-1.0');
        $assert_session->elementTextContains('css', "$compatible_row td:nth-of-type(4)", $version);
      }
    }
    else {
      // Verify there is no compatible updates table.       $assert_session->elementNotExists('css', $compatible_table_locator);
    }

    if ($incompatible) {
      
Home | Imprint | This part of the site doesn't use cookies.