From f0d3a7bf589e95a2d348289670daa15b30a6ee71 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Wed, 10 Jan 2024 21:12:27 +0000
Subject: [PATCH] Issue #2254189 by smustgrave, quietone, anya_m, andregp, sun,
 joachim: Fix test performance of Drupal\node\Tests\NodeTranslationUITest

---
 .../BlockContentTranslationUITest.php         |  1 +
 .../Functional/CommentTranslationUITest.php   |  1 +
 .../ContentTestTranslationUITest.php          |  1 +
 .../ContentTranslationMetadataFieldsTest.php  |  8 +++
 ...ewTranslationWithExistingRevisionsTest.php |  1 +
 ...slationOutdatedRevisionTranslationTest.php |  1 +
 ...slationRevisionTranslationDeletionTest.php |  1 +
 .../ContentTranslationSyncImageTest.php       |  1 +
 .../Functional/ContentTranslationTestBase.php |  6 +-
 ...entTranslationUntranslatableFieldsTest.php |  1 +
 .../ContentTranslationWorkflowsTest.php       |  1 +
 .../Functional/Views/TranslationLinkTest.php  |  1 +
 .../LayoutBuilderTranslationTest.php          |  1 +
 .../src/Functional/MediaTranslationUITest.php |  1 +
 .../MenuLinkContentTranslationUITest.php      |  1 +
 .../src/Functional/NodeTranslationUITest.php  | 59 ++++++++++++-------
 .../Functional/ShortcutTranslationUITest.php  |  1 +
 .../src/Functional/TermTranslationUITest.php  |  1 +
 .../src/Functional/UserTranslationUITest.php  |  1 +
 19 files changed, 64 insertions(+), 25 deletions(-)

diff --git a/core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php b/core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php
index 98d302dbc14b..1b24d5c02e31 100644
--- a/core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php
+++ b/core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php
@@ -51,6 +51,7 @@ protected function setUp(): void {
     $this->bundle = 'basic';
     $this->testLanguageSelector = FALSE;
     parent::setUp();
+    $this->doSetup();
 
     $this->drupalPlaceBlock('page_title_block');
   }
