diff --git a/core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php b/core/modules/block_content/tests/src/Functional/BlockContentTranslationUITest.php index 98d302dbc14..1b24d5c02e3 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 @@ class BlockContentTranslationUITest extends ContentTranslationUITestBase { $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 e20146500ab..779700b44d3 100644 --- a/core/modules/comment/tests/src/Functional/CommentTranslationUITest.php +++ b/core/modules/comment/tests/src/Functional/CommentTranslationUITest.php @@ -71,6 +71,7 @@ class CommentTranslationUITest extends ContentTranslationUITestBase { $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 ba0cbf67071..520eca531f0 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 @@ class ContentTestTranslationUITest extends ContentTranslationUITestBase { // 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 c189ede404f..f391918b7a4 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 @@ class ContentTranslationMetadataFieldsTest extends ContentTranslationTestBase { $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 e11056f56c5..fe41739bcdb 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 b01f5b5c70c..cb18d8e0bfd 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 97e2f0da6ba..12a726c3db2 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 899083a87cd..fb1f3c18bf6 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 405fa2beea3..48e5f94efe0 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 c499328bd02..014d78a6ddd 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 c8b740e0477..d55e49e786a 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 336bc3b9cb6..ff218d0e6c5 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 @@ class TranslationLinkTest extends ContentTranslationTestBase { $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 4b5999d9030..c52bc8cb347 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 20d3cd8c6e2..9e8538b9fe7 100644 --- a/core/modules/media/tests/src/Functional/MediaTranslationUITest.php +++ b/core/modules/media/tests/src/Functional/MediaTranslationUITest.php @@ -49,6 +49,7 @@ class MediaTranslationUITest extends ContentTranslationUITestBase { $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 e8ab747f60c..c711b8668b0 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 @@ class MenuLinkContentTranslationUITest extends ContentTranslationUITestBase { $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 004fab2e56b..b4ea93b0cf7 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 @@ use Drupal\node\Entity\Node; 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 @@ class NodeTranslationUITest extends ContentTranslationUITestBase { $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 @@ class NodeTranslationUITest extends ContentTranslationUITestBase { $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 @@ class NodeTranslationUITest extends ContentTranslationUITestBase { * 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 @@ class NodeTranslationUITest extends ContentTranslationUITestBase { * 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 @@ class NodeTranslationUITest extends ContentTranslationUITestBase { $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 0418d807923..c1271e499b3 100644 --- a/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php +++ b/core/modules/shortcut/tests/src/Functional/ShortcutTranslationUITest.php @@ -43,6 +43,7 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase { $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 2b4ad75364e..35ff9301e09 100644 --- a/core/modules/taxonomy/tests/src/Functional/TermTranslationUITest.php +++ b/core/modules/taxonomy/tests/src/Functional/TermTranslationUITest.php @@ -50,6 +50,7 @@ class TermTranslationUITest extends ContentTranslationUITestBase { $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 a1220381cc3..34dfc2ddae3 100644 --- a/core/modules/user/tests/src/Functional/UserTranslationUITest.php +++ b/core/modules/user/tests/src/Functional/UserTranslationUITest.php @@ -54,6 +54,7 @@ class UserTranslationUITest extends ContentTranslationUITestBase { $this->testLanguageSelector = FALSE; $this->name = $this->randomMachineName(); parent::setUp(); + $this->doSetup(); \Drupal::entityTypeManager()->getStorage('user')->resetCache(); }