elementAttributeContains example

$local_file = PublicStream::basePath() . '/' . $input;
      }
      $xpath = "//div[contains(@class, 'js-form-item-logo-path')]/div[@class='description']/code";
      $this->assertSession()->elementTextEquals('xpath', "{$xpath}[1]", $implicit_public_file);
      $this->assertSession()->elementTextEquals('xpath', "{$xpath}[2]", $explicit_file);
      $this->assertSession()->elementTextEquals('xpath', "{$xpath}[3]", $local_file);

      // Verify the actual 'src' attribute of the logo being output in a site       // branding block.       $this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);
      $this->drupalGet('');
      $this->assertSession()->elementAttributeContains('xpath', '//header//a[@rel="home"]/img', 'src', $expected['src']);
    }
    $unsupported_paths = [
      // Stream wrapper URI to non-existing file.       'public://whatever.png',
      'private://whatever.png',
      'temporary://whatever.png',
      // Bogus stream wrapper URIs.       'public:/whatever.png',
      '://whatever.png',
      ':whatever.png',
      'public://',
      
// Get the media entity view URL from the creation message.     $this->drupalGet($this->assertLinkToCreatedMedia());

    // Make sure a link to the file is displayed.     $assert_session->linkExists($test_filename);
    // The thumbnail should not be displayed.     $assert_session->elementNotExists('css', 'img');

    // Make sure checkbox changes the visibility of log message field.     $this->drupalGet("media/1/edit");
    $page->uncheckField('revision');
    $assert_session->elementAttributeContains('css', '.field--name-revision-log-message', 'style', 'display: none');
    $page->checkField('revision');
    $assert_session->elementAttributeNotContains('css', '.field--name-revision-log-message', 'style', 'display');

    // Load the media and check that all the fields are properly populated.     $media = Media::load(1);
    $this->assertSame($test_filename$media->getName());
    $this->assertSame('8', $media->get('field_string_file_size')->value);
    $this->assertSame('text/plain', $media->get('field_string_mime_type')->value);

    // Test the MIME type icon.     $icon_base = \Drupal::config('media.settings')->get('icon_base_uri');
    
$this->disableEditMode();
    // Canvas should close when editing module is closed.     $this->waitForOffCanvasToClose();

    $this->enableEditMode();

    // Open block form by clicking an element inside the block.     // This confirms that default action for links and form elements is     // suppressed.     $this->openBlockForm("$block_selector {$element_selector}", $block_selector);
    $web_assert->elementTextContains('css', '.contextual-toolbar-tab button', 'Editing');
    $web_assert->elementAttributeContains('css', '.dialog-off-canvas-main-canvas', 'class', 'js-settings-tray-edit-mode');
    // Simulate press the Escape key.     $this->getSession()->executeScript('jQuery("body").trigger(jQuery.Event("keyup", { keyCode: 27 }));');
    $this->waitForOffCanvasToClose();
    $this->getSession()->wait(100);
    $this->getSession()->getPage()->find('css', static::TOOLBAR_EDIT_LINK_SELECTOR)->mouseOver();
    $this->assertEditModeDisabled();
    $this->assertNotEmpty($web_assert->waitForElement('css', '#drupal-live-announce:contains(Exited edit mode)'));
    $web_assert->assertNoElementAfterWait('css', '.contextual-toolbar-tab button:contains(Editing)');
    $web_assert->elementAttributeNotContains('css', '.dialog-off-canvas-main-canvas', 'class', 'js-settings-tray-edit-mode');

    // Clean up test data so each test does not impact the next.
/** * Tests that the 'Discard changes' button skips validation and ignores input. */
  public function testDiscardValidation() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    // When submitting the form normally, a validation error should be shown.     $this->drupalGet('entity_test/1/layout');
    $assert_session->fieldExists('foo[0][value]');
    $assert_session->elementAttributeContains('named', ['field', 'foo[0][value]'], 'required', 'required');
    $page->pressButton('Save layout');
    $assert_session->pageTextContains('foo field is required.');

    // When Discarding changes, a validation error will not be shown.     // Reload the form for fresh state.     $this->drupalGet('entity_test/1/layout');
    $page->pressButton('Discard changes');
    $assert_session->pageTextNotContains('foo field is required.');
    $assert_session->addressEquals('entity_test/1/layout/discard-changes');

    // Submit the form to ensure no invalid form state retained.

    $this->assertCacheContexts($expected_contexts);

    // Clicking a click sort should change the order.     $this->clickLink('ID');
    $href = Url::fromRoute('<none>', []['query' => ['order' => 'id', 'sort' => 'desc']])->toString();
    $this->assertSession()->linkByHrefExists($href);
    // Check that the output has the expected order (asc).     $ids = $this->clickSortLoadIdsFromOutput();
    $this->assertEquals(range(1, 5)$ids);
    // Check that the rel attribute has the correct value.     $this->assertSession()->elementAttributeContains('xpath', "//a[@href='$href']", 'rel', 'nofollow');

    $this->clickLink('ID Sort descending');
    // Check that the output has the expected order (desc).     $ids = $this->clickSortLoadIdsFromOutput();
    $this->assertEquals(range(5, 1, -1)$ids);
  }

  /** * Tests the default click sorting functionality with distinct. */
  public function testClickSortingDistinct() {
    
    $this->drupalGet('admin/structure/block/add/system_menu_block:main/olivero');
    $this->submitForm([
      'region' => 'sidebar',
      'id' => 'main_navigation',
    ], 'Save block');
    // Verify admin user can see the block.     $this->drupalGet('');
    $this->assertSession()->pageTextContains('Main navigation');

    // Verify we have role = complementary on help_block blocks.     $this->drupalGet('admin/structure/block');
    $this->assertSession()->elementAttributeContains('xpath', "//div[@id='block-olivero-help']", 'role', 'complementary');

    // Verify anonymous user can see the block.     $this->drupalLogout();
    $this->assertSession()->pageTextContains('Main navigation');

    // Ensure comments don't show in the front page RSS feed.     // Create an article.     $this->drupalCreateNode([
      'type' => 'article',
      'title' => 'Foobar',
      'promote' => 1,
      
    $this->assertSession()->assertEscaped('<em>Page</em>');

    $this->assertSession()->checkboxNotChecked("edit-displays-default");
    $this->assertSession()->checkboxNotChecked("edit-displays-page-1");

    // Save the attachments and test the value on the view.     $this->drupalGet($attachment_display_url);
    $this->submitForm(['displays[page_1]' => 1], 'Apply');
    // Options summary should be escaped.     $this->assertSession()->assertEscaped('<em>Page</em>');
    $this->assertSession()->responseNotContains('<em>Page</em>');
    $this->assertSession()->elementAttributeContains('xpath', '//a[@id = "views-attachment-1-displays"]', 'title', 'Page');
    $this->submitForm([], 'Save');

    $view = Views::getView('test_attachment_ui');
    $view->initDisplay();
    $this->assertEquals(['page_1']array_keys(array_filter($view->displayHandlers->get('attachment_1')->getOption('displays'))), 'The attached displays got saved as expected');

    $this->drupalGet($attachment_display_url);
    $this->submitForm([
      'displays[default]' => 1,
      'displays[page_1]' => 1,
    ], 'Apply');
    

    $node->save();

    $this->drupalGet('/node/' . $node->id());
    // Media field (field_related_media) is there.     $assert_session->pageTextContains('Related media');
    // Media name element is not there.     $assert_session->pageTextNotContains($image_media_name);
    // Only one image is present.     $assert_session->elementsCount('xpath', '//img', 1);
    // The image has the correct image style.     $assert_session->elementAttributeContains('xpath', '//img', 'src', '/styles/large/');
  }

}
$edit = ['path[0][alias]' => '//' . $alias];
    $this->drupalGet($node6->toUrl('edit-form'));
    $this->submitForm($edit, 'Save');
    $this->drupalGet(Url::fromRoute('system.admin_content'));
    // This checks the link href before clicking it, rather than using     // \Drupal\Tests\BrowserTestBase::assertSession()->addressEquals() after     // clicking it, because the test browser does not always preserve the     // correct number of slashes in the URL when it visits internal links;     // using \Drupal\Tests\BrowserTestBase::assertSession()->addressEquals()     // would actually make the test pass unconditionally on the testbot (or     // anywhere else where Drupal is installed in a subdirectory).     $this->assertSession()->elementAttributeContains('xpath', "//a[normalize-space(text())='{$node6->getTitle()}']", 'href', base_path() . $alias);
    $this->clickLink($node6->getTitle());
    $this->assertSession()->statusCodeEquals(404);
  }

  /** * Returns the path ID. * * @param string $alias * A string containing an aliased path. * * @return int * Integer representing the path ID. */
