You are here

public function MediaGalleryModifyTest::testOrderChange in Thunder 6.0.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.2.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() {
  $this
    ->drupalGet("node/7/edit");
  $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');
  }
  $this
    ->assertSame('media:8', $secondElement
    ->getAttribute('data-entity-id'));
  $this
    ->clickSave();
  $this
    ->clickButtonCssSelector($page, '#slick-media-gallery-media-images-default-13-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-13-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".');
}