View source
<?php
namespace Drupal\Tests\automatic_updates\Functional;
use Drupal\automatic_updates\AutomaticUpdatesEvents;
use Drupal\automatic_updates\Exception\UpdateException;
use Drupal\automatic_updates\Validation\ValidationResult;
use Drupal\automatic_updates_test\ReadinessChecker\TestChecker1;
use Drupal\Tests\automatic_updates\Traits\ValidationTestTrait;
class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
use ValidationTestTrait;
protected $defaultTheme = 'stark';
protected static $modules = [
'block',
'automatic_updates',
'automatic_updates_test',
'package_manager_bypass',
];
protected function setUp() : void {
parent::setUp();
$this
->setReleaseMetadata(__DIR__ . '/../../fixtures/release-history/drupal.9.8.1-security.xml');
$this
->drupalLogin($this->rootUser);
$this
->checkForUpdates();
}
public function providerUpdateFormReferringUrl() : array {
return [
'Modules page' => [
'/admin/modules/automatic-update',
],
'Reports page' => [
'/admin/reports/updates/automatic-update',
],
];
}
public function providerTableLooksCorrect() : array {
return [
'Modules page' => [
'modules',
],
'Reports page' => [
'reports',
],
];
}
public function testFormNotDisplayedIfAlreadyCurrent(string $update_form_url) : void {
$this
->setCoreVersion('9.8.1');
$this
->checkForUpdates();
$this
->drupalGet($update_form_url);
$assert_session = $this
->assertSession();
$assert_session
->statusCodeEquals(200);
$assert_session
->pageTextContains('No update available');
$assert_session
->buttonNotExists('Update');
}
public function testTableLooksCorrect(string $access_page) : void {
$this
->drupalPlaceBlock('local_tasks_block', [
'primary' => TRUE,
]);
$assert_session = $this
->assertSession();
$this
->setCoreVersion('9.8.0');
$this
->checkForUpdates();
$this
->drupalGet('/admin');
if ($access_page === 'modules') {
$this
->clickLink('Extend');
$assert_session
->pageTextContainsOnce('There is a security update available for your version of Drupal.');
}
else {
$this
->clickLink('Reports');
$assert_session
->pageTextContainsOnce('There is a security update available for your version of Drupal.');
$this
->clickLink('Available updates');
}
$this
->clickLink('Update');
$assert_session
->pageTextNotContains('There is a security update available for your version of Drupal.');
$cells = $assert_session
->elementExists('css', '#edit-projects .update-update-security')
->findAll('css', 'td');
$this
->assertCount(3, $cells);
$assert_session
->elementExists('named', [
'link',
'Drupal',
], $cells[0]);
$this
->assertSame('9.8.0', $cells[1]
->getText());
$this
->assertSame('9.8.1 (Release notes)', $cells[2]
->getText());
$release_notes = $assert_session
->elementExists('named', [
'link',
'Release notes',
], $cells[2]);
$this
->assertSame('Release notes for Drupal', $release_notes
->getAttribute('title'));
$assert_session
->buttonExists('Update');
}
public function testUpdateErrors() : void {
$session = $this
->getSession();
$assert_session = $this
->assertSession();
$page = $session
->getPage();
$message = t("You've not experienced Shakespeare until you have read him in the original Klingon.");
$error = ValidationResult::createError([
$message,
]);
TestChecker1::setTestResult([
$error,
]);
$this
->drupalGet('/admin/reports/status');
$page
->clickLink('Run readiness checks');
$assert_session
->pageTextContainsOnce((string) $message);
$session
->reload();
$assert_session
->pageTextContainsOnce((string) $message);
$this
->setCoreVersion('9.8.0');
$this
->checkForUpdates();
$this
->createTestValidationResults();
$expected_results = $this->testResults['checker_1']['1 error'];
TestChecker1::setTestResult($expected_results);
$this
->drupalGet('/admin/modules/automatic-update');
$assert_session
->buttonNotExists('Update');
$assert_session
->pageTextContainsOnce((string) $expected_results[0]
->getMessages()[0]);
$assert_session
->pageTextContainsOnce(static::$errorsExplanation);
$assert_session
->pageTextNotContains(static::$warningsExplanation);
$assert_session
->pageTextNotContains((string) $message);
TestChecker1::setTestResult(NULL);
$error = new UpdateException($expected_results, 'The update exploded.');
TestChecker1::setTestResult($error, AutomaticUpdatesEvents::PRE_START);
$session
->reload();
$assert_session
->pageTextNotContains(static::$errorsExplanation);
$assert_session
->pageTextNotContains(static::$warningsExplanation);
$page
->pressButton('Update');
$this
->checkForMetaRefresh();
$assert_session
->pageTextContainsOnce('An error has occurred.');
$page
->clickLink('the error page');
$assert_session
->pageTextContainsOnce((string) $expected_results[0]
->getMessages()[0]);
$assert_session
->pageTextNotContains($expected_results[0]
->getSummary());
$assert_session
->pageTextContainsOnce('The update exploded.');
TestChecker1::setTestResult($expected_results, AutomaticUpdatesEvents::PRE_START);
$this
->deleteStagedUpdate();
$page
->pressButton('Update');
$this
->checkForMetaRefresh();
$assert_session
->pageTextContainsOnce('An error has occurred.');
$page
->clickLink('the error page');
$assert_session
->pageTextNotContains($expected_results[0]
->getSummary());
$assert_session
->pageTextContainsOnce((string) $expected_results[0]
->getMessages()[0]);
$expected_results = $this->testResults['checker_1']['1 warning'];
TestChecker1::setTestResult($expected_results, AutomaticUpdatesEvents::PRE_START);
$session
->reload();
$this
->deleteStagedUpdate();
$page
->pressButton('Update');
$this
->checkForMetaRefresh();
$assert_session
->pageTextContains('Ready to update');
}
public function testMinorVersionUpdateNotSupported(string $update_form_url) : void {
$this
->setCoreVersion('9.7.1');
$this
->drupalGet($update_form_url);
$assert_session = $this
->assertSession();
$assert_session
->pageTextContainsOnce('Updating from one minor version to another is not supported.');
$assert_session
->buttonNotExists('Update');
}
private function deleteStagedUpdate() : void {
$session = $this
->getSession();
$session
->getPage()
->pressButton('Delete existing update');
$this
->assertSession()
->pageTextContains('Staged update deleted');
$session
->reload();
}
}