From ac56748d350532c9fc79b9f05a8169d78254664a Mon Sep 17 00:00:00 2001
From: catch <6915-catch@users.noreply.drupalcode.org>
Date: Wed, 17 Jul 2024 02:43:48 +0100
Subject: [PATCH] Issue #3368071 by tstoeckler, longwave: Installing Content
 Translation module breaks Rest resources

(cherry picked from commit 45bcde634d857f0f8ea0909b7845dca85f53e846)
---
 .../Rest/BlockContentResourceTestBase.php          |  2 +-
 .../content_translation.link_relation_types.yml    | 14 ++++++++++++++
 .../src/Functional/Rest/MediaResourceTestBase.php  | 13 ++++++++++++-
 .../Rest/MenuLinkContentResourceTestBase.php       | 13 ++++++++++++-
 .../src/Functional/Rest/NodeResourceTestBase.php   | 13 ++++++++++++-
 .../src/Functional/Rest/TermResourceTestBase.php   |  2 +-
 6 files changed, 52 insertions(+), 5 deletions(-)
 create mode 100644 core/modules/content_translation/content_translation.link_relation_types.yml

diff --git a/core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php b/core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php
index f3af50a1f58c..00f5a0b8f2a7 100644
--- a/core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php
+++ b/core/modules/block_content/tests/src/Functional/Rest/BlockContentResourceTestBase.php
@@ -17,7 +17,7 @@ abstract class BlockContentResourceTestBase extends EntityResourceTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['block_content'];
+  protected static $modules = ['block_content', 'content_translation'];
 
   /**
    * {@inheritdoc}
diff --git a/core/modules/content_translation/content_translation.link_relation_types.yml b/core/modules/content_translation/content_translation.link_relation_types.yml
new file mode 100644
index 000000000000..6c1f0916ba40
--- /dev/null
+++ b/core/modules/content_translation/content_translation.link_relation_types.yml
@@ -0,0 +1,14 @@
+# Content Translation extension relation types.
+# See https://tools.ietf.org/html/rfc5988#section-4.2.
+drupal:content-translation-overview:
+  uri: https://drupal.org/link-relations/drupal-content-translation-overview
+  description: A page where translations of a resource can be viewed.
+drupal:content-translation-add:
+  uri: https://drupal.org/link-relations/drupal-content-translation-add
+  description: A page where a translation of a resource can be created.
+drupal:content-translation-edit:
+  uri: https://drupal.org/link-relations/drupal-content-translation-edit
+  description: A page where a translation of a resource can be edited.
+drupal:content-translation-delete:
+  uri: https://drupal.org/link-relations/drupal-content-translation-delete
+  description: A page where a translation of a resource can be deleted.
diff --git a/core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php b/core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php
index a0bab34bd445..7b797b8e9678 100644
--- a/core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php
+++ b/core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php
@@ -21,7 +21,7 @@ abstract class MediaResourceTestBase extends EntityResourceTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['media'];
+  protected static $modules = ['content_translation', 'media'];
 
   /**
    * {@inheritdoc}
@@ -309,6 +309,17 @@ protected function getExpectedUnauthorizedAccessMessage($method) {
     }
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  protected function getExpectedCacheContexts() {
+    return [
+      'languages:language_interface',
+      'url.site',
+      'user.permissions',
+    ];
+  }
+
   /**
    * {@inheritdoc}
    */
diff --git a/core/modules/menu_link_content/tests/src/Functional/Rest/MenuLinkContentResourceTestBase.php b/core/modules/menu_link_content/tests/src/Functional/Rest/MenuLinkContentResourceTestBase.php
index f959e3116071..e8490810beb7 100644
--- a/core/modules/menu_link_content/tests/src/Functional/Rest/MenuLinkContentResourceTestBase.php
+++ b/core/modules/menu_link_content/tests/src/Functional/Rest/MenuLinkContentResourceTestBase.php
@@ -15,7 +15,7 @@ abstract class MenuLinkContentResourceTestBase extends EntityResourceTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['menu_link_content'];
+  protected static $modules = ['content_translation', 'menu_link_content'];
 
   /**
    * {@inheritdoc}
@@ -231,4 +231,15 @@ protected function getExpectedUnauthorizedAccessMessage($method) {
     }
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  protected function getExpectedCacheContexts() {
+    return [
+      'languages:language_interface',
+      'url.site',
+      'user.permissions',
+    ];
+  }
+
 }
diff --git a/core/modules/node/tests/src/Functional/Rest/NodeResourceTestBase.php b/core/modules/node/tests/src/Functional/Rest/NodeResourceTestBase.php
index 484f73791cf2..d8c663bb03c0 100644
--- a/core/modules/node/tests/src/Functional/Rest/NodeResourceTestBase.php
+++ b/core/modules/node/tests/src/Functional/Rest/NodeResourceTestBase.php
@@ -15,7 +15,7 @@ abstract class NodeResourceTestBase extends EntityResourceTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['node', 'path'];
+  protected static $modules = ['content_translation', 'node', 'path'];
 
   /**
    * {@inheritdoc}
@@ -222,6 +222,17 @@ protected function getExpectedUnauthorizedAccessMessage($method) {
     return parent::getExpectedUnauthorizedAccessMessage($method);
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  protected function getExpectedCacheContexts() {
+    return [
+      'languages:language_interface',
+      'url.site',
+      'user.permissions',
+    ];
+  }
+
   /**
    * Tests PATCHing a node's path with and without 'create url aliases'.
    *
diff --git a/core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php b/core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php
index 2c64a7b04c9b..cdd3d8fbb9d6 100644
--- a/core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php
+++ b/core/modules/taxonomy/tests/src/Functional/Rest/TermResourceTestBase.php
@@ -15,7 +15,7 @@ abstract class TermResourceTestBase extends EntityResourceTestBase {
   /**
    * {@inheritdoc}
    */
-  protected static $modules = ['taxonomy', 'path'];
+  protected static $modules = ['content_translation', 'path', 'taxonomy'];
 
   /**
    * {@inheritdoc}
-- 
GitLab