Problem/Motivation

Today, the CKEditorIntegrationTest for the DrupalImage doesn't exists.
I would suggest a new method for DrupalImage into the CKEditorIntegrationTest which will check the basic behaviours of DrupalImage CKEditor Plugin.

To go further, another IntegrationTest should be created for DrupalImageCaption Plugin.

Proposed resolution

Add a new testDrupalImageDialog method.

Remaining tasks

Review

User interface changes

None

API changes

None

Data model changes

None

PS: It's my first contribution to the Core & I learn a lot about the JavascriptTestBase during this patch.

Comments

wengerk created an issue. See original summary.

wengerk’s picture

Issue summary: View changes
wengerk’s picture

Status: Active » Needs review
wengerk’s picture

Issue summary: View changes
wim leers’s picture

Thanks, this is a super helpful contribution! ❤️

+++ b/core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorDrupalImageIntegrationTest.php
@@ -0,0 +1,170 @@
+class CKEditorDrupalImageIntegrationTest extends JavascriptTestBase {

Rather than creating an entirely new test class with a single testSomething() method, can you instead add a new test method to \Drupal\Tests\ckeditor\FunctionalJavascript\CKEditorIntegrationTest?

That will also make this issue much easier to review :)

wengerk’s picture

StatusFileSize
new2.6 KB

Hi Wim Leers !

Thanks, I re-rolled the patch and move it into the \Drupal\Tests\ckeditor\FunctionalJavascript\CKEditorIntegrationTest.

On this patch, I had to create a clickOnElement function to click on a <a> tag (the button into CKeditor Toolbar) which is not reachable with standards Mink functions.

For futur JavascriptTests on CKeditor & others it would may be useful to have this function into JavascriptTestBase or BrowserTestBase ?

wim leers’s picture

Status: Needs work » Needs review

Let's let testbot test #6 :)

