Skip to content

Commit

Permalink
Issue #3100215: Split text tests are failing with Drupal 8.8 (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrfritsch authored and ol0lll committed Dec 11, 2019
1 parent cbf4f6d commit e19c7ef
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 47 deletions.
27 changes: 20 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
language: php
dist: xenial

php:
- 7.2

services:
- mysql

cache:
apt: true
directories:
- "$HOME/.composer/cache"
- "$HOME/.drush/cache"
- "$HOME/.npm"
- "$HOME/.composer/cache"
- "$HOME/.drush/cache"
- "$HOME/.npm"

php:
- 7.3

branches:
only:
Expand All @@ -21,9 +21,22 @@ branches:
env:
global:
- PATH="$PATH:$HOME/.composer/vendor/bin"
- COMPOSER_MEMORY_LIMIT=-1

matrix:
allow_failures:
- env: DRUPAL_TRAVIS_DRUPAL_VERSION=~8.8.0
include:
- env: DRUPAL_TRAVIS_DRUPAL_VERSION=~8.7.0
- env: DRUPAL_TRAVIS_DRUPAL_VERSION=~8.7.0
php: 7.2
- env: DRUPAL_TRAVIS_DRUPAL_VERSION=~8.8.0 DRUPAL_TRAVIS_TEST_DEPRECATION=false
php: 7.2
- env: DRUPAL_TRAVIS_DRUPAL_VERSION=~8.8.0
- env: DRUPAL_TRAVIS_DRUPAL_VERSION=~8.8.0 DRUPAL_TRAVIS_TEST_DEPRECATION=false

before_install:
- composer global require thunder/travis @beta
- composer global require thunder/travis

script:
- test-drupal-project
Expand Down
34 changes: 5 additions & 29 deletions js/plugins/splittext/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,40 +127,16 @@
var $editorObject = $('#' + editor.name);
var selection = editor.getSelection();
var ranges = selection.getRanges();
var endNode = ranges[0].getBoundaryNodes().endNode;

// First node that should be selected to cut content should be text type.
var firstNode = ranges[0].document.getBody().getFirst();
ranges[0].setStartBefore(firstNode);

// In order to find the first text node, we have to walk forward searching
// for first text node.
var walker = new CKEDITOR.dom.walker(ranges[0]);
var firstTextNode = walker.next();
while (firstTextNode && firstTextNode.type !== CKEDITOR.NODE_TEXT) {
firstTextNode = walker.next();
}

// To have styles nicely transferred additional tweaks for selection range
// are required. Only problematic part is when first element is split.
if (firstTextNode) {
var firstTextBaseParent = firstTextNode.getParents()[2];
var endNodeBaseParent = endNode.getParents()[2];
if (!firstTextBaseParent || !endNodeBaseParent || firstTextBaseParent.equals(endNodeBaseParent)) {
ranges[0].setStartBefore(firstTextNode);
}
}
// Last node that should be selected to cut content should be text type.
var lastNode = ranges[0].document.getBody().getLast();
ranges[0].setEndAfter(lastNode);

// Set new selection and trigger cut for it.
selection.selectRanges(ranges);

// First we "cut" text that will be "pasted" to new added paragraph.
var oldContent = editor.extractSelectedHtml(true, true);
tmpObject.newContent = editor.getData();

// Set extracted old data back to editor. New content will be set to newly
// added paragraph.
editor.setData(oldContent);
// We "cut" text that will be "pasted" to new added paragraph.
tmpObject.newContent = editor.extractSelectedHtml(true, true);
editor.updateElement();
editor.element.data('editor-value-is-changed', true);

