Problem/Motivation

The media library integration should have test coverage

Proposed resolution

Port existing tests.

Remaining tasks

  1. Port test coverage from \Drupal\Tests\media_library\FunctionalJavascript\CKEditorIntegrationTest. #3232409: Media Embed button is broken already added a subset of this: \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLibraryTest copied a portion of it. But not all. We should expand it here:
    1. #3232409 already ported ::testButton(). But incompletely. We should expand it in this issue.
    2. ::testAllowedMediaTypes() depends on more than just the filter settings: PHP code for CKEditor 5 must invoke the media library dialog correctly, using the filter settings (see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\MediaLibrary::getDynamicPluginConfig()). This still should be ported in its entirety.
    3. ::testConfigurationValidation() does not need to be ported.
  2. Port \Drupal\Tests\media\FunctionalJavascript\CKEditorIntegrationTest

Issue fork ckeditor5-3206522

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

zrpnr created an issue. See original summary.

zrpnr’s picture

Issue tags: +d10readiness, +NorthAmerica2021

Tagging for Contribution event

gábor hojtsy’s picture

Issue tags: -d10readiness +Drupal 10
wim leers’s picture

Issue summary: View changes

We should be able to copy tests from core similar to the work done with Quick Edit tests

\Drupal\Tests\media_library\FunctionalJavascript\CKEditorIntegrationTest

wim leers’s picture

Title: Add test coverage for media library » Add FunctionalJavascript test coverage for media library
effulgentsia’s picture

\Drupal\Tests\media_library\FunctionalJavascript\CKEditorIntegrationTest

There's also a CKEditorIntegrationTest class in the \Drupal\Tests\media namespace and the \Drupal\Tests\ckeditor namesapce. Might want to copy/extend those as well unless you already have the equivalent test coverage handled some other way.

wim leers’s picture

#6++

wim leers’s picture

Updated remaining tasks. Fixed copy/paste error in issue summary.

#6: \Drupal\Tests\ckeditor\FunctionalJavascript\CKEditorIntegrationTest contains:

  1. ::testOffCanvasStyles() → CKE5 equivalent already exists at \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5OffCanvasTest
  2. ::testDrupalImageDialog() + ::testDrupalImageCaptionDialog() → irrelevant, since CKE5 is not using EditorImageDialog
  3. ::testFragmentLink() → tested, verified this is not yet working. Opened new issue for this: #3238257: Fragment link pointing to <textarea> should be redirected to CKEditor 5 instance when CKEditor 5 replaced that textarea.

yash.rode made their first commit to this issue’s fork.

wim leers’s picture

Priority: Normal » Critical
  1. Port \Drupal\Tests\media\FunctionalJavascript\CKEditorIntegrationTest

This test's \Drupal\Tests\media\FunctionalJavascript\CKEditorIntegrationTest::testPreviewUsesDefaultThemeAndIsClientCacheable() (and others) will fail, because SA-CORE-2021-006 by azinck, seanB, effulgentsia, marcoscano, larowlan, phenaproxima, xjm, mcdruid, drumm, briantschu from September 15 introduced a new CSRF check that the CKEditor 5 module is not yet using.

That makes this test coverage even more important!

wim leers’s picture

🥳 Tests are running!

wim leers’s picture

Status: Active » Needs work

Not yet passing tests though, but getting there 👍

wim leers’s picture

The tests are currently failing because of what I wrote in #10 :) So all that still needs to happen here, is porting those same changes that were made to the CKEditor 4 media integration into our CKEditor 5 plugin. I provided @yash.rode with very specific pointers just now, I'm sure he'll be pushing new commits that make this MR green soon 🤓

wim leers’s picture

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

Status: Needs review » Needs work

Looking good — if I diff this against \Drupal\Tests\media_library\FunctionalJavascript\CKEditorIntegrationTest, I can find virtually no differences; and all the ones that I do find are essential 👍

Marking needs work again for the remaining work.

wim leers’s picture

To clarify: the remaining work here is to port the \Drupal\Tests\media\FunctionalJavascript\CKEditorIntegrationTest test — so far it only covers \Drupal\Tests\media_library\FunctionalJavascript\CKEditorIntegrationTest.

wim leers’s picture

yash.rode’s picture

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

Assigned: Unassigned » wim leers

Yay, green! Reviewing 🥳

wim leers’s picture

AFAICT the following test methods actually should be ported too:

  1. \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testErrorMessages()
  2. \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testAlt()

Both of those are implemented by the current DrupalMedia CKE5 plugin. On it…

wim leers’s picture

Finished porting ::testErrorMessages(). A single assertion is blocked on another issue: #3194084-17: Support functionality equivalent to ckeditor_stylesheets.

wim leers’s picture

The majority of \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest::testAlt() has now been ported. Found one significant behavioral difference, opened an issue for that: #3246365: [drupalMedia] Show the Image Media's default alt text that is being overridden.

Two tiny changes to the JS logic were required: the user-entered alt should always be trimmed, and when no value is provided, the attribute should be removed from the model. Trivial changes 😊

wim leers’s picture

Spent 45 minutes trying to fix #3246380: [drupalMedia] Media previews do not update after alt text was modified, but couldn't figure it out, hence created that issue. Now ::testAlt() is complete.

wim leers’s picture

wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs review » Reviewed & tested by the community

wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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