From 9e76aa57ca828d43b913503329d91a302e24bd6f Mon Sep 17 00:00:00 2001 From: quietone Date: Thu, 5 Sep 2024 13:36:58 +1200 Subject: [PATCH] Issue #3439833 by pooja_sharma, smustgrave, vensires: Fix Content Translation tests that rely on UID1's super user behavior --- .../ContentTranslationEnableTest.php | 19 +++++++++++-------- ...ewTranslationWithExistingRevisionsTest.php | 8 -------- ...slationOutdatedRevisionTranslationTest.php | 8 -------- ...tentTranslationPendingRevisionTestBase.php | 5 +++++ ...slationRevisionTranslationDeletionTest.php | 8 -------- ...entTranslationUntranslatableFieldsTest.php | 8 -------- 6 files changed, 16 insertions(+), 40 deletions(-) diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationEnableTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationEnableTest.php index 097cd05a58a..edbbfe990fa 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationEnableTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationEnableTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Drupal\Tests\content_translation\Functional; use Drupal\Tests\BrowserTestBase; +use Drupal\user\Entity\Role; /** * Test enabling content translation module. @@ -20,14 +21,6 @@ class ContentTranslationEnableTest extends BrowserTestBase { */ protected static $modules = ['entity_test', 'menu_link_content', 'node']; - /** - * {@inheritdoc} - * - * @todo Remove and fix test to not rely on super user. - * @see https://www.drupal.org/project/drupal/issues/3437620 - */ - protected bool $usesSuperUserAccessPolicy = TRUE; - /** * {@inheritdoc} */ @@ -37,6 +30,11 @@ class ContentTranslationEnableTest extends BrowserTestBase { * Tests that entity schemas are up-to-date after enabling translation. */ public function testEnable(): void { + $this->rootUser = $this->drupalCreateUser([ + 'administer modules', + 'administer site configuration', + 'administer content types', + ]); $this->drupalLogin($this->rootUser); // Enable modules and make sure the related config entity type definitions // are installed. @@ -46,6 +44,7 @@ class ContentTranslationEnableTest extends BrowserTestBase { ]; $this->drupalGet('admin/modules'); $this->submitForm($edit, 'Install'); + $this->rebuildContainer(); // Status messages are shown. $this->assertSession()->statusMessageContains('This site has only a single language enabled. Add at least one more language in order to translate content.', 'warning'); @@ -55,6 +54,10 @@ class ContentTranslationEnableTest extends BrowserTestBase { $this->drupalGet('admin/reports/status'); $this->assertSession()->elementTextEquals('css', "details.system-status-report__entry summary:contains('Entity/field definitions') + div", 'Up to date'); + $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID), [ + 'administer content translation', + 'administer languages', + ]); $this->drupalGet('admin/config/regional/content-language'); // The node entity type should not be an option because it has no bundles. $this->assertSession()->responseNotContains('entity_types[node]'); diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationNewTranslationWithExistingRevisionsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationNewTranslationWithExistingRevisionsTest.php index 7a8955a262e..65f0c5ed4dc 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationNewTranslationWithExistingRevisionsTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationNewTranslationWithExistingRevisionsTest.php @@ -25,14 +25,6 @@ class ContentTranslationNewTranslationWithExistingRevisionsTest extends ContentT 'node', ]; - /** - * {@inheritdoc} - * - * @todo Remove and fix test to not rely on super user. - * @see https://www.drupal.org/project/drupal/issues/3437620 - */ - protected bool $usesSuperUserAccessPolicy = TRUE; - /** * {@inheritdoc} */ diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php index 96726c68756..731ffd374c7 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationOutdatedRevisionTranslationTest.php @@ -14,14 +14,6 @@ use Drupal\language\Entity\ConfigurableLanguage; */ class ContentTranslationOutdatedRevisionTranslationTest extends ContentTranslationPendingRevisionTestBase { - /** - * {@inheritdoc} - * - * @todo Remove and fix test to not rely on super user. - * @see https://www.drupal.org/project/drupal/issues/3437620 - */ - protected bool $usesSuperUserAccessPolicy = TRUE; - /** * {@inheritdoc} */ diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationPendingRevisionTestBase.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationPendingRevisionTestBase.php index cd31802a13f..24fd851abea 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationPendingRevisionTestBase.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationPendingRevisionTestBase.php @@ -79,6 +79,11 @@ abstract class ContentTranslationPendingRevisionTestBase extends ContentTranslat * Enables content moderation for the test entity type and bundle. */ protected function enableContentModeration() { + $perms = array_merge(parent::getAdministratorPermissions(), [ + 'administer workflows', + 'view latest version', + ]); + $this->rootUser = $this->drupalCreateUser($perms); $this->drupalLogin($this->rootUser); $workflow_id = 'editorial'; $this->drupalGet('/admin/config/workflow/workflows'); diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationRevisionTranslationDeletionTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationRevisionTranslationDeletionTest.php index 8ecd28de8fe..3e123a5ca4f 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationRevisionTranslationDeletionTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationRevisionTranslationDeletionTest.php @@ -14,14 +14,6 @@ use Drupal\language\Entity\ConfigurableLanguage; */ class ContentTranslationRevisionTranslationDeletionTest extends ContentTranslationPendingRevisionTestBase { - /** - * {@inheritdoc} - * - * @todo Remove and fix test to not rely on super user. - * @see https://www.drupal.org/project/drupal/issues/3437620 - */ - protected bool $usesSuperUserAccessPolicy = TRUE; - /** * {@inheritdoc} */ diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php index d0b8a15e1f8..02945baf525 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php @@ -24,14 +24,6 @@ class ContentTranslationUntranslatableFieldsTest extends ContentTranslationPendi */ protected static $modules = ['field_test']; - /** - * {@inheritdoc} - * - * @todo Remove and fix test to not rely on super user. - * @see https://www.drupal.org/project/drupal/issues/3437620 - */ - protected bool $usesSuperUserAccessPolicy = TRUE; - /** * {@inheritdoc} */