$entity->setNewRevision();
    $entity->save();

    $this->drupalGet($entity->toUrl('version-history'));
    $this->assertSession()->elementsCount('css', 'table tbody tr', 3);
    // Current revision text is found on the latest revision row.     $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', 'Current revision');
    $this->assertSession()->elementTextNotContains('css', 'table tbody tr:nth-child(2)', 'Current revision');
    $this->assertSession()->elementTextNotContains('css', 'table tbody tr:nth-child(3)', 'Current revision');
    // Current revision row has 'revision-current' class.     $this->assertSession()->elementAttributeContains('css', 'table tbody tr:nth-child(1)', 'class', 'revision-current');
  }

  /** * Test description with entity implementing revision log. * * @covers ::getRevisionDescription */
  public function testDescriptionRevLog(): void {
    /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $entity */
    $entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
    $entity->setName('view all revisions');
    
    // exists on the Manage field display.     $this->drupalGet("entity_test/structure/entity_test/fields/entity_test.entity_test.{$field_name}");
    $this->assertSession()->elementsCount('xpath', "//table[@id='field-unlimited-values']/tbody/tr//input[contains(@class, 'form-text')]", 1);

    // Display creation form -> 1 widget.     $this->drupalGet('entity_test/add');
    $this->assertSession()->fieldValueEquals("{$field_name}[0][value]", '');
    // Verify that no extraneous widget is displayed.     $this->assertSession()->fieldNotExists("{$field_name}[1][value]");

    // Check if aria-describedby attribute is placed on multiple value widgets.     $this->assertSession()->elementAttributeContains('xpath', '//table[@id="field-unlimited-values"]', 'aria-describedby', 'edit-field-unlimited--description');

    // Press 'add more' button -> 2 widgets.     $this->submitForm([], 'Add another item');
    $this->assertSession()->fieldValueEquals("{$field_name}[0][value]", '');
    $this->assertSession()->fieldValueEquals("{$field_name}[1][value]", '');
    // Verify that no extraneous widget is displayed.     $this->assertSession()->fieldNotExists("{$field_name}[2][value]");
    // TODO : check that non-field inputs are preserved ('title'), etc.
    // Yet another time so that we can play with more values -> 3 widgets.     $this->submitForm([], 'Add another item');

    
// Check #field_prefix and #field_suffix placement.     $this->assertSession()->elementExists('xpath', '//span[@class="field-prefix"]/following-sibling::div[@id="edit-form-radios-test"]');
    $this->assertSession()->elementExists('xpath', '//span[@class="field-suffix"]/preceding-sibling::div[@id="edit-form-radios-test"]');

    // Check #prefix and #suffix placement. Both elements placed before the form     // item.     $this->assertSession()->elementExists('xpath', '//div[@id="form-test-textfield-title-prefix"]/following-sibling::div[contains(@class, \'js-form-item-form-textfield-test-title\')]');
    $this->assertSession()->elementExists('xpath', '//div[@id="form-test-textfield-title-suffix"]/preceding-sibling::div[contains(@class, \'js-form-item-form-textfield-test-title\')]');

    // Check title attribute for radios and checkboxes.     $this->assertSession()->elementAttributeContains('css', '#edit-form-checkboxes-title-attribute', 'title', 'Checkboxes test (Required)');
    $this->assertSession()->elementAttributeContains('css', '#edit-form-radios-title-attribute', 'title', 'Radios test (Required)');

    // Check Title/Label not displayed when 'visually-hidden' attribute is set     // in checkboxes.     $this->assertSession()->elementExists('xpath', '//fieldset[@id="edit-form-checkboxes-title-invisible--wrapper"]/legend/span[contains(@class, "visually-hidden")]');

    // Check Title/Label not displayed when 'visually-hidden' attribute is set     // in radios.     $this->assertSession()->elementExists('xpath', '//fieldset[@id="edit-form-radios-title-invisible--wrapper"]/legend/span[contains(@class, "visually-hidden")]');
  }

  
