diff --git a/core/modules/locale/tests/src/Functional/LocaleTranslatedSchemaDefinitionTest.php b/core/modules/locale/tests/src/Functional/LocaleTranslatedSchemaDefinitionTest.php index 3146acb..646eb4f 100644 --- a/core/modules/locale/tests/src/Functional/LocaleTranslatedSchemaDefinitionTest.php +++ b/core/modules/locale/tests/src/Functional/LocaleTranslatedSchemaDefinitionTest.php @@ -4,7 +4,7 @@ use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\BrowserTestBase; -use Drupal\Tests\UpdateUiTrait; +use Drupal\Tests\RequirementsPageTrait; /** * Adds and configures languages to check field schema definition. @@ -13,7 +13,7 @@ */ class LocaleTranslatedSchemaDefinitionTest extends BrowserTestBase { - use UpdateUiTrait; + use RequirementsPageTrait; /** * Modules to enable. @@ -86,7 +86,7 @@ public function testTranslatedUpdate() { // markup and a link instead of specific text because text may be // translated. $this->drupalGet($update_url . '/selection', ['external' => TRUE]); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->drupalGet($update_url . '/selection', ['external' => TRUE]); $this->assertRaw('messages--status', 'No pending updates.'); $this->assertNoLinkByHref('fr/update.php/run', 'No link to run updates.'); diff --git a/core/modules/system/tests/src/Functional/Update/DbUpdatesTrait.php b/core/modules/system/tests/src/Functional/Update/DbUpdatesTrait.php index e3aab95..938b60a 100644 --- a/core/modules/system/tests/src/Functional/Update/DbUpdatesTrait.php +++ b/core/modules/system/tests/src/Functional/Update/DbUpdatesTrait.php @@ -4,7 +4,7 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; -use Drupal\Tests\UpdateUiTrait; +use Drupal\Tests\RequirementsPageTrait; /** * Provides methods to conditionally enable db update functions and apply @@ -15,7 +15,7 @@ trait DbUpdatesTrait { use StringTranslationTrait; - use UpdateUiTrait; + use RequirementsPageTrait; /** * Enables db updates until the specified index. @@ -36,7 +36,7 @@ protected function enableUpdates($module, $group, $index) { */ protected function applyUpdates() { $this->drupalGet(Url::fromRoute('system.db_update')); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->clickLink($this->t('Continue')); $this->clickLink($this->t('Apply pending updates')); $this->checkForMetaRefresh(); diff --git a/core/modules/system/tests/src/Functional/Update/InvalidUpdateHookTest.php b/core/modules/system/tests/src/Functional/Update/InvalidUpdateHookTest.php index 424ca63..3e37d68 100644 --- a/core/modules/system/tests/src/Functional/Update/InvalidUpdateHookTest.php +++ b/core/modules/system/tests/src/Functional/Update/InvalidUpdateHookTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\system\Functional\Update; use Drupal\Tests\BrowserTestBase; -use Drupal\Tests\UpdateUiTrait; +use Drupal\Tests\RequirementsPageTrait; /** * Tests that a module implementing hook_update_8000() causes an error to be @@ -13,7 +13,7 @@ */ class InvalidUpdateHookTest extends BrowserTestBase { - use UpdateUiTrait; + use RequirementsPageTrait; /** * Modules to enable. @@ -48,7 +48,7 @@ public function testInvalidUpdateHook() { // Confirm that a module with hook_update_8000() cannot be updated. $this->drupalLogin($this->updateUser); $this->drupalGet($this->updateUrl); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->clickLink(t('Continue')); $this->assertText(t('Some of the pending updates cannot be applied because their dependencies were not met.')); } diff --git a/core/modules/system/tests/src/Functional/Update/UpdatePostUpdateTest.php b/core/modules/system/tests/src/Functional/Update/UpdatePostUpdateTest.php index 3e2c46a..f013988 100644 --- a/core/modules/system/tests/src/Functional/Update/UpdatePostUpdateTest.php +++ b/core/modules/system/tests/src/Functional/Update/UpdatePostUpdateTest.php @@ -78,7 +78,7 @@ public function testPostUpdate() { } $this->drupalGet('update.php/selection'); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->drupalGet('update.php/selection'); $this->assertText('No pending updates.'); } diff --git a/core/modules/system/tests/src/Functional/Update/UpdateSchemaTest.php b/core/modules/system/tests/src/Functional/Update/UpdateSchemaTest.php index 26c63ff..9d967c8 100644 --- a/core/modules/system/tests/src/Functional/Update/UpdateSchemaTest.php +++ b/core/modules/system/tests/src/Functional/Update/UpdateSchemaTest.php @@ -5,7 +5,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Url; use Drupal\Tests\BrowserTestBase; -use Drupal\Tests\UpdateUiTrait; +use Drupal\Tests\RequirementsPageTrait; /** * Tests that update hooks are properly run. @@ -14,7 +14,7 @@ */ class UpdateSchemaTest extends BrowserTestBase { - use UpdateUiTrait; + use RequirementsPageTrait; /** * {@inheritdoc} @@ -59,7 +59,7 @@ public function testUpdateHooks() { $this->drupalLogin($this->user); $this->drupalGet($this->updateUrl, ['external' => TRUE]); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->clickLink(t('Continue')); $this->assertRaw('Schema version 8001.'); // Run the update hooks. diff --git a/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php b/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php index a52274e..cc32694 100644 --- a/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php +++ b/core/modules/system/tests/src/Functional/Update/UpdateScriptTest.php @@ -5,7 +5,7 @@ use Drupal\Core\Url; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\Tests\BrowserTestBase; -use Drupal\Tests\UpdateUiTrait; +use Drupal\Tests\RequirementsPageTrait; /** * Tests the update script access and functionality. @@ -14,7 +14,7 @@ */ class UpdateScriptTest extends BrowserTestBase { - use UpdateUiTrait; + use RequirementsPageTrait; /** * Modules to enable. @@ -102,7 +102,7 @@ public function testRequirements() { // If there are no requirements warnings or errors, we expect to be able to // go through the update process uninterrupted. $this->drupalGet($this->updateUrl, ['external' => TRUE]); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->clickLink(t('Continue')); $this->assertText(t('No pending updates.'), 'End of update process was reached.'); // Confirm that all caches were cleared. @@ -182,7 +182,7 @@ public function testNoUpdateFunctionality() { // Click through update.php with 'administer software updates' permission. $this->drupalLogin($this->updateUser); $this->drupalGet($this->updateUrl, ['external' => TRUE]); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->clickLink(t('Continue')); $this->assertText(t('No pending updates.')); $this->assertNoLink('Administration pages'); @@ -194,7 +194,7 @@ public function testNoUpdateFunctionality() { $admin_user = $this->drupalCreateUser(['administer software updates', 'access administration pages']); $this->drupalLogin($admin_user); $this->drupalGet($this->updateUrl, ['external' => TRUE]); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->clickLink(t('Continue')); $this->assertText(t('No pending updates.')); $this->assertLink('Administration pages'); @@ -227,7 +227,7 @@ public function testSuccessfulUpdateFunctionality() { $admin_user = $this->drupalCreateUser(['administer software updates', 'access administration pages', 'access site reports', 'access site in maintenance mode']); $this->drupalLogin($admin_user); $this->drupalGet($this->updateUrl, ['external' => TRUE]); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->clickLink(t('Continue')); $this->clickLink(t('Apply pending updates')); $this->checkForMetaRefresh(); @@ -295,7 +295,7 @@ public function testSuccessfulMultilingualUpdateFunctionality() { // Click through update.php with 'access administration pages' and // 'access site reports' permissions. $this->drupalGet($this->updateUrl, ['external' => TRUE]); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->clickLink(t('Continue')); $this->clickLink(t('Apply pending updates')); $this->checkForMetaRefresh(); @@ -328,7 +328,7 @@ protected function runUpdates($maintenance_mode) { $this->assertNoText('Operating in maintenance mode.'); } $this->drupalGet($this->updateUrl, ['external' => TRUE]); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->clickLink(t('Continue')); $this->clickLink(t('Apply pending updates')); $this->checkForMetaRefresh(); diff --git a/core/modules/system/tests/src/Functional/Update/UpdatesWith7xTest.php b/core/modules/system/tests/src/Functional/Update/UpdatesWith7xTest.php index ee42bd3..799e939 100644 --- a/core/modules/system/tests/src/Functional/Update/UpdatesWith7xTest.php +++ b/core/modules/system/tests/src/Functional/Update/UpdatesWith7xTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\system\Functional\Update; use Drupal\Tests\BrowserTestBase; -use Drupal\Tests\UpdateUiTrait; +use Drupal\Tests\RequirementsPageTrait; /** * Tests that the minimum schema version is correct even if only 7.x update @@ -13,7 +13,7 @@ */ class UpdatesWith7xTest extends BrowserTestBase { - use UpdateUiTrait; + use RequirementsPageTrait; /** * Modules to enable. @@ -51,7 +51,7 @@ public function testWith7x() { // Click through update.php with 'administer software updates' permission. $this->drupalLogin($this->updateUser); $this->drupalGet($this->updateUrl, ['external' => TRUE]); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->clickLink(t('Continue')); $this->assertText(t('Some of the pending updates cannot be applied because their dependencies were not met.')); } diff --git a/core/profiles/minimal/tests/src/Functional/MinimalTest.php b/core/profiles/minimal/tests/src/Functional/MinimalTest.php index d831e66..64f4a4a 100644 --- a/core/profiles/minimal/tests/src/Functional/MinimalTest.php +++ b/core/profiles/minimal/tests/src/Functional/MinimalTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\minimal\Functional; use Drupal\Tests\BrowserTestBase; -use Drupal\Tests\UpdateUiTrait; +use Drupal\Tests\RequirementsPageTrait; use Drupal\user\UserInterface; /** @@ -13,7 +13,7 @@ */ class MinimalTest extends BrowserTestBase { - use UpdateUiTrait; + use RequirementsPageTrait; protected $profile = 'minimal'; @@ -37,7 +37,7 @@ public function testMinimal() { // Ensure that there are no pending updates after installation. $this->drupalLogin($this->rootUser); $this->drupalGet('update.php/selection'); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->drupalGet('update.php/selection'); $this->assertText('No pending updates.'); diff --git a/core/profiles/standard/tests/src/Functional/StandardTest.php b/core/profiles/standard/tests/src/Functional/StandardTest.php index b1d1251..d6e7c7f 100644 --- a/core/profiles/standard/tests/src/Functional/StandardTest.php +++ b/core/profiles/standard/tests/src/Functional/StandardTest.php @@ -10,7 +10,7 @@ use Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber; use Drupal\filter\Entity\FilterFormat; use Drupal\Tests\BrowserTestBase; -use Drupal\Tests\UpdateUiTrait; +use Drupal\Tests\RequirementsPageTrait; use Drupal\user\Entity\Role; /** @@ -21,7 +21,7 @@ class StandardTest extends BrowserTestBase { use SchemaCheckTestTrait; - use UpdateUiTrait; + use RequirementsPageTrait; protected $profile = 'standard'; @@ -157,7 +157,7 @@ public function testStandard() { // Ensure that there are no pending updates after installation. $this->drupalLogin($this->rootUser); $this->drupalGet('update.php/selection'); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->drupalGet('update.php/selection'); $this->assertText('No pending updates.'); diff --git a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php index d795f6b..7b6d9d6 100644 --- a/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php +++ b/core/tests/Drupal/FunctionalTests/Update/UpdatePathTestBase.php @@ -10,7 +10,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Language\Language; use Drupal\Core\Url; -use Drupal\Tests\UpdateUiTrait; +use Drupal\Tests\RequirementsPageTrait; use Drupal\user\Entity\User; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\Request; @@ -43,7 +43,7 @@ abstract class UpdatePathTestBase extends BrowserTestBase { use SchemaCheckTestTrait; - use UpdateUiTrait; + use RequirementsPageTrait; /** * Modules to enable after the database is loaded. @@ -297,7 +297,7 @@ protected function runUpdates() { ]); $this->drupalGet($this->updateUrl); - $this->updateRequirementsProblem(); + $this->continueOnExpectedWarnings('try again'); $this->clickLink(t('Continue')); $this->doSelectionTest(); diff --git a/core/tests/Drupal/Tests/RequirementsPageTrait.php b/core/tests/Drupal/Tests/RequirementsPageTrait.php new file mode 100644 index 0000000..1181d0c --- /dev/null +++ b/core/tests/Drupal/Tests/RequirementsPageTrait.php @@ -0,0 +1,70 @@ +assertFalse(strpos($this->getTextContent(), 'Errors found')); + $this->assertRequirementWarnings(); + $this->clickLink($link_label); + $this->checkForMetaRefresh(); + } + + /** + * Assert the expected requirement warnings are present on the page. + */ + protected function assertRequirementWarnings() { + // Assert a warning is shown on older test environments. + if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) { + $this->assertWarningSummaries(['PHP']); + } + } + + /** + * Assert the given warning summaries are present on the page. + * + * If an expected warning is not found, or if a warning not in the list is + * present, a fail is raised. + * + * @param string[] $warning_summaries + * A list of warning summaries to expect on the requirements screen (e.g. + * 'PHP', 'PHP OPcode caching', etc.). + */ + protected function assertWarningSummaries(array $warning_summaries) { + // Allow only details elements that are directly after the warning header + // or each other. There is no guaranteed wrapper we can rely on across + // distributions. When there are multiple warnings, the selectors will be: + // - h3#warning+details summary + // - h3#warning+details+details summary + // - etc. + // We add one more selector than expected warnings to confirm that there + // isn't any other warning before clicking the link. + // @todo Make this more reliable in + // https://www.drupal.org/project/drupal/issues/2927345. + $selectors = []; + for ($i = 0; $i <= count($warning_summaries); $i++) { + $selectors[] = 'h3#warning' . implode('', array_fill(0, $i + 1, '+details')) . ' summary'; + } + $warning_elements = $this->cssSelect(implode(', ', $selectors)); + + // Confirm that there are only the expected warnings. + $warnings = []; + foreach ($warning_elements as $warning) { + $warnings[] = trim($warning->getText()); + } + $this->assertEquals($warning_summaries, $warnings); + } + +} diff --git a/core/tests/Drupal/Tests/UpdateUiTrait.php b/core/tests/Drupal/Tests/UpdateUiTrait.php deleted file mode 100644 index a74b4b8..0000000 --- a/core/tests/Drupal/Tests/UpdateUiTrait.php +++ /dev/null @@ -1,61 +0,0 @@ -continueOnExpectedWarnings(['PHP']); - } - } - - /** - * Continues update when an expected warning is found. - * - * @param string[] $expected_warnings - * A list of warning summaries to expect on the requirements screen (e.g. - * 'PHP', 'PHP OPcode caching', etc.). If only the expected warnings - * are found, the test will click the "try again" link to go to the - * next screen of the update. If an expected warning is not found, or if - * a warning not in the list is present, a fail is raised. - */ - protected function continueOnExpectedWarnings($expected_warnings = []) { - // Don't try to continue if there are errors. - if (strpos($this->getTextContent(), 'Errors found') !== FALSE) { - return; - } - // Allow only details elements that are directly after the warning header - // or each other. There is no guaranteed wrapper we can rely on across - // distributions. When there are multiple warnings, the selectors will be: - // - h3#warning+details summary - // - h3#warning+details+details summary - // - etc. - // We add one more selector than expected warnings to confirm that there - // isn't any other warning before clicking the link. - // @todo Make this more reliable in - // https://www.drupal.org/project/drupal/issues/2927345. - $selectors = []; - for ($i = 0; $i <= count($expected_warnings); $i++) { - $selectors[] = 'h3#warning' . implode('', array_fill(0, $i + 1, '+details')) . ' summary'; - } - $warning_elements = $this->cssSelect(implode(', ', $selectors)); - - // Confirm that there are only the expected warnings. - $warnings = []; - foreach ($warning_elements as $warning) { - $warnings[] = trim($warning->getText()); - } - $this->assertEquals($expected_warnings, $warnings); - $this->clickLink('try again'); - $this->checkForMetaRefresh(); - } - -}