From a9ac24ad01024f457f9a568f1d1171231fd17908 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 28 Apr 2022 21:25:26 +0100
Subject: [PATCH] Revert "Revert "Issue #3276974 by hooroomoo, Wim Leers:
 [drupalMedia] Media View Modes don't work if alignment not enabled""

This reverts commit 45ee80dd7275bb9f613f4b59aee1b0d984d25f57.
---
 core/modules/ckeditor5/ckeditor5.ckeditor5.yml |  1 +
 .../FunctionalJavascript/MediaLibraryTest.php  |  5 -----
 .../src/FunctionalJavascript/MediaTest.php     | 18 +++++++++++++++++-
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/core/modules/ckeditor5/ckeditor5.ckeditor5.yml b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml
index e3256c37d73a..819d9b6686d5 100644
--- a/core/modules/ckeditor5/ckeditor5.ckeditor5.yml
+++ b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml
@@ -630,6 +630,7 @@ media_media:
   ckeditor5:
     plugins:
       - drupalMedia.DrupalMedia
+      - drupalMedia.DrupalElementStyle
     config:
       drupalMedia:
         toolbar: [mediaImageTextAlternative]
diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php
index f94987fb18a9..1cde072e9b9c 100644
--- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php
+++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php
@@ -229,12 +229,7 @@ public function testAllowedMediaTypes() {
         ->setFilterConfig('media_embed', [
           'status' => TRUE,
           'settings' => [
-            'default_view_mode' => 'view_mode_1',
             'allowed_media_types' => $allowed_media_types,
-            'allowed_view_modes' => [
-              'view_mode_1' => 'view_mode_1',
-              'view_mode_2' => 'view_mode_2',
-            ],
           ],
         ])->save();
 
diff --git a/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php b/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php
index e69b37e71487..3a77e71807fb 100644
--- a/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php
+++ b/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTest.php
@@ -1196,8 +1196,10 @@ function (ConstraintViolation $v) {
    * Tests that view mode is reflected onto the CKEditor 5 Widget wrapper, that
    * the media style toolbar allows changing the view mode and that the changes
    * are reflected on the widget and downcast drupal-media tag.
+   *
+   * @dataProvider providerTestViewMode
    */
-  public function testViewMode() {
+  public function testViewMode(bool $with_alignment) {
     EntityViewMode::create([
       'id' => 'media.view_mode_1',
       'targetEntityType' => 'media',
@@ -1263,6 +1265,10 @@ public function testViewMode() {
       ],
     ])->save();
 
+    if (!$with_alignment) {
+      $filter_format->filters('filter_align')->setConfiguration(array_merge($filter_format->filters('filter_align')->getConfiguration(), ['status' => FALSE]));
+    }
+
     // Test that view mode dependencies are returned from the MediaEmbed
     // filter's ::getDependencies() method.
     $expected_config_dependencies = [
@@ -1478,6 +1484,16 @@ public function testViewMode() {
     $this->assertNotEmpty($this->getBalloonButton('View Mode 4'));
   }
 
+  /**
+   * For testing view modes in different scenarios.
+   */
+  public function providerTestViewMode(): array {
+    return [
+      'with alignment' => [TRUE],
+      'without alignment' => [FALSE],
+    ];
+  }
+
   /**
    * Verifies value of an attribute on the downcast <drupal-media> element.
    *
-- 
GitLab