// Enable the language switcher block.     $this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, ['id' => 'test_language_block']);

    $this->drupalGet('');

    /** @var \Drupal\Core\Routing\UrlGenerator $generator */
    $generator = $this->container->get('url_generator');

    // Verify the English URL is correct     $english_url = $generator->generateFromRoute('entity.user.canonical', ['user' => 2]['language' => $languages['en']]);
    $this->assertSession()->elementAttributeContains('xpath', '//div[@id="block-test-language-block"]/ul/li/a[@hreflang="en"]', 'href', $english_url);

    // Verify the Italian URL is correct     $italian_url = $generator->generateFromRoute('entity.user.canonical', ['user' => 2]['language' => $languages['it']]);
    $this->assertSession()->elementAttributeContains('xpath', '//div[@id="block-test-language-block"]/ul/li/a[@hreflang="it"]', 'href', $italian_url);
  }

  /** * Tests active class on links when switching languages. */
  public function testLanguageLinkActiveClass() {
    // Add language.

  protected function assertMediaAdded($index = 0) {
    $selector = '.js-media-library-add-form-added-media';

    // Assert that focus is shifted to the new media items.     $this->assertJsCondition('jQuery("' . $selector . '").is(":focus")');

    $assert_session = $this->assertSession();
    $assert_session->pageTextMatches('/The media items? ha(s|ve) been created but ha(s|ve) not yet been saved. Fill in any required fields and save to add (it|them) to the media library./');
    $assert_session->elementAttributeContains('css', $selector, 'aria-label', 'Added media items');

    $fields = $this->assertElementExistsAfterWait('css', '[data-drupal-selector="edit-media-' . $index . '-fields"]');
    $assert_session->elementNotExists('css', '.js-media-library-menu');

    // Assert extraneous components were removed in     // FileUploadForm::hideExtraSourceFieldComponents().     $assert_session->elementNotExists('css', '[data-drupal-selector$="preview"]', $fields);
    $assert_session->buttonNotExists('Remove', $fields);
    $assert_session->elementNotExists('css', '[data-drupal-selector$="filename"]', $fields);
  }

  
'title' => 'Unnamed',
    ]);
    $node->save();

    $user = $this->drupalCreateUser([
      'administer nodes',
      'access contextual links',
    ]);
    $this->drupalLogin($user);

    $this->drupalGet('node/' . $node->id());
    $this->assertSession()->elementAttributeContains('css', 'div[data-contextual-id]', 'data-contextual-id', 'node:node=' . $node->id() . ':');
  }

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