elementContains example

/** * Asserts that the update table element HTML contains the specified text. * * @param string $text * The expected text. * * @see \Behat\Mink\WebAssert::elementContains() */
  protected function assertUpdateTableElementContains($text) {
    $this->assertSession()
      ->elementContains('css', $this->updateTableLocator, $text);
  }

  /** * Asserts that the update table element HTML contains the specified text. * * @param string $text * The expected text. * * @see \Behat\Mink\WebAssert::elementNotContains() */
  protected function assertUpdateTableElementNotContains($text) {
    
$web_assert = $this->assertSession();
    $this->drupalGet('js_message_test_link');

    $current_messages = [];
    foreach (JSMessageTestController::getMessagesSelectors() as $messagesSelector) {
      $web_assert->elementExists('css', $messagesSelector);
      foreach (JSMessageTestController::getTypes() as $type) {
        $this->click('[id="add-' . $messagesSelector . '-' . $type . '"]');
        $selector = "$messagesSelector .messages.messages--$type";
        $msg_element = $web_assert->waitForElementVisible('css', $selector);
        $this->assertNotEmpty($msg_element, "Message element visible: $selector");
        $web_assert->elementContains('css', $selector, "This is a message of the type, $type. You be the judge of its importance.");
        $current_messages[$selector] = "This is a message of the type, $type. You be the judge of its importance.";
        $this->assertCurrentMessages($current_messages$messagesSelector);
      }
      // Remove messages 1 by 1 and confirm the messages are expected.       foreach (JSMessageTestController::getTypes() as $type) {
        $this->click('[id="remove-' . $messagesSelector . '-' . $type . '"]');
        $selector = "$messagesSelector .messages.messages--$type";
        // The message for this selector should not be on the page.         unset($current_messages[$selector]);
        $this->assertCurrentMessages($current_messages$messagesSelector);
      }
    }
$page = $this->getSession()->getPage();
    $overridden_block = $this->placeBlock('system_powered_by_block', [
      'id' => 'overridden_block',
      'label_display' => 1,
      'label' => 'This will be overridden.',
    ]);
    $this->drupalGet('user');
    $block_selector = $this->getBlockSelector($overridden_block);
    // Confirm the block is marked as Settings Tray editable.     $this->assertEquals('editable', $page->find('css', $block_selector)->getAttribute('data-drupal-settingstray'));
    // Confirm the label is not overridden.     $web_assert->elementContains('css', $block_selector, 'This will be overridden.');
    $this->enableEditMode();
    $this->openBlockForm($block_selector);

    // Confirm the block Settings Tray functionality is disabled when block is     // overridden.     $this->container->get('state')->set('settings_tray_override_test.block', TRUE);
    $overridden_block->save();
    $block_config = \Drupal::configFactory()->getEditable('block.block.overridden_block');
    $block_config->set('settings', $block_config->get('settings'))->save();

    $this->drupalGet('user');
    
