annotate core/tests/Drupal/Tests/RequirementsPageTrait.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@18 1 <?php
Chris@18 2
Chris@18 3 namespace Drupal\Tests;
Chris@18 4
Chris@18 5 /**
Chris@18 6 * Provides helper methods for the requirements page.
Chris@18 7 */
Chris@18 8 trait RequirementsPageTrait {
Chris@18 9
Chris@18 10 /**
Chris@18 11 * Handles the update requirements page.
Chris@18 12 */
Chris@18 13 protected function updateRequirementsProblem() {
Chris@18 14 // Assert a warning is shown on older test environments.
Chris@18 15 if (version_compare(phpversion(), DRUPAL_MINIMUM_SUPPORTED_PHP) < 0) {
Chris@18 16 $this->assertNoText('Errors found');
Chris@18 17 $this->assertWarningSummaries(['PHP']);
Chris@18 18 $this->clickLink('try again');
Chris@18 19 $this->checkForMetaRefresh();
Chris@18 20 }
Chris@18 21 }
Chris@18 22
Chris@18 23 /**
Chris@18 24 * Continues installation when the expected warnings are found.
Chris@18 25 *
Chris@18 26 * This function is no longer called by any core test, but it is retained for
Chris@18 27 * use by contrib/custom tests. It is not deprecated, because it remains the
Chris@18 28 * recommended function to call for its purpose.
Chris@18 29 *
Chris@18 30 * @param string[] $expected_warnings
Chris@18 31 * A list of warning summaries to expect on the requirements screen (e.g.
Chris@18 32 * 'PHP', 'PHP OPcode caching', etc.). If only the expected warnings
Chris@18 33 * are found, the test will click the "continue anyway" link to go to the
Chris@18 34 * next screen of the installer. If an expected warning is not found, or if
Chris@18 35 * a warning not in the list is present, a fail is raised.
Chris@18 36 */
Chris@18 37 protected function continueOnExpectedWarnings($expected_warnings = []) {
Chris@18 38 $this->assertNoText('Errors found');
Chris@18 39 $this->assertWarningSummaries($expected_warnings);
Chris@18 40 $this->clickLink('continue anyway');
Chris@18 41 $this->checkForMetaRefresh();
Chris@18 42 }
Chris@18 43
Chris@18 44 /**
Chris@18 45 * Assert the given warning summaries are present on the page.
Chris@18 46 *
Chris@18 47 * If an expected warning is not found, or if a warning not in the list is
Chris@18 48 * present, a fail is raised.
Chris@18 49 *
Chris@18 50 * @param string[] $warning_summaries
Chris@18 51 * A list of warning summaries to expect on the requirements screen (e.g.
Chris@18 52 * 'PHP', 'PHP OPcode caching', etc.).
Chris@18 53 */
Chris@18 54 protected function assertWarningSummaries(array $warning_summaries) {
Chris@18 55 // Allow only details elements that are directly after the warning header
Chris@18 56 // or each other. There is no guaranteed wrapper we can rely on across
Chris@18 57 // distributions. When there are multiple warnings, the selectors will be:
Chris@18 58 // - h3#warning+details summary
Chris@18 59 // - h3#warning+details+details summary
Chris@18 60 // - etc.
Chris@18 61 // We add one more selector than expected warnings to confirm that there
Chris@18 62 // isn't any other warning before clicking the link.
Chris@18 63 // @todo Make this more reliable in
Chris@18 64 // https://www.drupal.org/project/drupal/issues/2927345.
Chris@18 65 $selectors = [];
Chris@18 66 for ($i = 0; $i <= count($warning_summaries); $i++) {
Chris@18 67 $selectors[] = 'h3#warning' . implode('', array_fill(0, $i + 1, '+details')) . ' summary';
Chris@18 68 }
Chris@18 69 $warning_elements = $this->cssSelect(implode(', ', $selectors));
Chris@18 70
Chris@18 71 // Confirm that there are only the expected warnings.
Chris@18 72 $warnings = [];
Chris@18 73 foreach ($warning_elements as $warning) {
Chris@18 74 $warnings[] = trim($warning->getText());
Chris@18 75 }
Chris@18 76 $this->assertEquals($warning_summaries, $warnings);
Chris@18 77 }
Chris@18 78
Chris@18 79 }