Problem/Motivation

Because of #3083275: [meta] Update tests that rely on Classy to not rely on it anymore and Classy being deprecated in Drupal 9 + removed in Drupal 10,: Tests that aren't specifically testing Classy yet declare $defaultTheme = 'classy'; should be refactored to use Stark as the default theme instead.

Proposed resolution

Change all tests in this module to use Stark as the default theme, and refactor the tests where needed so they continue to function properly.

Comments

danflanagan8 created an issue. See original summary.

danflanagan8’s picture

Assigned: danflanagan8 » Unassigned
Status: Active » Needs review
StatusFileSize
new18.87 KB

Some notes for reviewers...

1. In MediaAccessTest I had to make a change to the .view-media selector. But I couldn't pass up an opportunity to make the assertions below that considerably more meaningful. In a sense this was "required" because I was no longer able to select the view in a very convincing way.

2. In MediaJavascriptTestBase there's a helper method to assert links in a status message. This cannot use JsWebAssert::statusMessageContainsAfterWait because that method just checks text, not markup.

3. I put a @todo in CKEditorIntegrationTest and left it with Classy until Starterkit is ready. This one has tons of apparently important selection of classes.

4. In MediaSourceOEmbedVideoTest I remove a hunk of code that was added in #2982307: Misnamed template can cause fatal error in themes that do not extend Stable. No that the default theme is Stark, I believe that the hunk of code is no longer needed. It only makes sense if the test begins by running something that extends stable. This test also has one of those sneaky negative assertions with no positive counterpart that needed to be updated even though there wasn't a failure triggered moving from classy to stark.

5. MediaStandardProfileTest uses the standard profile, so it doesn't even need to declare a default theme.

6. This module has a ton of changes so I did not make any nice-to-have changes such as changing pageTextContains to statusMessageContains.

danflanagan8’s picture

Another note. In MediaDisplayTest, the following hunk is improved in addition to being refactored for stark. The final assertion was originally added in #2934850: Media Images should be rendered at a reasonable size by default. But that assertion doesn't actually test that at all. It just tested if there was an img tag, with no regard for the image style. That's why the assertion now checks that the image src corresponds to the appropriate image style.

+++ b/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php
@@ -193,14 +194,13 @@ public function testMediaDisplay() {
-    $assert_session->elementExists('css', '.field--name-field-related-media');
+    $assert_session->pageTextContains('Related media');
     // Media name element is not there.
-    $assert_session->elementNotExists('css', '.field--name-name');
     $assert_session->pageTextNotContains($image_media_name);
-    // Only one element is present inside the media container.
-    $this->assertCount(1, $page->findAll('css', '.field--name-field-related-media article.media--type-image > div'));
-    // Assert the image is present.
-    $assert_session->elementExists('css', '.field--name-field-related-media article.media--type-image img');
+    // Only one image is present.
+    $assert_session->elementsCount('xpath', '//img', 1);
+    // The image has the correct image style.
+    $assert_session->elementAttributeContains('xpath', '//img', 'src', '/styles/large/');
   }
