waitForElementTextContains example

$this->assertTrue($menu->hasLink('Type Five'));

    // Insert media to test validation with null target_bundles.     $this->switchToMediaType('One');
    $this->assertNotEmpty($assert_session->waitForText('Showing Type One media.'));
    $this->selectMediaItem(0);
    $this->pressInsertSelected('Added one media item.');

    // Assert that the media type menu is not available when only 1 type is     // configured for the field.     $this->openMediaLibraryForField('field_single_media_type', '#media-library-wrapper');
    $this->waitForElementTextContains('.media-library-selected-count', '0 of 1 item selected');

    // Select a media item, assert the hidden selection field contains the ID of     // the selected item.     $this->selectMediaItem(0);
    $assert_session->hiddenFieldValueEquals('media-library-modal-selection', '4');
    $this->assertSelectedMediaCount('1 of 1 item selected');
    $assert_session->elementNotExists('css', '.js-media-library-menu');
    $assert_session->elementExists('css', '.ui-dialog-titlebar-close')->click();

    // Assert the menu links can be sorted through the widget configuration.     $this->openMediaLibraryForField('field_twin_media');
    
    $button_pane = $assert_session->elementExists('css', '.ui-dialog-buttonpane');
    $assert_session->buttonExists('Insert selected', $button_pane);
    $assert_session->buttonNotExists('Apply filters', $button_pane);

    // Assert the pager works as expected.     // An active pager item is not linked and contains "Page #" as text.     $assert_session->elementTextContains('css', '.js-media-library-view .js-pager__items > li:nth-of-type(1)', 'Page 1');
    $assert_session->elementNotExists('css', '.js-media-library-view .js-pager__items > li:nth-of-type(1) a');
    $assert_session->elementExists('css', '.js-media-library-view .js-pager__items > li:nth-of-type(2) a');
    $this->assertCount(24, $this->getCheckboxes());
    $page->clickLink('Next page');
    $this->waitForElementTextContains('.js-media-library-view .js-pager__items > li:nth-of-type(2)', 'Page 2');
    $assert_session->elementExists('css', '.js-media-library-view .js-pager__items > li:nth-of-type(1) a');
    $assert_session->elementNotExists('css', '.js-media-library-view .js-pager__items > li:nth-of-type(2) a');
    $this->assertCount(1, $this->getCheckboxes());
    $page->clickLink('Previous page');
    $this->waitForElementTextContains('.js-media-library-view .js-pager__items > li:nth-of-type(1)', 'Page 1');
    $this->assertCount(24, $this->getCheckboxes());

    $page->checkField('Select Bear');
    $this->pressInsertSelected('Added one media item.');
    $assert_session->pageTextContains('Bear');
    $assert_session->pageTextNotContains('Cat');
    
$assert_session->fieldValueEquals('media_library_select_form[0]', $added_media->id());
    $assert_session->checkboxChecked('media_library_select_form[0]');
    $assert_session->pageTextContains('1 of 2 items selected');
    $assert_session->hiddenFieldValueEquals('current_selection', $added_media->id());
    // Ensure the created item is added in the widget.     $this->pressInsertSelected('Added one media item.');
    $this->waitForText($png_image->filename);

    // Remove the item.     $assert_session->elementTextContains('css', '.field--name-field-twin-media', $png_image->filename);
    $assert_session->elementExists('css', '.field--name-field-twin-media')->pressButton('Remove');
    $this->waitForElementTextContains('#drupal-live-announce', $png_image->filename . ' has been removed');
    $assert_session->elementTextNotContains('css', '.field--name-field-twin-media', $png_image->filename);

    $this->openMediaLibraryForField('field_twin_media');
    $this->switchToMediaType('Three');
    $png_uri_2 = $file_system->copy($png_image->uri, 'public://');
    $this->addMediaFileToField('Add files', $this->container->get('file_system')->realpath($png_uri_2));
    $this->waitForFieldExists('Alternative text')->setValue($this->randomString());
    $this->pressSaveButton();
    $this->pressInsertSelected('Added one media item.');
    $this->waitForText($file_system->basename($png_uri_2));

    
// Upload 5 files into a media field that only allows 2.     $this->openMediaLibraryForField('field_twin_media');
    $this->uploadFiles(5);
    // Save the media items and ensure that the user is warned that they have     // selected too many items.     if ($selected_operation) {
      $this->saveAnd($selected_operation);
    }
    else {
      $this->pressSaveButton();
    }
    $this->waitForElementTextContains('.messages--warning', 'There are currently 5 items selected. The maximum number of items for the field is 2. Please remove 3 items from the selection.');
    // If the user tries to insert the selected items anyway, they should get     // an error.     $this->pressInsertSelected(NULL, FALSE);
    $this->waitForElementTextContains('.messages--error', 'There are currently 5 items selected. The maximum number of items for the field is 2. Please remove 3 items from the selection.');
    $assert_session->elementNotExists('css', '.messages--warning');
    // Once the extra items are deselected, all should be well.     $this->deselectMediaItem(2);
    $this->deselectMediaItem(3);
    $this->deselectMediaItem(4);
    $this->pressInsertSelected('Added 2 media items.');
  }

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