diff --git a/core/modules/comment/tests/src/Functional/CommentTranslationUITest.php b/core/modules/comment/tests/src/Functional/CommentTranslationUITest.php
index e20146500ab2..779700b44d32 100644
--- a/core/modules/comment/tests/src/Functional/CommentTranslationUITest.php
+++ b/core/modules/comment/tests/src/Functional/CommentTranslationUITest.php
@@ -71,6 +71,7 @@ protected function setUp(): void {
     $this->testLanguageSelector = FALSE;
     $this->subject = $this->randomMachineName();
     parent::setUp();
+    $this->doSetup();
   }
 
   /**
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTestTranslationUITest.php b/core/modules/content_translation/tests/src/Functional/ContentTestTranslationUITest.php
index ba0cbf67071d..520eca531f01 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTestTranslationUITest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTestTranslationUITest.php
@@ -48,6 +48,7 @@ protected function setUp(): void {
     // Use the entity_test_mul as this has multilingual property support.
     $this->entityTypeId = 'entity_test_mul_changed';
     parent::setUp();
+    $this->doSetup();
   }
 
   /**
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationMetadataFieldsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationMetadataFieldsTest.php
index c189ede404f6..f391918b7a4a 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationMetadataFieldsTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationMetadataFieldsTest.php
@@ -43,6 +43,14 @@ protected function setupBundle() {
     $this->createContentType(['type' => $this->bundle]);
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp(): void {
+    parent::setUp();
+    $this->doSetup();
+  }
+
   /**
    * Tests skipping setting non translatable metadata fields.
    */
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationNewTranslationWithExistingRevisionsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationNewTranslationWithExistingRevisionsTest.php
index e11056f56c56..fe41739bcdb5 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationNewTranslationWithExistingRevisionsTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationNewTranslationWithExistingRevisionsTest.php
@@ -33,6 +33,7 @@ class ContentTranslationNewTranslationWithExistingRevisionsTest extends ContentT
    */
   protected function setUp(): void {
     parent::setUp();
+    $this->doSetup();
     $this->enableContentModeration();
   }
 
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php
index b01f5b5c70c3..cb18d8e0bfd5 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php
@@ -22,6 +22,7 @@ class ContentTranslationOutdatedRevisionTranslationTest extends ContentTranslati
    */
   protected function setUp(): void {
     parent::setUp();
+    $this->doSetup();
     $this->enableContentModeration();
   }
 
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationRevisionTranslationDeletionTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationRevisionTranslationDeletionTest.php
index 97e2f0da6ba6..12a726c3db26 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationRevisionTranslationDeletionTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationRevisionTranslationDeletionTest.php
@@ -22,6 +22,7 @@ class ContentTranslationRevisionTranslationDeletionTest extends ContentTranslati
    */
   protected function setUp(): void {
     parent::setUp();
+    $this->doSetup();
     $this->enableContentModeration();
   }
 
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php
index 899083a87cde..fb1f3c18bf61 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php
@@ -57,6 +57,7 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase {
    */
   protected function setUp(): void {
     parent::setUp();
+    $this->doSetup();
     $this->files = $this->drupalGetTestFiles('image');
   }
 
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php
index 405fa2beea38..48e5f94efe09 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationTestBase.php
@@ -83,11 +83,9 @@ abstract class ContentTranslationTestBase extends BrowserTestBase {
   protected $manager;
 
   /**
-   * {@inheritdoc}
+   * Completes preparation for content translation tests.
    */
-  protected function setUp(): void {
-    parent::setUp();
-
+  protected function doSetup(): void {
     $this->setupLanguages();
     $this->setupBundle();
     $this->enableTranslation();
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php
index c499328bd020..014d78a6ddd9 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php
@@ -32,6 +32,7 @@ class ContentTranslationUntranslatableFieldsTest extends ContentTranslationPendi
    */
   protected function setUp(): void {
     parent::setUp();
+    $this->doSetup();
 
     // Configure one field as untranslatable.
     $this->drupalLogin($this->administrator);
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php
index c8b740e0477b..d55e49e786ae 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php
@@ -74,6 +74,7 @@ class ContentTranslationWorkflowsTest extends ContentTranslationTestBase {
    */
   protected function setUp(): void {
     parent::setUp();
+    $this->doSetup();
 
     $field_storage = FieldStorageConfig::create([
       'field_name' => 'field_reference',
diff --git a/core/modules/content_translation/tests/src/Functional/Views/TranslationLinkTest.php b/core/modules/content_translation/tests/src/Functional/Views/TranslationLinkTest.php
index 336bc3b9cb67..ff218d0e6c55 100644
--- a/core/modules/content_translation/tests/src/Functional/Views/TranslationLinkTest.php
+++ b/core/modules/content_translation/tests/src/Functional/Views/TranslationLinkTest.php
@@ -42,6 +42,7 @@ protected function setUp(): void {
     $this->entityTypeId = 'user';
 
     parent::setUp();
+    $this->doSetup();
 
     // Assign user 1  a language code so that the entity can be translated.
     $user = User::load(1);
diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTranslationTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTranslationTest.php
index 4b5999d90302..c52bc8cb347f 100644
--- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTranslationTest.php
+++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTranslationTest.php
@@ -41,6 +41,7 @@ class LayoutBuilderTranslationTest extends ContentTranslationTestBase {
    */
   protected function setUp(): void {
     parent::setUp();
+    $this->doSetup();
     $this->setUpViewDisplay();
     $this->setUpEntities();
   }
diff --git a/core/modules/media/tests/src/Functional/MediaTranslationUITest.php b/core/modules/media/tests/src/Functional/MediaTranslationUITest.php
index 20d3cd8c6e2c..9e8538b9fe78 100644
--- a/core/modules/media/tests/src/Functional/MediaTranslationUITest.php
+++ b/core/modules/media/tests/src/Functional/MediaTranslationUITest.php
@@ -49,6 +49,7 @@ protected function setUp(): void {
     $this->entityTypeId = 'media';
     $this->bundle = 'test';
     parent::setUp();
+    $this->doSetup();
   }
 
   /**
diff --git a/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentTranslationUITest.php b/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentTranslationUITest.php
index e8ab747f60ca..c711b8668b02 100644
--- a/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentTranslationUITest.php
+++ b/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentTranslationUITest.php
@@ -41,6 +41,7 @@ protected function setUp(): void {
     $this->entityTypeId = 'menu_link_content';
     $this->bundle = 'menu_link_content';
     parent::setUp();
+    $this->doSetup();
   }
 
   /**
diff --git a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php
index 004fab2e56b6..b4ea93b0cf7a 100644
--- a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php
+++ b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php
@@ -3,12 +3,18 @@
 namespace Drupal\Tests\node\Functional;
 
 use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\Entity\EntityFormDisplay;
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\Core\Url;
 use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
 use Drupal\Tests\language\Traits\LanguageTestTrait;
+use Drupal\comment\Tests\CommentTestTrait;
+use Drupal\field\Entity\FieldConfig;
+use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\language\Entity\ConfigurableLanguage;
 use Drupal\node\Entity\Node;
+use Drupal\user\Entity\Role;
+use Drupal\user\RoleInterface;
 
 /**
  * Tests the Node Translation UI.
@@ -19,6 +25,7 @@
 class NodeTranslationUITest extends ContentTranslationUITestBase {
 
   use LanguageTestTrait;
+  use CommentTestTrait;
 
   /**
    * {@inheritdoc}
@@ -29,18 +36,11 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
    * {@inheritdoc}
    */
   protected $defaultCacheContexts = [
-    'languages:language_interface',
     'theme',
-    'route',
     'timezone',
-    'url.path.parent',
     'url.query_args:_wrapper_format',
     'url.site',
-    'user.roles',
-    'url.path.is_front',
-    // These two cache contexts are added by BigPipe.
-    'cookies:big_pipe_nojs',
-    'session.exists',
+    'user.permissions',
   ];
 
   /**
@@ -53,18 +53,9 @@ class NodeTranslationUITest extends ContentTranslationUITestBase {
     'language',
     'content_translation',
     'node',
-    'datetime',
     'field_ui',
-    'help',
   ];
 
-  /**
-   * The profile to install as a basis for testing.
-   *
-   * @var string
-   */
-  protected $profile = 'standard';
-
   /**
    * {@inheritdoc}
    */
@@ -73,6 +64,10 @@ protected function setUp(): void {
     $this->bundle = 'article';
     parent::setUp();
 
+    // Create the bundle.
+    $this->drupalCreateContentType(['type' => 'article', 'title' => 'Article']);
+    $this->doSetup();
+
     // Ensure the help message is shown even with prefixed paths.
     $this->drupalPlaceBlock('help_block', ['region' => 'content']);
 
@@ -99,10 +94,6 @@ public function testPublishedStatusNoFields() {
     $this->drupalGet('admin/structure/types/manage/article/fields');
     $this->drupalGet('admin/structure/types/manage/article/fields/node.article.' . $this->fieldName . '/delete');
     $this->submitForm([], 'Delete');
-    $this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_tags/delete');
-    $this->submitForm([], 'Delete');
-    $this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_image/delete');
-    $this->submitForm([], 'Delete');
 
     // Add a node.
     $default_langcode = $this->langcodes[0];
@@ -312,6 +303,14 @@ public function testDisabledBundle() {
    * Tests that translations are rendered properly.
    */
   public function testTranslationRendering() {
+    // Add a comment field to the article content type.
+    \Drupal::service('module_installer')->install(['comment']);
+    $this->addDefaultCommentField('node', 'article');
+
+    // Add 'post comments' permission to the authenticated role.
+    $role = Role::load(RoleInterface::AUTHENTICATED_ID);
+    $role->grantPermission('post comments')->save();
+
     $default_langcode = $this->langcodes[0];
     $values[$default_langcode] = $this->getNewEntityValues($default_langcode);
     $this->entityId = $this->createEntity($values[$default_langcode], $default_langcode);
@@ -556,6 +555,20 @@ public function testRevisionTranslationRendering() {
    * Tests title is not escaped (but XSS-filtered) for details form element.
    */
   public function testDetailsTitleIsNotEscaped() {
+    // Create an image field.
+    \Drupal::service('module_installer')->install(['image']);
+    FieldStorageConfig::create([
+      'entity_type' => 'node',
+      'field_name' => 'field_image',
+      'type' => 'image',
+    ])->save();
+    FieldConfig::create([
+      'entity_type' => 'node',
+      'field_name' => 'field_image',
+      'bundle' => 'article',
+      'translatable' => TRUE,
+    ])->save();
+
     $this->drupalLogin($this->administrator);
     // Make the image field a multi-value field in order to display a
     // details form element.
@@ -563,6 +576,10 @@ public function testDetailsTitleIsNotEscaped() {
     $this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_image');
     $this->submitForm($edit, 'Save');
 
+    // Enable the display of the image field.
+    EntityFormDisplay::load('node.article.default')
+      ->setComponent('field_image', ['region' => 'content'])->save();
+
     // Make the image field non-translatable.
     static::setFieldTranslatable('node', 'article', 'field_image', FALSE);
 
diff --git a/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php b/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php
index 0418d807923b..c1271e499b3d 100644
--- a/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php
+++ b/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php
@@ -43,6 +43,7 @@ protected function setUp(): void {
     $this->entityTypeId = 'shortcut';
     $this->bundle = 'default';
     parent::setUp();
+    $this->doSetup();
   }
 
   /**
diff --git a/core/modules/taxonomy/tests/src/Functional/TermTranslationUITest.php b/core/modules/taxonomy/tests/src/Functional/TermTranslationUITest.php
index 2b4ad75364e1..35ff9301e099 100644
--- a/core/modules/taxonomy/tests/src/Functional/TermTranslationUITest.php
+++ b/core/modules/taxonomy/tests/src/Functional/TermTranslationUITest.php
@@ -50,6 +50,7 @@ protected function setUp(): void {
     $this->entityTypeId = 'taxonomy_term';
     $this->bundle = 'tags';
     parent::setUp();
+    $this->doSetup();
   }
 
   /**
diff --git a/core/modules/user/tests/src/Functional/UserTranslationUITest.php b/core/modules/user/tests/src/Functional/UserTranslationUITest.php
index a1220381cc3d..34dfc2ddae35 100644
--- a/core/modules/user/tests/src/Functional/UserTranslationUITest.php
+++ b/core/modules/user/tests/src/Functional/UserTranslationUITest.php
@@ -54,6 +54,7 @@ protected function setUp(): void {
     $this->testLanguageSelector = FALSE;
     $this->name = $this->randomMachineName();
     parent::setUp();
+    $this->doSetup();
 
     \Drupal::entityTypeManager()->getStorage('user')->resetCache();
   }
-- 
GitLab