larowlan’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php
    @@ -62,8 +62,10 @@ public function testMediaDisplay() {
    +    // Verify the "name" field is really not present. The name should be in the h1 with
    

    >80 here

  2. +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php
    @@ -176,7 +177,7 @@ public function testMediaDisplay() {
    -        'label' => 'hidden',
    +        'label' => 'above',
    

    why was this change needed?

  3. +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaDisplayTest.php
    @@ -193,14 +194,13 @@ public function testMediaDisplay() {
    +    $assert_session->elementAttributeContains('xpath', '//img', 'src', '/styles/large/');
    

    💪

  4. +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.php
    @@ -71,13 +71,13 @@ public function testMediaImageSource() {
    +    $image_element = $assert_session->elementExists('css', 'img');
    

    the test comment says 'inside the media element' but it doesn't look like we're testing that anymore, just that 'a img element exists'

  5. +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.php
    @@ -71,13 +71,13 @@ public function testMediaImageSource() {
    +    $field = $assert_session->elementExists('xpath', '//div[@class="layout-content"]/div/div[2]/div[1]');
    

    this feels brittle?

  6. +++ b/core/modules/media/tests/src/FunctionalJavascript/MediaSourceOEmbedVideoTest.php
    @@ -150,7 +150,7 @@ public function testMediaOEmbedVideoSource() {
    -    $assert_session->elementNotExists('css', '.image-style-thumbnail');
    +    $assert_session->elementNotExists('css', 'img');
    

    same here re losing some precision

danflanagan8’s picture

Status: Needs work » Needs review
StatusFileSize
new18.95 KB
new2.83 KB

Thanks for the review @larowlan. I have attached a new patch. Here are some notes.

4.1: Updated. Not sure how the patch even ran given this violation.

4.2: The presence of the label is used to assert the presence of the field since we no longer have a good css class to assert the presence of the field. I have updated a comment to perhaps clarify this slightly.

4.4: I have updated this so that an image is being found within the image field output. We're viewing a media at its "view" route, so this should be sufficient since any field on the page is a field from the media.

4.5: Very brittle! I have updated.

4.6: We are losing precision, but it's a negative assertion so I think it's ok to lose some precision. In fact, the lost precision may enhance the effectiveness of the test. We don't really care what the image style is. We just want to make sure the the oembed media is not being rendered as a media thumbnail (i.e. image). Rather, we only want it to be rendered as an oembed iframe, which is what the assertion before the img thing checks.

Let me know if I am unpersuasive about 4.6!

Or if anything else isn't quite right. Cheers!

Status: Needs review » Needs work

The last submitted patch, 5: 3275807-5.patch, failed testing. View results

danflanagan8’s picture

That looks like a real failure related to the Standard profile recently being changed to use Olivero:

1) Drupal\Tests\media\FunctionalJavascript\MediaStandardProfileTest::testMediaSources
Behat\Mink\Exception\ExpectationException: 0 elements matching css "article.media--type-audio > *" found on the page, but should be 1.

I'll dig in.

danflanagan8’s picture

Status: Needs work » Needs review
StatusFileSize
new28.45 KB
new9.87 KB

Here's the story. Olivero uses a div instead of an article to render media. So I made that little swap in MediaStandardProfileTest.

But why didn't this fail everywhere else once standard started using Olivero? It's because elsewhere MediaStandardProfileTest still declares Classy to be the defaultTheme and that value is honored even when the standard profile is used. But our patch here is removing the defaultTheme declaration such that we are relying on the theme in the standard profile. Which is now Olivero.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nod_’s picture

Status: Needs review » Reviewed & tested by the community

That checks out, classy is still used in the media_library module but that's out of scope here I'd say.

The various xpath expressions/css selectors changes make sense to me.

nod_’s picture

StatusFileSize
new28.56 KB

10.0.x version

danflanagan8’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for the review, @nod_!

And you beat me to noting the need for a reroll. That's because of this issue: #3271057: Move Media Library CKEditor 4 integrations from Media into CKEditor

That was fixed in 9.5.x, so I suspect the patch won't apply to D9.5.x either. I'll queue that up to confirm but I'm pretty sure. Adding the Need reroll tag and setting to NW.

danflanagan8’s picture

Status: Needs work » Needs review

I queued the patch in #11 up with 9.5. Back to NR. Sorry for the simul-posting confusion.

nod_’s picture

all green :)

nod_’s picture

Status: Needs review » Reviewed & tested by the community

Just applied the patch to the new branch, didn't touch at the logic :)

  • lauriii committed 1f14841 on 10.1.x
    Issue #3275807 by danflanagan8, nod_, larowlan: Media Tests should not...

  • lauriii committed bb7750a on 10.0.x
    Issue #3275807 by danflanagan8, nod_, larowlan: Media Tests should not...

  • lauriii committed 1e9d9b5 on 9.5.x
    Issue #3275807 by danflanagan8, nod_, larowlan: Media Tests should not...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed 1f14841 and pushed to 10.1.x. Also cherry-picked to 10.0.x and 9.5.x. Thanks!

Status: Fixed » Closed (fixed)

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