function EntityReferenceWidgetTest::testAddAfterReordering

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

Tests that order is correct after re-order and adding another item.

File

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

Class

EntityReferenceWidgetTest
Tests the Media library entity reference widget.

Namespace

Drupal\Tests\media_library\FunctionalJavascript

Code

public function testAddAfterReordering() : 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');
    // Order: Dog - Cat.
    $this->pressInsertSelected('Added 2 media items.');
    // Change positions.
    // Order: Cat - Dog.
    $this->sortableAfter('[data-media-library-item-delta="0"]', '[data-media-library-item-delta="1"]', '.js-media-library-selection');
    $this->openMediaLibraryForField('field_unlimited_media');
    $this->selectMediaItem(2);
    // Order: Cat - Dog - Bear.
    $this->pressInsertSelected('Added one media item.');
    $page->pressButton('Save');
    $assert_session->elementTextContains('css', '.field--name-field-unlimited-media > .field__items > .field__item:first-child', 'Cat');
    $assert_session->elementTextContains('css', '.field--name-field-unlimited-media > .field__items > .field__item:last-child', 'Bear');
}

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