function EntityReferenceWidgetTest::testRemoveAfterReordering
Tests that changed order is maintained after removing a selection.
File
- 
              core/
modules/ media_library/ tests/ src/ FunctionalJavascript/ EntityReferenceWidgetTest.php, line 515  
Class
- EntityReferenceWidgetTest
 - Tests the Media library entity reference widget.
 
Namespace
Drupal\Tests\media_library\FunctionalJavascriptCode
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.