You are here

public function MediaGalleryModifyTest::testOrderChange in Thunder 6.2.x

Same name and namespace in other branches
  1. 8.5 tests/src/FunctionalJavascript/MediaGalleryModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaGalleryModifyTest::testOrderChange()
  2. 8.2 tests/src/FunctionalJavascript/MediaGalleryModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaGalleryModifyTest::testOrderChange()
  3. 8.3 tests/src/FunctionalJavascript/MediaGalleryModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaGalleryModifyTest::testOrderChange()
  4. 8.4 tests/src/FunctionalJavascript/MediaGalleryModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaGalleryModifyTest::testOrderChange()
  5. 6.0.x tests/src/FunctionalJavascript/MediaGalleryModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaGalleryModifyTest::testOrderChange()
  6. 6.1.x tests/src/FunctionalJavascript/MediaGalleryModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaGalleryModifyTest::testOrderChange()

Test order change for Gallery.

Throws

\Exception

File

tests/src/FunctionalJavascript/MediaGalleryModifyTest.php, line 39

Class

MediaGalleryModifyTest
Tests the Gallery media modification.

Namespace

Drupal\Tests\thunder\FunctionalJavascript

Code

public function testOrderChange() {
  $node = $this
    ->loadNodeByUuid('36b2e2b2-3df0-43eb-a282-d792b0999c07');
  $this
    ->drupalGet($node
    ->toUrl('edit-form'));
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->editParagraph($page, 'field_paragraphs', 0);

  // Wait for all images to be displayed properly.
  $this
    ->getSession()
    ->wait(10000, "jQuery('[data-drupal-selector=\"edit-field-paragraphs-0-subform-field-media-0-inline-entity-form-field-media-images-current\"] .media-form__item-widget--image').filter(function() {return jQuery(this).width() === 182;}).length === 5");
  $list_selector = 'div[data-drupal-selector="edit-field-paragraphs-0-subform-field-media-0-inline-entity-form-field-media-images-current"]';
  $this
    ->scrollElementInView($list_selector . ' > *:nth-child(2)');
  $item_selector = "{$list_selector} .item-container";
  $this
    ->sortableAfter("{$item_selector}:first-child", "{$item_selector}:nth-child(2)", $list_selector);
  $this
    ->createScreenshot($this
    ->getScreenshotFolder() . '/MediaGalleryModifyTest_AfterOrderChange_' . date('Ymd_His') . '.png');
  $secondElement = $page
    ->find('xpath', '//div[@data-drupal-selector="edit-field-paragraphs-0-subform-field-media-0-inline-entity-form-field-media-images-current"]/div[2]');
  if (empty($secondElement)) {
    throw new \Exception('Second element in Gallery is not found');
  }
  $media = $this
    ->loadMediaByUuid('159797c5-d9f9-4e27-b425-0f703a8a416d');
  $this
    ->assertSame('media:' . $media
    ->id(), $secondElement
    ->getAttribute('data-entity-id'));
  $this
    ->clickSave();
  $gallery = $this
    ->loadMediaByUuid('df67621b-518f-4159-a59e-1bad0700800c');
  $this
    ->clickButtonCssSelector($page, '#slick-media-gallery-media-images-default-' . $gallery
    ->id() . '-1 button.slick-next');

  // Check that, 2nd image is file: 26357237683_0891e46ba5_k.jpg.
  $fileNamePosition = $this
    ->getSession()
    ->evaluateScript('jQuery(\'#slick-media-gallery-media-images-default-' . $gallery
    ->id() . '-1 div.slick-slide:not(.slick-cloned):nth(1) img\').attr(\'src\').indexOf("26357237683_0891e46ba5_k.jpg")');
  $this
    ->assertNotEquals(-1, $fileNamePosition, 'For 2nd image in gallery, used file should be "26357237683_0891e46ba5_k.jpg".');
}