saveAnd example

$assert_session->pageTextContains('Allowed providers: YouTube, Vimeo.');
    $page->pressButton('Add');
    // assertWaitOnAjaxRequest() required for input "id" attributes to     // consistently match their label's "for" attribute.     $assert_session->assertWaitOnAjaxRequest();
    $this->waitForText('The media item has been created but has not yet been saved.');
    // Assert that Additional selected media does not appear.     $assert_session->pageTextNotContains('Additional selected media');
    $assert_session->elementNotExists('css', '[data-drupal-selector="edit-selection"]');
    // Assert the name field contains the remote video title.     $assert_session->fieldValueEquals('Name', $youtube_title);
    $this->saveAnd('select');
    $this->waitForText('Add Type Five via URL');
    // Load the created media item.     $media_items = Media::loadMultiple();
    $added_media = array_pop($media_items);

    // Ensure the media item was saved to the library and automatically     // selected. The added media items should be in the first position of the     // add form.     $assert_session->pageTextContains('Add or select media');
    $assert_session->pageTextContains($youtube_title);
    $assert_session->fieldValueEquals('media_library_select_form[0]', $added_media->id());
    
    $assert_session->elementNotExists('css', 'details summary:contains(Additional selected media)');
    // Files are temporary until the form is saved.     $files = $file_storage->loadMultiple();
    $file = array_pop($files);
    $this->assertSame('public://type-three-dir', $file_system->dirname($file->getFileUri()));
    $this->assertTrue($file->isTemporary());
    // Assert the revision_log_message field is not shown.     $upload_form = $assert_session->elementExists('css', '.js-media-library-add-form');
    $assert_session->fieldNotExists('Revision log message', $upload_form);
    // Assert the name field contains the filename and the alt text is required.     $assert_session->fieldValueEquals('Name', $png_image->filename);
    $this->saveAnd('select');
    $this->waitForText('Alternative text field is required');
    $page->fillField('Alternative text', $this->randomString());
    $this->saveAnd('select');
    $this->assertJsCondition('jQuery("input[name=\'media_library_select_form[0]\']").is(":focus")');
    // The file should be permanent now.     $files = $file_storage->loadMultiple();
    $file = array_pop($files);
    $this->assertFalse($file->isTemporary());
    // Load the created media item.     $media_items = Media::loadMultiple();
    $added_media = array_pop($media_items);
    


    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();
    $this->drupalGet('node/add/basic_page');
    // 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.
Home | Imprint | This part of the site doesn't use cookies.