ParagraphSplitTest.php in Thunder 6.2.x
File
tests/src/FunctionalJavascript/Integration/ParagraphSplitTest.php
View source
<?php
namespace Drupal\Tests\thunder\FunctionalJavascript\Integration;
use Drupal\Tests\thunder\FunctionalJavascript\ThunderArticleTestTrait;
use Drupal\Tests\thunder\FunctionalJavascript\ThunderJavascriptTestBase;
use Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait;
class ParagraphSplitTest extends ThunderJavascriptTestBase {
use ThunderParagraphsTestTrait;
use ThunderArticleTestTrait;
protected static $paragraphsField = 'field_paragraphs';
protected static $selectorTemplate = "textarea[name='%s[%d][subform][field_text][0][value]']";
public function testParagraphSplitBefore() {
$firstParagraphContent = '<p>Content that will be in the first paragraph after the split.</p>';
$secondParagraphContent = '<p>Content that will be in the second paragraph after the split.</p>';
$this
->articleFillNew([]);
$this
->addTextParagraph(static::$paragraphsField, $firstParagraphContent . $secondParagraphContent);
$this
->selectCkEditorElement($this
->getCkEditorCssSelector(0), 1);
$this
->clickParagraphSplitButton();
$this
->assertWaitOnAjaxRequest();
$this
->assertCkEditorContent($this
->getCkEditorCssSelector(0), $firstParagraphContent . PHP_EOL);
$this
->assertCkEditorContent($this
->getCkEditorCssSelector(1), $secondParagraphContent . PHP_EOL);
}
public function testParagraphSplitDataLoss() {
$firstParagraphContent = '<p>Content that will be in the first paragraph after the split.</p>';
$secondParagraphContent = '<p>Content that will be in the second paragraph after the split.</p>';
$this
->articleFillNew([]);
$this
->addTextParagraph(static::$paragraphsField, '');
$driver = $this
->getSession()
->getDriver();
$driver
->executeScript("jQuery('[name=\"field_paragraphs_0_remove\"]').trigger('mousedown')");
$this
->assertWaitOnAjaxRequest();
$this
->addTextParagraph(static::$paragraphsField, $firstParagraphContent . $secondParagraphContent);
$this
->selectCkEditorElement($this
->getCkEditorCssSelector(1), 1);
$this
->clickParagraphSplitButton();
$this
->assertWaitOnAjaxRequest();
$this
->assertCkEditorContent($this
->getCkEditorCssSelector(1), $firstParagraphContent . PHP_EOL);
$this
->assertCkEditorContent($this
->getCkEditorCssSelector(2), $secondParagraphContent . PHP_EOL);
}
public function testAddParagraphAfterSplitDataLoss() {
$firstParagraphContent = '<p>Content that will be in the first paragraph after the split.</p>';
$secondParagraphContent = '<p>Content that will be in the second paragraph after the split.</p>';
$thirdParagraphContent = '<p>Content that will be placed into the first paragraph after split.</p>';
$this
->articleFillNew([]);
$this
->addTextParagraph(static::$paragraphsField, $firstParagraphContent . $secondParagraphContent);
$this
->selectCkEditorElement($this
->getCkEditorCssSelector(0), 1);
$this
->clickParagraphSplitButton();
$this
->assertWaitOnAjaxRequest();
$paragraphDelta = $this
->getParagraphDelta(static::$paragraphsField, 0);
$ckEditorCssSelector = "textarea[name='" . static::$paragraphsField . "[{$paragraphDelta}][subform][field_text][0][value]']";
$this
->fillCkEditor($ckEditorCssSelector, $thirdParagraphContent);
$ckEditorId = $this
->getCkEditorId($ckEditorCssSelector);
$this
->getSession()
->getDriver()
->executeScript("window.ed = CKEDITOR.instances[\"{$ckEditorId}\"]; window.ed.setData(\"{$thirdParagraphContent}\"); window.ed.updateElement(); window.ed.element.data('editor-value-is-changed', true);");
$this
->addTextParagraph(static::$paragraphsField, '', 'text', 1);
$this
->assertCkEditorContent($this
->getCkEditorCssSelector(0), $thirdParagraphContent . PHP_EOL);
$this
->assertCkEditorContent($this
->getCkEditorCssSelector(2), '');
$this
->assertCkEditorContent($this
->getCkEditorCssSelector(1), $secondParagraphContent . PHP_EOL);
}
protected function clickParagraphSplitButton() {
$this
->getSession()
->executeScript("jQuery('.cke_button__splittext')[0].click();");
}
protected function getCkEditorCssSelector($paragraphDelta) {
return sprintf(static::$selectorTemplate, static::$paragraphsField, $paragraphDelta);
}
}