$field_empty_types_message = 'There are no allowed media types configured for this field. <a href="' . $field_empty_types_url->toString() . '">Edit the field settings</a> to select the allowed media types.';

    $field_null_types_url = new Url('entity.field_config.node_field_edit_form', [
      'field_config' => 'node.basic_page.field_null_types_media',
    ] + $route_bundle_params);
    $field_null_types_message = 'There are no allowed media types configured for this field. <a href="' . $field_null_types_url->toString() . '">Edit the field settings</a> to select the allowed media types.';

    // Visit a node create page.     $this->drupalGet('node/add/basic_page');

    // Assert a properly configured field still shows a message.     $assert_session->elementContains('css', '.field--name-field-twin-media', $field_twin_message);
    $assert_session->elementNotExists('css', '.js-media-library-open-button[name^="field_twin_media"]');
    // Assert that the message is shown when the target_bundles setting for the     // entity reference field is an empty array.     $assert_session->elementContains('css', '.field--name-field-empty-types-media', $field_empty_types_message);
    $assert_session->elementNotExists('css', '.js-media-library-open-button[name^="field_empty_types_media"]');
    // Assert that the message is shown when the target_bundles setting for the     // entity reference field is null.     $assert_session->elementContains('css', '.field--name-field-null-types-media', $field_null_types_message);
    $assert_session->elementNotExists('css', '.js-media-library-open-button[name^="field_null_types_media"]');

    // Assert the messages are also shown in the default value section of the

  public function testDescriptionRevisionLogMessage(): void {
    /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $entity */
    $entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
    $entity->setName('view all revisions');
    $entity->setRevisionLogMessage('<em>Hello</em> <script>world</script> <strong>123</strong>');
    $entity->save();

    $this->drupalGet($entity->toUrl('version-history'));
    // Script tags are stripped, while admin-safe tags are retained.     $this->assertSession()->elementContains('css', 'table tbody tr:nth-child(1)', '<em>Hello</em> world <strong>123</strong>');
  }

  /** * Test revert operation. * * @covers ::buildRevertRevisionLink */
  public function testOperationRevertRevision(): void {
    /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $entity */
    $entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
    $entity->setName('view all revisions');
    
$full_admin_user = $this->drupalCreateUser([
      'administer software updates',
      'access administration pages',
      'administer site configuration',
    ]);
    $this->drupalLogin($full_admin_user);
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->assertSession()->statusCodeEquals(200);
    $this->updateRequirementsProblem();
    $this->clickLink('maintenance mode');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->elementContains('css', 'main h1', 'Maintenance mode');

    // Now login as a user with only 'administer software updates' (but not     // 'administer site configuration') permission and try again.     $this->drupalLogin($this->updateUser);
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->assertSession()->statusCodeEquals(200);
    $this->updateRequirementsProblem();
    $this->clickLink('maintenance mode');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->elementContains('css', 'main h1', 'Maintenance mode');
  }

  
      'render_placeholder_message_test.last',
    ];

    $assert = $this->assertSession();
    foreach ($test_routes as $route) {
      // Verify that we start off with zero messages queued.       $this->drupalGet(Url::fromRoute('render_placeholder_message_test.queued'));
      $assert->responseNotContains($messages_markup);

      // Verify the test case at this route behaves as expected.       $this->drupalGet(Url::fromRoute($route));
      $assert->elementContains('css', 'p.logged-message:nth-of-type(1)', 'Message: P1');
      $assert->elementContains('css', 'p.logged-message:nth-of-type(2)', 'Message: P2');
      $assert->responseContains($messages_markup);
      $assert->elementExists('css', 'div[aria-label="Status message"] ul');
      $assert->elementContains('css', 'div[aria-label="Status message"] ul li:nth-of-type(1)', 'P1');
      $assert->elementContains('css', 'div[aria-label="Status message"] ul li:nth-of-type(2)', 'P2');

      // Verify that we end with all messages printed, hence again zero queued.       $this->drupalGet(Url::fromRoute('render_placeholder_message_test.queued'));
      $assert->responseNotContains($messages_markup);
    }
  }

  
$web_assert = $this->assertSession();
    $page = $this->getSession()->getPage();
    $page->find('css', static::TOOLBAR_EDIT_LINK_SELECTOR)->mouseOver();
    $this->assertTrue($page->waitFor(10, function D$page) {
      return !$page->find('css', '.contextual .trigger:not(.visually-hidden)');
    }));
    // Contextual triggers should be hidden.     $web_assert->elementExists('css', '.contextual .trigger.visually-hidden');
    // No contextual triggers should be not hidden.     $web_assert->elementNotExists('css', '.contextual .trigger:not(.visually-hidden)');
    // The toolbar edit button should read "Edit".     $web_assert->elementContains('css', static::TOOLBAR_EDIT_LINK_SELECTOR, 'Edit');
    // The main canvas element should NOT have the "js-settings-tray-edit-mode"     // class.     $web_assert->elementNotExists('css', '.dialog-off-canvas-main-canvas.js-settings-tray-edit-mode');
  }

  /** * Assert that edit mode has been properly enabled. */
  protected function assertEditModeEnabled() {
    $web_assert = $this->assertSession();
    $page = $this->getSession()->getPage();
    
// Ensure that a delete link for the published state exists before deleting     // the draft state.     $published_delete_link = Url::fromRoute('entity.workflow.delete_state_form', [
      'workflow' => $workflow->id(),
      'workflow_state' => 'published',
    ])->toString();
    $draft_delete_link = Url::fromRoute('entity.workflow.delete_state_form', [
      'workflow' => $workflow->id(),
      'workflow_state' => 'draft',
    ])->toString();
    $this->assertSession()->elementContains('css', 'tr[data-drupal-selector="edit-states-published"]', 'Delete');
    $this->assertSession()->linkByHrefExists($published_delete_link);
    $this->assertSession()->linkByHrefExists($draft_delete_link);

    // Make the published state a default state and ensure it is no longer     // linked.     \Drupal::state()->set('workflow_type_test.required_states', ['published']);
    $this->getSession()->reload();
    $this->assertSession()->linkByHrefNotExists($published_delete_link);
    $this->assertSession()->linkByHrefExists($draft_delete_link);
    $this->assertSession()->elementNotContains('css', 'tr[data-drupal-selector="edit-states-published"]', 'Delete');
    \Drupal::state()->set('workflow_type_test.required_states', []);
    
