function EntityReferenceWidgetTest::testRemoveAfterReordering

Same name in other branches
  1. 9 core/modules/media_library/tests/src/FunctionalJavascript/EntityReferenceWidgetTest.php \Drupal\Tests\media_library\FunctionalJavascript\EntityReferenceWidgetTest::testRemoveAfterReordering()
  2. 11.x core/modules/media_library/tests/src/FunctionalJavascript/EntityReferenceWidgetTest.php \Drupal\Tests\media_library\FunctionalJavascript\EntityReferenceWidgetTest::testRemoveAfterReordering()

Tests that changed order is maintained after removing a selection.

File

core/modules/media_library/tests/src/FunctionalJavascript/EntityReferenceWidgetTest.php, line 507

Class

EntityReferenceWidgetTest
Tests the Media library entity reference widget.

Namespace

Drupal\Tests\media_library\FunctionalJavascript

Code

public function testRemoveAfterReordering() : void {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $this->drupalGet('node/add/basic_page');
    $page->fillField('Title', 'My page');
    $this->openMediaLibraryForField('field_unlimited_media');
    $page->checkField('Select Dog');
    $page->checkField('Select Cat');
    $page->checkField('Select Bear');
    // Order: Dog - Cat - Bear.
    $this->pressInsertSelected('Added 3 media items.');
    // Move first item (Dog) to the end.
    // Order: Cat - Bear - Dog.
    $this->sortableAfter('[data-media-library-item-delta="0"]', '[data-media-library-item-delta="2"]', '.js-media-library-selection');
    $wrapper = $assert_session->elementExists('css', '.field--name-field-unlimited-media');
    // Remove second item (Bear).
    // Order: Cat - Dog.
    $wrapper->find('css', "[aria-label='Remove Bear']")
        ->press();
    $this->waitForText('Bear has been removed.');
    $page->pressButton('Save');
    $assert_session->elementTextContains('css', '.field--name-field-unlimited-media > .field__items > .field__item:last-child', 'Dog');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.