comparison core/tests/Drupal/FunctionalTests/Installer/InstallerTestBase.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents a9cd425dd02b
children
comparison
equal deleted inserted replaced
4:a9cd425dd02b 5:12f9dff5fda9
6 use Drupal\Core\Language\Language; 6 use Drupal\Core\Language\Language;
7 use Drupal\Core\Session\UserSession; 7 use Drupal\Core\Session\UserSession;
8 use Drupal\Core\Site\Settings; 8 use Drupal\Core\Site\Settings;
9 use Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware; 9 use Drupal\Core\Test\HttpClientMiddleware\TestHttpClientMiddleware;
10 use Drupal\Tests\BrowserTestBase; 10 use Drupal\Tests\BrowserTestBase;
11 use Drupal\Tests\RequirementsPageTrait;
11 use GuzzleHttp\HandlerStack; 12 use GuzzleHttp\HandlerStack;
12 use Symfony\Component\DependencyInjection\ContainerBuilder; 13 use Symfony\Component\DependencyInjection\ContainerBuilder;
13 use Symfony\Component\DependencyInjection\Reference; 14 use Symfony\Component\DependencyInjection\Reference;
14 use Symfony\Component\HttpFoundation\Request; 15 use Symfony\Component\HttpFoundation\Request;
15 use Symfony\Component\HttpFoundation\RequestStack; 16 use Symfony\Component\HttpFoundation\RequestStack;
16 17
17 /** 18 /**
18 * Base class for testing the interactive installer. 19 * Base class for testing the interactive installer.
19 */ 20 */
20 abstract class InstallerTestBase extends BrowserTestBase { 21 abstract class InstallerTestBase extends BrowserTestBase {
22
23 use RequirementsPageTrait;
21 24
22 /** 25 /**
23 * Custom settings.php values to write for a test run. 26 * Custom settings.php values to write for a test run.
24 * 27 *
25 * @var array 28 * @var array
242 * during the installer. 245 * during the installer.
243 * 246 *
244 * @see system_requirements() 247 * @see system_requirements()
245 */ 248 */
246 protected function setUpRequirementsProblem() { 249 protected function setUpRequirementsProblem() {
247 // By default, skip the "recommended PHP version" warning on older test 250 // Do nothing.
248 // environments. This allows the installer to be tested consistently on
249 // both recommended PHP versions and older (but still supported) versions.
250 if (version_compare(phpversion(), '7.0') < 0) {
251 $this->continueOnExpectedWarnings(['PHP']);
252 }
253 } 251 }
254 252
255 /** 253 /**
256 * Final installer step: Configure site. 254 * Final installer step: Configure site.
257 */ 255 */
273 if ($this->isInstalled) { 271 if ($this->isInstalled) {
274 parent::refreshVariables(); 272 parent::refreshVariables();
275 } 273 }
276 } 274 }
277 275
278 /**
279 * Continues installation when an expected warning is found.
280 *
281 * @param string[] $expected_warnings
282 * A list of warning summaries to expect on the requirements screen (e.g.
283 * 'PHP', 'PHP OPcode caching', etc.). If only the expected warnings
284 * are found, the test will click the "continue anyway" link to go to the
285 * next screen of the installer. If an expected warning is not found, or if
286 * a warning not in the list is present, a fail is raised.
287 */
288 protected function continueOnExpectedWarnings($expected_warnings = []) {
289 // Don't try to continue if there are errors.
290 if (strpos($this->getTextContent(), 'Errors found') !== FALSE) {
291 return;
292 }
293 // Allow only details elements that are directly after the warning header
294 // or each other. There is no guaranteed wrapper we can rely on across
295 // distributions. When there are multiple warnings, the selectors will be:
296 // - h3#warning+details summary
297 // - h3#warning+details+details summary
298 // - etc.
299 // We add one more selector than expected warnings to confirm that there
300 // isn't any other warning before clicking the link.
301 // @todo Make this more reliable in
302 // https://www.drupal.org/project/drupal/issues/2927345.
303 $selectors = [];
304 for ($i = 0; $i <= count($expected_warnings); $i++) {
305 $selectors[] = 'h3#warning' . implode('', array_fill(0, $i + 1, '+details')) . ' summary';
306 }
307 $warning_elements = $this->cssSelect(implode(', ', $selectors));
308
309 // Confirm that there are only the expected warnings.
310 $warnings = [];
311 foreach ($warning_elements as $warning) {
312 $warnings[] = trim($warning->getText());
313 }
314 $this->assertEquals($expected_warnings, $warnings);
315 $this->clickLink('continue anyway');
316 $this->checkForMetaRefresh();
317 }
318
319 } 276 }