$web_assert = $this->assertSession();
    foreach ($this->getTestThemes() as $theme) {
      $this->enableTheme($theme);
      $block = $this->placeBlock('settings_tray_test_validation');
      $this->drupalGet('user');
      $this->enableEditMode();
      $this->openBlockForm($this->getBlockSelector($block));
      $page->pressButton('Save Block with validation error');
      $web_assert->assertWaitOnAjaxRequest();
      // The settings_tray_test_validation test plugin form always has a       // validation error.       $web_assert->elementContains('css', '#drupal-off-canvas', 'Sorry system error. Please save again');
      $this->disableEditMode();
      $block->delete();
    }
  }

}
      'render_placeholder_message_test.last',
    ];

    $assert = $this->assertSession();
    foreach ($test_routes as $route) {
      // Verify that we start off with zero messages queued.       $this->drupalGet(Url::fromRoute('render_placeholder_message_test.queued'));
      $assert->responseNotContains($messages_markup);

      // Verify the test case at this route behaves as expected.       $this->drupalGet(Url::fromRoute($route));
      $assert->elementContains('css', 'p.logged-message:nth-of-type(1)', 'Message: P1');
      $assert->elementContains('css', 'p.logged-message:nth-of-type(2)', 'Message: P2');
      $assert->responseContains($messages_markup);
      $assert->elementExists('css', 'div[aria-label="Status message"] ul');
      $assert->elementContains('css', 'div[aria-label="Status message"] ul li:nth-of-type(1)', 'P1');
      $assert->elementContains('css', 'div[aria-label="Status message"] ul li:nth-of-type(2)', 'P2');

      // Verify that we end with all messages printed, hence again zero queued.       $this->drupalGet(Url::fromRoute('render_placeholder_message_test.queued'));
      $assert->responseNotContains($messages_markup);
    }
  }

}
'label' => $media_type_id,
      'source' => 'test',
      'source_configuration' => [],
      'field_map' => [],
      'new_revision' => FALSE,
    ]);
    $media_type->save();

    $this->drupalGet('media/add/' . $media_type_id);

    // Make sure we have a vertical tab fieldset and 'Path' field.     $assert_session->elementContains('css', '.js-form-type-vertical-tabs #edit-path-0 summary', 'URL alias');
    $assert_session->fieldExists('path[0][alias]');

    // Disable the 'Path' field for this content type.     \Drupal::service('entity_display.repository')->getFormDisplay('media', $media_type_id, 'default')
      ->removeComponent('path')
      ->save();

    $this->drupalGet('media/add/' . $media_type_id);

    // See if the whole fieldset is gone now.     $assert_session->elementNotExists('css', '.js-form-type-vertical-tabs #edit-path-0');
    
// Fill main input.     $password_confirm_widget->fillField('Password', 'o');

    // Password tips should be refreshed and get visible.     $this->assertNotNull($this->assert->waitForElement('css', "$password_confirm_selector + .password-suggestions > ul > li"));
    $this->assertTrue($password_confirm_item->find('css', "$password_confirm_selector + .password-suggestions > ul > li")->isVisible());

    // Password match message must become invisible.     $this->assertFalse($password_confirm_item->find('css', 'input.js-password-confirm + [data-drupal-selector="password-confirm-message"]')->isVisible());

    // Password strength message should be updated.     $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>');

    // Deleting the input must not change the element above.     $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∘');

    
$session->fieldDisabled('type_settings[default_revision]');

    // Ensure that the draft settings cannot be changed.     $this->drupalGet('admin/config/workflow/workflows/manage/test/state/draft');
    $session->fieldDisabled('type_settings[published]');
    $session->fieldDisabled('type_settings[default_revision]');

    $this->drupalGet('admin/config/workflow/workflows/manage/test/type/node');
    $session->pageTextContains('Select the content types for the Test workflow');
    foreach ($types as $type) {
      $session->pageTextContains($type->label());
      $session->elementContains('css', sprintf('.form-item-bundles-%s label', $type->id())sprintf('Update %s', $type->label()));
    }

    // Ensure warning message are displayed for unsupported features.     $this->drupalGet('admin/config/workflow/workflows/manage/test/type/entity_test_rev');
    $this->assertSession()->pageTextContains('Test entity - revisions entities do not support publishing statuses. For example, even after transitioning from a published workflow state to an unpublished workflow state they will still be visible to site visitors.');
  }

}
    $this->assertCacheContext('session');

    $page->findLink($gravity->label());
  }

  /** * Tests switching workspace via a query parameter. */
  public function testQueryParameterNegotiator() {
    $web_assert = $this->assertSession();
    // Initially the default workspace should be active.     $web_assert->elementContains('css', '#block-workspaceswitcher', 'None');

    // When adding a query parameter the workspace will be switched.     $current_user_url = \Drupal::currentUser()->getAccount()->toUrl();
    $this->drupalGet($current_user_url['query' => ['workspace' => 'stage']]);
    $web_assert->elementContains('css', '#block-workspaceswitcher', 'Stage');

    // The workspace switching via query parameter should persist.     $this->drupalGet($current_user_url);
    $web_assert->elementContains('css', '#block-workspaceswitcher', 'Stage');

    // Check that WorkspaceCacheContext provides the cache context used to
Home | Imprint | This part of the site doesn't use cookies.