You are here

public function MediaImageModifyTest::testRemoveAdd in Thunder 6.2.x

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

Test add/remove image in image paragraph.

Demo Article (node Id: 6) is used for testing. Cases tested:

  • remove inside inline entity form
  • add inside entity browser
  • reorder inside entity browser
  • remove inside entity browser.

File

tests/src/FunctionalJavascript/MediaImageModifyTest.php, line 115

Class

MediaImageModifyTest
Tests the Image media modification.

Namespace

Drupal\Tests\thunder\FunctionalJavascript

Code

public function testRemoveAdd() {

  // Test remove inside inline entity form.
  $node = $this
    ->loadNodeByUuid('0bd5c257-2231-450f-b4c2-ab156af7b78d');
  $this
    ->drupalGet($node
    ->toUrl('edit-form'));
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->editParagraph($page, 'field_paragraphs', 0);

  // Remove image.
  $this
    ->clickAjaxButtonCssSelector('[data-drupal-selector="edit-field-paragraphs-0-subform-field-image-current-items-0-remove-button"]');
  $this
    ->assertWaitOnAjaxRequest();

  // Check that there are no errors.
  $this
    ->assertSession()
    ->elementNotExists('css', '[data-drupal-selector="edit-field-paragraphs-0-subform-field-image-wrapper"] div.messages--error');

  // Click Select entities -> to open Entity Browser.
  $this
    ->openEntityBrowser($page, 'edit-field-paragraphs-0-subform-field-image-entity-browser-entity-browser-open-modal', 'image_browser');

  // Select another image and store filename.
  $this
    ->clickButtonCssSelector($page, '#entity-browser-image-browser-form div.view-content > div.views-row:nth-child(1)');
  $fileName = $this
    ->getSession()
    ->evaluateScript('jQuery(\'#entity-browser-image-browser-form div.view-content > div.views-row:nth-child(1) img\').attr(\'src\').split(\'?\')[0].split(\'/\').splice(-1);');
  $this
    ->clickButtonDrupalSelector($page, 'edit-submit');
  $this
    ->getSession()
    ->switchToIFrame();
  $this
    ->assertWaitOnAjaxRequest();

  // Save paragraph.
  $this
    ->clickAjaxButtonCssSelector('[name="field_paragraphs_0_collapse"]');
  $this
    ->assertEquals($fileName, $this
    ->getSession()
    ->evaluateScript('jQuery(\'[data-drupal-selector="edit-field-paragraphs-0-preview"] div.paragraph-preview__thumbnail img\').attr(\'src\').split(\'?\')[0].split(\'/\').splice(-1)'), 'Image file should be identical to previously selected.');
}