View source
<?php
namespace Drupal\Tests\thunder\FunctionalJavascript;
class MediaGalleryModifyTest extends ThunderJavascriptTestBase {
use ThunderEntityBrowserTestTrait;
use ThunderParagraphsTestTrait;
public function testOrderChange() {
$this
->drupalGet("node/7/edit");
$page = $this
->getSession()
->getPage();
$this
->editParagraph($page, 'field_paragraphs', 0);
$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");
$cssSelector = 'div[data-drupal-selector="edit-field-paragraphs-0-subform-field-media-0-inline-entity-form-field-media-images-current"]';
$this
->scrollElementInView($cssSelector . ' > *:nth-child(2)');
$dragElement = $this
->xpath("//div[@data-entity-id='media:8']")[0];
$this
->dragDropElement($dragElement, 300, 0);
$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-13-media-images-default-1 button.slick-next');
$fileNamePosition = $this
->getSession()
->evaluateScript('jQuery(\'#slick-media-13-media-images-default-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".');
}
public function testAddRemove() {
$this
->drupalGet("node/7/edit");
$page = $this
->getSession()
->getPage();
$this
->editParagraph($page, 'field_paragraphs', 0);
$this
->clickAjaxButtonCssSelector('[data-drupal-selector="edit-field-paragraphs-0-subform-field-media-0-inline-entity-form-field-media-images-current-items-1-remove-button"]');
$this
->clickSave();
$this
->clickButtonCssSelector($page, '#slick-media-13-media-images-default-1 button.slick-next');
$numberOfImages = $this
->getSession()
->evaluateScript('jQuery(\'#slick-media-13-media-images-default-1 div.slick-slide:not(.slick-cloned)\').length;');
$this
->assertEquals(4, $numberOfImages, 'There should be 4 images in Gallery.');
$fileNamePosition = $this
->getSession()
->evaluateScript('jQuery(\'#slick-media-13-media-images-default-1 div.slick-slide:not(.slick-cloned):nth(1) img\').attr(\'src\').indexOf("26315068204_24ffa6cfc4_o.jpg")');
$this
->assertNotEquals(-1, $fileNamePosition, 'For 2nd image in gallery, used file should be "26315068204_24ffa6cfc4_o.jpg".');
$this
->drupalGet("node/7/edit");
$this
->editParagraph($page, 'field_paragraphs', 0);
$this
->openEntityBrowser($page, 'edit-field-paragraphs-0-subform-field-media-0-inline-entity-form-field-media-images-entity-browser-entity-browser-open-modal', 'multiple_image_browser');
$this
->uploadFile($page, '/tests/fixtures/reference.jpg');
$dragElement = $this
->xpath("//*[@id='edit-selected']/div[5]")[0];
$this
->dragDropElement($dragElement, -440, 0);
$this
->submitEntityBrowser($page);
$this
->clickSave();
$numberOfImages = $this
->getSession()
->evaluateScript('jQuery(\'#slick-media-13-media-images-default-1 div.slick-slide:not(.slick-cloned)\').length;');
$this
->assertEquals(5, $numberOfImages, 'There should be 5 images in Gallery.');
$this
->clickButtonCssSelector($page, '#slick-media-13-media-images-default-1 button.slick-next');
$this
->clickButtonCssSelector($page, '#slick-media-13-media-images-default-1 button.slick-next');
$fileNamePosition = $this
->getSession()
->evaluateScript('jQuery(\'#slick-media-13-media-images-default-1 div.slick-slide:not(.slick-cloned):nth(2) img\').attr(\'src\').indexOf("reference.jpg")');
$this
->assertNotEquals(-1, $fileNamePosition, 'For 3rd image in gallery, used file should be "reference.jpg".');
$this
->drupalGet("node/7/edit");
$this
->editParagraph($page, 'field_paragraphs', 0);
$this
->openEntityBrowser($page, 'edit-field-paragraphs-0-subform-field-media-0-inline-entity-form-field-media-images-entity-browser-entity-browser-open-modal', 'multiple_image_browser');
$this
->clickButtonDrupalSelector($page, 'edit-selected-items-23-2-remove-button');
$this
->submitEntityBrowser($page);
$this
->clickSave();
$numberOfImages = $this
->getSession()
->evaluateScript('jQuery(\'#slick-media-13-media-images-default-1 div.slick-slide:not(.slick-cloned)\').length;');
$this
->assertEquals(4, $numberOfImages, 'There should be 4 images in Gallery.');
$this
->clickButtonCssSelector($page, '#slick-media-13-media-images-default-1 button.slick-next');
$this
->clickButtonCssSelector($page, '#slick-media-13-media-images-default-1 button.slick-next');
$fileNamePosition = $this
->getSession()
->evaluateScript('jQuery(\'#slick-media-13-media-images-default-1 div.slick-slide:not(.slick-cloned):nth(2) img\').attr(\'src\').indexOf("reference.jpg")');
$this
->assertEquals(-1, $fileNamePosition, 'For 2nd image in gallery, used file should not be "reference.jpg".');
}
}