Expand Down
45 changes: 34 additions & 11 deletions tests/src/FunctionalJavascript/ParagraphsFeaturesSplitTextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,38 @@ public function testSplitTextFeature() {
$ck_editor_id_0 = $this->getCkEditorId(0);
$ck_editor_id_1 = $this->getCkEditorId(1);
static::assertEquals(
$paragraph_content_0 . PHP_EOL . PHP_EOL . '<p><br />' . PHP_EOL . '</p>' . PHP_EOL,
$paragraph_content_0 . PHP_EOL,
$driver->evaluateScript("CKEDITOR.instances['$ck_editor_id_0'].getData();")
);
static::assertEquals(
$paragraph_content_1 . PHP_EOL,
$driver->evaluateScript("CKEDITOR.instances['$ck_editor_id_1'].getData();")
);

// Case 2 - split text works after removal of paragraph.
// Case 2 - simple split inside word.
$paragraph_content = '<p>Content will be split inside the word spl-it.</p>';

// Check that split text functionality is used.
$this->drupalGet("node/add/$content_type");
$ck_editor_id = $this->createNewTextParagraph(0, $paragraph_content);

// Make split of created text paragraph.
$driver->executeScript("var selection = CKEDITOR.instances['$ck_editor_id'].getSelection(); var element = selection.getStartElement(); selection.selectElement(element); var ranges = selection.getRanges(); ranges[0].setStart(element.getFirst(), element.getHtml().indexOf('split') + 3); ranges[0].setEnd(element.getFirst(), element.getHtml().indexOf('split') + 3); selection.selectRanges(ranges);");
$this->clickParagraphSplitButton(0);

// Validate split results.
$ck_editor_id_0 = $this->getCkEditorId(0);
$ck_editor_id_1 = $this->getCkEditorId(1);
static::assertEquals(
'<p>Content will be spl</p>' . PHP_EOL,
$driver->evaluateScript("CKEDITOR.instances['$ck_editor_id_0'].getData();")
);
static::assertEquals(
'<p>it inside the word spl-it.</p>' . PHP_EOL,
$driver->evaluateScript("CKEDITOR.instances['$ck_editor_id_1'].getData();")
);

// Case 3 - split text works after removal of paragraph.
$this->drupalGet("node/add/$content_type");
$this->createNewTextParagraph(0, '');

Expand All @@ -134,15 +157,15 @@ public function testSplitTextFeature() {
$ck_editor_id_0 = $this->getCkEditorId(1);
$ck_editor_id_1 = $this->getCkEditorId(2);
static::assertEquals(
$paragraph_content_0 . PHP_EOL . PHP_EOL . '<p><br />' . PHP_EOL . '</p>' . PHP_EOL,
$paragraph_content_0 . PHP_EOL,
$driver->evaluateScript("CKEDITOR.instances['$ck_editor_id_0'].getData();")
);
static::assertEquals(
$paragraph_content_1 . PHP_EOL,
$driver->evaluateScript("CKEDITOR.instances['$ck_editor_id_1'].getData();")
);

// Case 3 - add of new paragraph after text split.
// Case 4 - add of new paragraph after text split.
$this->drupalGet("node/add/$content_type");
$ck_editor_id = $this->createNewTextParagraph(0, $paragraph_content_0 . $paragraph_content_1);

Expand Down Expand Up @@ -173,7 +196,7 @@ public function testSplitTextFeature() {
static::assertEquals($paragraph_content_1_new . PHP_EOL, $ck_editor_content_1);
static::assertEquals('', $ck_editor_content_2);

// Case 4 - test split in middle of formatted text.
// Case 5 - test split in middle of formatted text.
$text = '<p>Text start</p><ol><li>line 1</li><li>line 2 with some <strong>bold text</strong> and back to normal</li><li>line 3</li></ol><p>Text end after indexed list</p>';
$this->drupalGet("node/add/$content_type");
$ck_editor_id = $this->createNewTextParagraph(0, $text);
Expand Down Expand Up @@ -205,7 +228,7 @@ public function testSplitTextFeature() {
static::assertEquals($expected_content_0, $ck_editor_content_0);
static::assertEquals($expected_content_1, $ck_editor_content_1);

// Case 5 - split paragraph with multiple text fields.
// Case 6 - split paragraph with multiple text fields.
$this->addParagraphsType("test_3_text_fields");
$this->addFieldtoParagraphType('test_3_text_fields', 'text_3_1', 'text_long');
$this->addFieldtoParagraphType('test_3_text_fields', 'text_3_2', 'text_long');
Expand Down Expand Up @@ -246,7 +269,7 @@ public function testSplitTextFeature() {
$driver->evaluateScript("CKEDITOR.instances['$ck_editor_id_para_0_text_0'].getData();")
);
static::assertEquals(
$paragraph_content_0 . PHP_EOL . PHP_EOL . '<p><br />' . PHP_EOL . '</p>' . PHP_EOL,
$paragraph_content_0 . PHP_EOL,
$driver->evaluateScript("CKEDITOR.instances['$ck_editor_id_para_0_text_1'].getData();")
);
static::assertEquals(
Expand All @@ -266,8 +289,8 @@ public function testSplitTextFeature() {
$driver->evaluateScript("CKEDITOR.instances['$ck_editor_id_para_1_text_2'].getData();")
);

// Case 6 - simple text split with auto-collapse.
// 6.1 - Enable auto-collapse.
// Case 7 - simple text split with auto-collapse.
// 7.1 - Enable auto-collapse.
$this->drupalGet("admin/structure/types/manage/$content_type/form-display");

// Edit form display settings.
Expand All @@ -288,7 +311,7 @@ public function testSplitTextFeature() {
$this->assertSession()->assertWaitOnAjaxRequest();
$this->drupalPostForm(NULL, [], $this->t('Save'));

// 6.2 - Test that simple text split works with auto-collapse.
// 7.2 - Test that simple text split works with auto-collapse.
$paragraph_content_0 = '<p>Content that will be in the first paragraph after the split.</p>';
$paragraph_content_1 = '<p>Content that will be in the second paragraph after the split.</p>';

Expand All @@ -313,7 +336,7 @@ public function testSplitTextFeature() {

$ck_editor_id_0 = $this->getCkEditorId(0);
static::assertEquals(
$paragraph_content_0 . PHP_EOL . PHP_EOL . '<p><br />' . PHP_EOL . '</p>' . PHP_EOL,
$paragraph_content_0 . PHP_EOL,
$driver->evaluateScript("CKEDITOR.instances['$ck_editor_id_0'].getData();")
);
}
Expand Down

0 comments on commit e19c7ef

Please sign in to comment.