wim leers’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
    @@ -38,7 +39,7 @@ protected function setUp() {
    -      'name' => 'Filtered HTML',
    +      'name'   => 'Filtered HTML',
    

    Unnecessary change, let's revert this.

  2. +++ b/core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
    @@ -118,4 +119,51 @@ public function testFragmentLink() {
    +    $this->clickOnElement('css', '.cke_button__drupalimage');
    ...
    +  protected function clickOnElement($selector_type, $selector) {
    

    Why can't this use \Drupal\Tests\BrowserTestBase::click()? Isn't the problem that you're not waiting for CKEditor to have loaded? (See \Drupal\Tests\ckeditor\FunctionalJavascript\AjaxCssTest::waitOnCkeditorInstance().)

wengerk’s picture

StatusFileSize
new1.23 KB

I didn't know Drupal already added a click function in \Drupal\Tests\BrowserTestBase ! Thanks.

I change the code, remove the unnecessary change in #8 & remove the clickOnElement.

wengerk’s picture

Status: Needs work » Needs review
wengerk’s picture

Issue summary: View changes

Update Motivation & Proposed Resolution according discussion in #5

wim leers’s picture

Status: Needs review » Needs work

Great! Look how wonderfully small the patch now became :) This is now ready, only the comments need to be refined a little bit more:

  1. +++ b/core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
    @@ -118,4 +118,24 @@ public function testFragmentLink() {
    +   * Tests CKEditor button image apprear, works & dialog open.
    

    Tests if the Image button appears and works as expected.

  2. +++ b/core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
    @@ -118,4 +118,24 @@ public function testFragmentLink() {
    +    // Asserts the Dialog open when clicking on the button.
    

    Asserts the image dialog opens when clicking the Image button.

Once those are done, this is RTBC!

wengerk’s picture

StatusFileSize
new1.24 KB
new371 bytes

Thanks for you review & your help @wim-leers !

wengerk’s picture

Status: Needs work » Needs review

Testing changes in #13 with testbot.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! 👍

wengerk’s picture

StatusFileSize
new1.27 KB
new889 bytes

The patch in #13 works but I use some features scheduled for removal in Drupal 9.0.0 e.g. assertElementPresent from Drupal\FunctionalTests\AssertLegacyTrait.

I switch to the Drupal\Tests\WebAssert methods as recommended in Drupal\FunctionalTests\AssertLegacyTrait.

Sorry for requesting a review again :/ but I think it's important, specially for new tests, to follow the bests practices.

wengerk’s picture

Status: Reviewed & tested by the community » Needs review

changes to follow bests practices - let's tests it with testbot.

Status: Needs review » Needs work

The last submitted patch, 16: interdiff-2912399-13-16.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Reviewed & tested by the community

👍

FYI: upload interdiffs as .txt files, then test bot doesn’t try to test them! That’s the convention we’ve been using here on d.o for years :)

alexpott’s picture

Just triggering an 8.4.x run as this is adding test coverage and it'd be great if it is backportable.

+++ b/core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
@@ -118,4 +118,25 @@ public function testFragmentLink() {
+    $web_assert->assertWaitOnAjaxRequest();
+
+    $web_assert->elementExists('css', '.ui-dialog');

These two calls could be replaced by $web_assert->waitForElement('css', '.ui-dialog'); but that's not necessary for the patch to be committed.

alexpott’s picture

Crediting @Wim Leers for the code reviews.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed e9c9ee5282 to 8.5.x and 1136b5980d to 8.4.x. Thanks!

  • alexpott committed e9c9ee5 on 8.5.x
    Issue #2912399 by wengerk, Wim Leers: Extend the CKEditorIntegrationTest...

  • alexpott committed 1136b59 on 8.4.x
    Issue #2912399 by wengerk, Wim Leers: Extend the CKEditorIntegrationTest...

  • xjm committed 90c4ab5 on 8.5.x
    Revert "Issue #2912399 by wengerk, Wim Leers: Extend the...

  • xjm committed af7e004 on 8.4.x
    Revert "Issue #2912399 by wengerk, Wim Leers: Extend the...
xjm’s picture

Status: Fixed » Needs work

I believe this issue introduced a new random fail:
https://www.drupal.org/pift-ci-job/794678

https://www.drupal.org/pift-ci-job/794008 Edit: not that one, that one is different. See also #2701393: Switching between editors on the format configuration causes errors upon save.

This might be fixed by making the change mentioned in #20.

xjm’s picture

#2701393: Switching between editors on the format configuration causes errors upon save was reverted as well; note that these are two separate random failures in two separate tests, but they have a similar drawback with waiting for the AJAX request but not the element.

tedbow’s picture

+++ b/core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php
@@ -118,4 +118,25 @@ public function testFragmentLink() {
+    $web_assert->assertWaitOnAjaxRequest();
+
+    $web_assert->elementExists('css', '.ui-dialog');

In Settings Tray we found that relying on \Drupal\FunctionalJavascriptTests\JSWebAssert::assertWaitOnAjaxRequest can lead to random failures because often the following elementExists() check is passing just because the testbot is running fast enough.

So we added \Drupal\Tests\settings_tray\FunctionalJavascript\SettingsTrayJavascriptTestBase::assertElementVisibleAfterWait

which is just
$this->assertNotEmpty($this->assertSession()->waitForElementVisible($selector, $locator, $timeout));

So I am not sure if in this test your element will be visible but you could replace both these lines with

$this->assertNotEmpty($this->assertSession()->waitForElement('css', '.ui-dialog'));

Then you aren't waiting for ajax calls to be done which seems tricky but waiting for the effect of the ajax call, i.e. the element on the page.

wengerk’s picture

StatusFileSize
new1.25 KB
new411 bytes

As suggested in #20 & #29, the both lines:

$web_assert->assertWaitOnAjaxRequest();
$web_assert->elementExists('css', '.ui-dialog');

has been replaced by a single:
$this->assertNotEmpty($web_assert->waitForElement('css', '.ui-dialog'));

Thanks all for you help !

wengerk’s picture

Status: Needs work » Needs review
tedbow’s picture

StatusFileSize
new2.19 KB
new2.14 KB

@wengerk thanks for the patch.

Now let's see if we can make the this random failure happen by running only this test 110 times with and without fix in #30

The last submitted patch, 32: 2912399-16_110x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 32: 2912399-30_110x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tedbow’s picture

Status: Needs work » Needs review
StatusFileSize
new2.13 KB
new2.19 KB

darn you "\"

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wengerk’s picture

StatusFileSize
new1.22 KB
new690 bytes
new1.77 KB

Re-rolled for Drupal 8.7.x

I also upload a x110 files to asserts no random-fails appear in this test.

The x110 tests fail but no because of random fail. It seems the "old fashion" way to run the same tests did'nt work anymore ?

Status: Needs review » Needs work

The last submitted patch, 38: 2912399-38_110x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

wengerk’s picture

Status: Needs work » Needs review
wim leers’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +JavaScript

The last submitted patch, 35: 2912399-16_110x.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Second time lucky!

Committed and pushed cab7a12733 to 8.7.x and 4390dc6b92 to 8.6.x. Thanks!

  • alexpott committed cab7a12 on 8.7.x
    Issue #2912399 by wengerk, tedbow, Wim Leers: Extend the...

  • alexpott committed 4390dc6 on 8.6.x
    Issue #2912399 by wengerk, tedbow, Wim Leers: Extend the...
wim leers’s picture

YAY! This helps us be more confident about CKEditor updates :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

idebr’s picture

Version: 8.7.x-dev » 8.6.x-dev