$this->drupalLogin($this->updateUser); $update_script_test_config->set('requirement_type', REQUIREMENT_WARNING)->save(); /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */ $update_registry = \Drupal::service('update.update_hook_registry'); $update_registry->setInstalledVersion('update_script_test', $update_registry->getInstalledVersion('update_script_test') - 1); $this->drupalGet($this->updateUrl, ['external' => TRUE]); $this->assertSession()->pageTextContains('This is a requirements warning provided by the update_script_test module.'); $this->clickLink('try again'); $this->assertSession()->pageTextNotContains('This is a requirements warning provided by the update_script_test module.'); $this->clickLink('Continue'); $this->clickLink('Apply pending updates'); $this->checkForMetaRefresh(); $this->assertSession()->pageTextContains('The update_script_test_update_8001() update was executed successfully.'); // Confirm that all caches were cleared.
$this->assertSession()->pageTextContains('hook_cache_flush() invoked for update_script_test.module.');
// Now try again without pending updates to make sure that works too.
$this->drupalGet($this->updateUrl, ['external' => TRUE]); $this->assertSession()->pageTextContains('This is a requirements warning provided by the update_script_test module.'); $this->clickLink('try again'); $this->assertSession()->pageTextNotContains('This is a requirements warning provided by the update_script_test module.'); $this->clickLink('Continue'); $this->assertSession()->pageTextContains('No pending updates.');
publicfunctiontestCheckForMetaRefresh(){ // Disable following redirects in the client.
$this->getSession()->getDriver()->getClient()->followRedirects(FALSE); // Set the maximumMetaRefreshCount to zero to make sure the redirect doesn't
// happen when doing a drupalGet.
$this->maximumMetaRefreshCount = 0; $this->drupalGet('test-meta-refresh'); $this->assertNotEmpty($this->cssSelect('meta[http-equiv="refresh"]')); // Allow one redirect to happen.
$this->maximumMetaRefreshCount = 1; $this->checkForMetaRefresh(); // Check that we are now on the test page.
$this->assertSession()->pageTextContains('Test page text.'); }
// Ensure that any changes to variables in the other thread are picked up.
$this->refreshVariables();
// Replace original page output with new output from redirected page(s).
if($new = $this->checkForMetaRefresh()){ $out = $new; // We are finished with all meta refresh redirects, so reset the counter.
$this->metaRefreshCount = 0; }
// Log only for WebDriverTestBase tests because for DrupalTestBrowser we log
// with ::getResponseLogHandler.
if($this->htmlOutputEnabled && !$this->isTestUsingGuzzleClient()){ $html_output = 'GET request to: ' . $url . '<hr />Ending URL: ' . $this->getSession()->getCurrentUrl(); $html_output .= '<hr />' . $out;
/**
* Performs a single <meta> refresh explicitly.
*
* This test disables the automatic <meta> refresh checking, each time it is
* desired that this runs, a test case must explicitly call this.
*
* @see setUp()
*/ protectedfunctionperformMetaRefresh(){ $this->maximumMetaRefreshCount = 1; $this->checkForMetaRefresh(); $this->maximumMetaRefreshCount = 0; $this->metaRefreshCount = 0; }
$this->doSelectionTest(); // Run the update hooks.
$this->clickLink('Apply pending updates'); $this->checkForMetaRefresh();
// Ensure there are no failed updates.
if($this->checkFailedUpdates){ $failure = $this->cssSelect('.failure'); if($failure){ $this->fail('The update failed with the following message: "' . reset($failure)->getText() . '"'); }
// Ensure that there are no pending updates.
foreach(['update', 'post_update']as$update_type){ switch($update_type){
$this->setProjectInstalledVersion('8.0.0'); // Instead of using refreshUpdateStatus(), set these manually.
$this->config('update.settings') ->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString()) ->save(); $this->config('update_test.settings') ->set('xml_map', ['drupal' => '0.0']) ->save();
/**
* Checks the messages at admin/modules when an update is missing.
*/ publicfunctiontestModulePageRegularUpdate(){ $this->drupalLogin($this->drupalCreateUser([
// Increment the schema version.
\Drupal::state()->set('update_test_schema_version', 8001);
// Ensure schema has changed.
$this->resetAll(); /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */ $update_registry = \Drupal::service('update.update_hook_registry'); $this->assertEquals(8001, $update_registry->getInstalledVersion('update_test_schema')); // Ensure the index was added for column a.
$this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.'); }
// Ensure that any changes to variables in the other thread are picked up.
$this->refreshVariables();
// Check if there are any meta refresh redirects (like Batch API pages).
if($this->checkForMetaRefresh()){ // We are finished with all meta refresh redirects, so reset the counter.
$this->metaRefreshCount = 0; }
// Log only for WebDriverTestBase tests because for tests using
// DrupalTestBrowser we log with ::getResponseLogHandler.
if($this->htmlOutputEnabled && !$this->isTestUsingGuzzleClient()){ $out = $this->getSession()->getPage()->getContent(); $html_output = 'POST request to: ' . $action . '<hr />Ending URL: ' . $this->getSession()->getCurrentUrl(); $html_output .= '<hr />' . $out;
protectedfunctionrefreshUpdateStatus($xml_map, $url = 'update-test'){ // Tell the Update Manager module to fetch from the URL provided by
// update_test module.
$this->config('update.settings')->set('fetch.url', Url::fromUri('base:' . $url, ['absolute' => TRUE])->toString())->save(); // Save the map for UpdateTestController::updateTest() to use.
$this->config('update_test.settings')->set('xml_map', $xml_map)->save(); // Manually check the update status.
$this->drupalGet('admin/reports/updates'); $this->clickLink('Check manually'); $this->checkForMetaRefresh(); }
protectedfunctionupdateRequirementsProblem(){ // Assert a warning is shown on older test environments.
$links = $this->getSession()->getPage()->findAll('named', ['link', 'try again']);
/**
* Continues installation when the expected warnings are 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 "continue anyway" link to go to the
* next screen of the installer. If an expected warning is not found, or if
* a warning not in the list is present, a fail is raised.
*/