waitForFieldExists example

protected function waitForFieldExists($field$timeout = 10000) {
    $assert_session = $this->assertSession();
    $assert_session->waitForField($field$timeout);
    return $assert_session->fieldExists($field);
  }

  /** * Waits for a file field to exist before uploading. */
  public function addMediaFileToField($locator$path) {
    $page = $this->getSession()->getPage();
    $this->waitForFieldExists($locator);
    $page->attachFileToField($locator$path);
  }

  /** * Clicks "Save and select||insert" button and waits for AJAX completion. * * @param string $operation * The final word of the button to be clicked. */
  protected function saveAnd($operation) {
    $this->assertElementExistsAfterWait('css', '.ui-dialog-buttonpane')->pressButton("Save and $operation");

    

    $this->drupalLogin($user);

    $this->drupalGet('/admin/structure/types/manage/article/fields/add-field');
    $page->selectFieldOption('new_storage_type', 'field_ui:entity_reference:media');
    $this->assertNotNull($assert_session->waitForField('label'));
    $page->fillField('label', 'Shatner');
    $this->waitForText('field_shatner');
    $page->pressButton('Save and continue');
    $page->pressButton('Save field settings');
    $assert_session->pageTextNotContains('Undefined index: target_bundles');
    $this->waitForFieldExists('Type One')->check();
    $this->assertElementExistsAfterWait('css', '[name="settings[handler_settings][target_bundles][type_one]"][checked="checked"]');
    $page->checkField('settings[handler_settings][target_bundles][type_two]');
    $this->assertElementExistsAfterWait('css', '[name="settings[handler_settings][target_bundles][type_two]"][checked="checked"]');
    $page->checkField('settings[handler_settings][target_bundles][type_three]');
    $this->assertElementExistsAfterWait('css', '[name="settings[handler_settings][target_bundles][type_three]"][checked="checked"]');
    $page->pressButton('Save settings');
    $assert_session->pageTextContains('Saved Shatner configuration.');

    $this->drupalGet('/admin/structure/types/manage/article/fields/node.article.field_shatner');
    $assert_session->checkboxNotChecked('set_default_value');
    $page->checkField('set_default_value');
    
$assert_session->pageTextNotContains('Cat');
    // For reasons that are not clear, deleting media items by pressing the     // "Delete" button can fail (the button is found, but never actually pressed     // by the Mink driver). This workaround allows the delete form to be     // submitted.     $assert_session->elementExists('css', 'form')->submit();
    $assert_session->pageTextNotContains('Dog');
    $assert_session->pageTextContains('Cat');

    // Test the 'Select all media' checkbox and assert that it makes the     // expected announcements.     $select_all = $this->waitForFieldExists('Select all media');
    $select_all->check();
    $this->waitForText('All 7 items selected');
    $select_all->uncheck();
    $this->waitForText('Zero items selected');
    $select_all->check();
    $page->selectFieldOption('Action', 'media_delete_action');
    $this->submitForm([], 'Apply to selected items');
    // For reasons that are not clear, deleting media items by pressing the     // "Delete" button can fail (the button is found, but never actually pressed     // by the Mink driver). This workaround allows the delete form to be     // submitted.
// 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));

    // Also make sure that we can upload to the unlimited cardinality field.     $this->openMediaLibraryForField('field_unlimited_media');
    $this->switchToMediaType('Three');

    // Select a media item to check if the selection is persisted when adding     // new items.     $existing_media_name = $file_system->basename($png_uri_2);
    
Home | Imprint | This part of the site doesn't use cookies.