Problem/Motivation

In #2994699-52: Create a CKEditor plugin to select and embed a media item from the Media Library, I raised some questions about CKEditorTestTrait (which is added by that issue). In his reply, @Wim Leers felt that we should defer those changes to a follow-up. I agree with that, so this is said follow-up.

Proposed resolution

Make the changes to CKEditorTestTrait outlined in #2994699-52: Create a CKEditor plugin to select and embed a media item from the Media Library's first few points.

Remaining tasks

Do it.

User interface changes

None.

API changes

A trait used by tests will have some internal refactoring, but no breaking API changes are expected.

Data model changes

None.

Release notes snippet

None.

Comments

phenaproxima created an issue. See original summary.

oknate’s picture

Copying over feedback from #2994699-52: Create a CKEditor plugin to select and embed a media item from the Media Library

1.

+++ b/core/modules/ckeditor/tests/src/Traits/CKEditorTestTrait.php
@@ -0,0 +1,103 @@
+   * @param string $instance_id
+   *   The CKEditor instance ID.

This parameter description needs to start with (optional) and state that it defaults to 'edit-body-0-value'.

2.

+++ b/core/modules/ckeditor/tests/src/Traits/CKEditorTestTrait.php
@@ -0,0 +1,103 @@
+    $this->getSession()->wait($timeout, $condition);

It might be preferable for us to use $this->assertSession()->assertJsCondition() here, since that will cause the test to fail (and rightfully so), if CKEditor is not ready in time.

3.

+++ b/core/modules/ckeditor/tests/src/Traits/CKEditorTestTrait.php
@@ -0,0 +1,103 @@
+  protected function assignNameToCkeditorIframe() {
+    $javascript = <<<JS
+(function(){
+  document.getElementsByClassName('cke_wysiwyg_frame')[0].id = 'ckeditor';
+})()
+JS;
+    $this->getSession()->evaluateScript($javascript);
+  }

What if there is more than one CKEditor instance on the page? Maybe this method should accept an $index parameter, defaulting to 0, to choose which CKEditor to work with. And then it can use that index to generate a unique name, like "ckeditor_0". Alternately, we could have this method loop through every CKEditor frame (getElementsByClassName() returns a set of elements anyway) and assign a unique one to each: "ckeditor_0", "ckeditor_1", etc.

4.

+++ b/core/modules/ckeditor/tests/src/Traits/CKEditorTestTrait.php
@@ -0,0 +1,103 @@
+  protected function pressEditorButton($name) {
+    $this->getSession()->switchToIFrame();
+    $button = $this->assertSession()->waitForElementVisible('css', 'a.cke_button__' . $name);
+    $this->assertNotEmpty($button);
+    $button->click();
+  }

Again, what if there are multiple CKEditor instances?

oknate’s picture

Status: Postponed » Needs review
StatusFileSize
new4.61 KB

This doesn't need to be postponed anymore, now that #2994699: Create a CKEditor plugin to select and embed a media item from the Media Library has landed.

oknate’s picture

StatusFileSize
new3.25 KB
new4.64 KB
oknate’s picture

Cleanup.

oknate’s picture

Note: This was backported to 8.7 yesterday: #3076609: \Drupal\Tests\ckeditor\FunctionalJavascript\CKEditorIntegrationTest fails on Sqlite, so if this issue is resolved the changes should go into that branch too.

oknate’s picture

Title: [PP-1] Improve CKEditorTestTrait » Improve CKEditorTestTrait

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jhedstrom’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me. Most of the changes were initially from #2994699-52: Create a CKEditor plugin to select and embed a media item from the Media Library, so this has been reviewed there too :)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 4: 3073261-4.patch, failed testing. View results

oknate’s picture

Status: Needs work » Reviewed & tested by the community

Setting back to RTBC, it looks like the failure was unrelated. I reran testing 8.9 against patch #4 and it was all green.

alexpott’s picture

Crediting @Wim Leers and @phenaproxima for review on the other issue.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed b28a392ece to 9.0.x and 5a4dd40a42 to 8.9.x and 1bce7388c9 to 8.8.x. Thanks!

Backported to 8.8.x as a test-only improvement.

  • alexpott committed b28a392 on 9.0.x
    Issue #3073261 by oknate, phenaproxima, Wim Leers: Improve...

  • alexpott committed 5a4dd40 on 8.9.x
    Issue #3073261 by oknate, phenaproxima, Wim Leers: Improve...

  • alexpott committed 1bce738 on 8.8.x
    Issue #3073261 by oknate, phenaproxima, Wim Leers: Improve...

Status: Fixed » Closed (fixed)

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