From 2435612664c035a4179efae3b7dd8a6a01a30db8 Mon Sep 17 00:00:00 2001 From: lucashedding <lucashedding@1463982.no-reply.drupal.org> Date: Tue, 14 Apr 2020 16:22:52 -0600 Subject: [PATCH] Issue #3126755 by heddn: Fix failing tests on 8.9.0-beta2 --- src/Form/SettingsForm.php | 3 +- .../src/Controller/JsonTestController.php | 18 ----- tests/src/Build/InPlaceUpdateTest.php | 67 ++----------------- tests/src/Build/ModifiedFilesTest.php | 37 +--------- .../Build/QuickStart/QuickStartTestBase.php | 65 ++++++++++++++++++ tests/src/Functional/AutomaticUpdatesTest.php | 6 +- tests/src/Functional/NotifyTest.php | 2 +- 7 files changed, 75 insertions(+), 123 deletions(-) diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php index 8e14652bee..43005c01fb 100644 --- a/src/Form/SettingsForm.php +++ b/src/Form/SettingsForm.php @@ -172,7 +172,7 @@ class SettingsForm extends ConfigFormBase { $update_text = $this->t('Your site is running %version of Drupal core. No recommended update is available at this time.</i>', ['%version' => \Drupal::VERSION]); if ($not_recommended_version && $not_dev_core) { - $update_text = $this->t('Even with all that caution, if you want to try it out, <a href="@link">manually update now</a>.', [ + $update_text = $this->t('A newer version of Drupal is available and you may <a href="@link">manually update now</a>.', [ '@link' => Url::fromRoute('automatic_updates.inplace-update', [ 'project' => 'drupal', 'type' => 'core', @@ -183,7 +183,6 @@ class SettingsForm extends ConfigFormBase { } $form['experimental']['update'] = [ - '#prefix' => 'This module does not have a stable release and it is recommended to not use these features on a live website. Use at your own risk.', '#type' => 'html_tag', '#tag' => 'p', '#value' => $update_text, diff --git a/tests/modules/test_automatic_updates/src/Controller/JsonTestController.php b/tests/modules/test_automatic_updates/src/Controller/JsonTestController.php index b646680580..7f4b91edd9 100644 --- a/tests/modules/test_automatic_updates/src/Controller/JsonTestController.php +++ b/tests/modules/test_automatic_updates/src/Controller/JsonTestController.php @@ -52,24 +52,6 @@ class JsonTestController extends ControllerBase { 'insecure' => [], 'pubDate' => 'Tue, 19 Feb 2019 14:11:01 +0000', ]; - $feed[] = [ - 'title' => 'Node - Moderately critical - Access bypass - SA-CONTRIB-2019', - 'link' => 'https://www.drupal.org/sa-contrib-2019', - 'project' => 'node', - 'type' => 'module', - 'is_psa' => '0', - 'insecure' => ['7.x-7.22', '8.x-8.2.0'], - 'pubDate' => 'Tue, 19 Mar 2019 12:50:00 +0000', - ]; - $feed[] = [ - 'title' => 'Standard - Moderately critical - Access bypass - SA-CONTRIB-2019', - 'link' => 'https://www.drupal.org/sa-contrib-2019', - 'project' => 'standard', - 'type' => 'profile', - 'insecure' => ['8.x-8.6.13', '8.x-' . \Drupal::VERSION], - 'is_psa' => '0', - 'pubDate' => 'Tue, 19 Mar 2019 12:50:00 +0000', - ]; $feed[] = [ 'title' => 'Seven - Moderately critical - Access bypass - SA-CONTRIB-2019', 'link' => 'https://www.drupal.org/sa-contrib-2019', diff --git a/tests/src/Build/InPlaceUpdateTest.php b/tests/src/Build/InPlaceUpdateTest.php index 5c52988022..b241f41d6a 100644 --- a/tests/src/Build/InPlaceUpdateTest.php +++ b/tests/src/Build/InPlaceUpdateTest.php @@ -4,7 +4,6 @@ namespace Drupal\Tests\automatic_updates\Build; use Drupal\automatic_updates\Services\InPlaceUpdate; use Drupal\Component\FileSystem\FileSystem as DrupalFilesystem; -use Drupal\Core\Archiver\Zip; use Drupal\Tests\automatic_updates\Build\QuickStart\QuickStartTestBase; use Drupal\Tests\automatic_updates\Traits\InstallTestTrait; use GuzzleHttp\Client; @@ -63,7 +62,7 @@ class InPlaceUpdateTest extends QuickStartTestBase { */ public function testCoreRollbackUpdate() { $from_version = '8.7.0'; - $to_version = '8.8.0'; + $to_version = '8.8.5'; $this->installCore($from_version); // Configure module to have db updates cause a rollback. @@ -167,66 +166,6 @@ class InPlaceUpdateTest extends QuickStartTestBase { $this->assertTrue($finder->hasResults(), "Expected version 8.8.{x} does not exist in {$this->getWorkspaceDirectory()}/core/lib/Drupal.php"); } - /** - * Prepare core for testing. - * - * @param string $starting_version - * The starting version. - */ - protected function installCore($starting_version) { - // Get tarball of drupal core. - $drupal_tarball = "drupal-$starting_version.zip"; - $destination = DrupalFileSystem::getOsTemporaryDirectory() . DIRECTORY_SEPARATOR . 'drupal-' . random_int(10000, 99999) . microtime(TRUE); - $fs = new SymfonyFilesystem(); - $fs->mkdir($destination); - $http_client = new Client(); - $http_client->get("https://ftp.drupal.org/files/projects/$drupal_tarball", ['sink' => $destination . DIRECTORY_SEPARATOR . $drupal_tarball]); - $zip = new Zip($destination . DIRECTORY_SEPARATOR . $drupal_tarball); - $zip->extract($destination); - // Move the tarball codebase over to the test workspace. - $finder = new Finder(); - $finder->files() - ->ignoreUnreadableDirs() - ->ignoreDotFiles(FALSE) - ->in("$destination/drupal-$starting_version"); - $options = ['override' => TRUE, 'delete' => FALSE]; - $fs->mirror("$destination/drupal-$starting_version", $this->getWorkingPath(), $finder->getIterator(), $options); - $fs->remove("$destination/drupal-$starting_version"); - // Copy in this module from the original code base. - $finder = new Finder(); - $finder->files() - ->ignoreUnreadableDirs() - ->in($this->getDrupalRoot()) - ->path('automatic_updates'); - $this->copyCodebase($finder->getIterator()); - - $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700); - $this->installQuickStart('minimal'); - - // Currently, this test has to use extension_discovery_scan_tests so we can - // install test modules. - $settings_php = $this->getWorkspaceDirectory() . '/sites/default/settings.php'; - $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0755); - $fs->chmod($settings_php, 0640); - $fs->appendToFile($settings_php, '$settings[\'extension_discovery_scan_tests\'] = TRUE;' . PHP_EOL); - - // Log in so that we can install modules. - $this->formLogin($this->adminUsername, $this->adminPassword); - $this->moduleInstall('update'); - $this->moduleInstall('automatic_updates'); - $this->moduleInstall('test_automatic_updates'); - - // Confirm we are running correct Drupal version. - $finder = new Finder(); - $finder->files()->in($this->getWorkspaceDirectory())->path('core/lib/Drupal.php'); - $finder->contains("/const VERSION = '$starting_version'/"); - $this->assertTrue($finder->hasResults(), "Expected version $starting_version does not exist in {$this->getWorkspaceDirectory()}/core/lib/Drupal.php"); - - // Assert that the site is functional after install. - $this->visit(); - $this->assertDrupalVisit(); - } - /** * Core versions data provider resulting in a successful upgrade. */ @@ -247,6 +186,10 @@ class InPlaceUpdateTest extends QuickStartTestBase { 'from' => '8.7.6', 'to' => '8.7.7', ]; + $datum[] = [ + 'from' => '8.9.0-beta1', + 'to' => '8.9.0-beta2', + ]; return $datum; } diff --git a/tests/src/Build/ModifiedFilesTest.php b/tests/src/Build/ModifiedFilesTest.php index 76ce2874db..b404826f37 100644 --- a/tests/src/Build/ModifiedFilesTest.php +++ b/tests/src/Build/ModifiedFilesTest.php @@ -39,16 +39,7 @@ class ModifiedFilesTest extends QuickStartTestBase { * @dataProvider coreProjectProvider */ public function testCoreModified($version, array $modifications = []) { - $this->copyCodebase(); - - // We have to fetch the tags for this shallow repo. It might not be a - // shallow clone, therefore we use executeCommand instead of assertCommand. - $this->executeCommand('git fetch --unshallow --tags'); - $this->symfonyFileSystem->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700); - $this->executeCommand('git reset HEAD --hard'); - $this->assertCommandSuccessful(); - $this->executeCommand("git checkout $version -f"); - $this->assertCommandSuccessful(); + $this->installCore($version); // Assert modifications. $this->assertModifications('core', 'drupal', $modifications); @@ -118,32 +109,6 @@ class ModifiedFilesTest extends QuickStartTestBase { * The modified files to assert. */ protected function assertModifications($project_type, $project, array $modifications) { - $this->symfonyFileSystem->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700); - $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); - $this->assertErrorOutputContains('Generating autoload files'); - $this->installQuickStart('minimal'); - - // Currently, this test has to use extension_discovery_scan_tests so we can - // install test modules. - $this->symfonyFileSystem->chmod($this->getWorkspaceDirectory() . '/sites/default', 0750); - $settings_php = $this->getWorkspaceDirectory() . '/sites/default/settings.php'; - $this->symfonyFileSystem->chmod($settings_php, 0640); - $this->symfonyFileSystem->appendToFile($settings_php, PHP_EOL . '$settings[\'extension_discovery_scan_tests\'] = TRUE;' . PHP_EOL); - - // Restart server for config override to apply. - $this->stopServer(); - $this->standUpServer(); - - // Log in so that we can install modules. - $this->formLogin($this->adminUsername, $this->adminPassword); - $this->moduleInstall('update'); - $this->moduleInstall('automatic_updates'); - $this->moduleInstall('test_automatic_updates'); - - // Assert that the site is functional. - $this->visit(); - $this->assertDrupalVisit(); - // Validate project is not modified. $this->visit("/automatic_updates/modified-files/$project_type/$project"); $assert = $this->getMink()->assertSession(); diff --git a/tests/src/Build/QuickStart/QuickStartTestBase.php b/tests/src/Build/QuickStart/QuickStartTestBase.php index 5acaa96960..af99c15301 100644 --- a/tests/src/Build/QuickStart/QuickStartTestBase.php +++ b/tests/src/Build/QuickStart/QuickStartTestBase.php @@ -3,6 +3,11 @@ namespace Drupal\Tests\automatic_updates\Build\QuickStart; use Drupal\BuildTests\Framework\BuildTestBase; +use Drupal\Component\FileSystem\FileSystem as DrupalFilesystem; +use Drupal\Core\Archiver\Zip; +use GuzzleHttp\Client; +use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; +use Symfony\Component\Finder\Finder; use Symfony\Component\Process\PhpExecutableFinder; /** @@ -43,6 +48,66 @@ abstract class QuickStartTestBase extends BuildTestBase { $this->assertNotEmpty($this->adminPassword = $matches[2]); } + /** + * Prepare core for testing. + * + * @param string $starting_version + * The starting version. + */ + protected function installCore($starting_version) { + // Get tarball of drupal core. + $drupal_tarball = "drupal-$starting_version.zip"; + $destination = DrupalFileSystem::getOsTemporaryDirectory() . DIRECTORY_SEPARATOR . 'drupal-' . random_int(10000, 99999) . microtime(TRUE); + $fs = new SymfonyFilesystem(); + $fs->mkdir($destination); + $http_client = new Client(); + $http_client->get("https://ftp.drupal.org/files/projects/$drupal_tarball", ['sink' => $destination . DIRECTORY_SEPARATOR . $drupal_tarball]); + $zip = new Zip($destination . DIRECTORY_SEPARATOR . $drupal_tarball); + $zip->extract($destination); + // Move the tarball codebase over to the test workspace. + $finder = new Finder(); + $finder->files() + ->ignoreUnreadableDirs() + ->ignoreDotFiles(FALSE) + ->in("$destination/drupal-$starting_version"); + $options = ['override' => TRUE, 'delete' => FALSE]; + $fs->mirror("$destination/drupal-$starting_version", $this->getWorkingPath(), $finder->getIterator(), $options); + $fs->remove("$destination/drupal-$starting_version"); + // Copy in this module from the original code base. + $finder = new Finder(); + $finder->files() + ->ignoreUnreadableDirs() + ->in($this->getDrupalRoot()) + ->path('automatic_updates'); + $this->copyCodebase($finder->getIterator()); + + $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700); + $this->installQuickStart('minimal'); + + // Currently, this test has to use extension_discovery_scan_tests so we can + // install test modules. + $settings_php = $this->getWorkspaceDirectory() . '/sites/default/settings.php'; + $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0755); + $fs->chmod($settings_php, 0640); + $fs->appendToFile($settings_php, '$settings[\'extension_discovery_scan_tests\'] = TRUE;' . PHP_EOL); + + // Log in so that we can install modules. + $this->formLogin($this->adminUsername, $this->adminPassword); + $this->moduleInstall('update'); + $this->moduleInstall('automatic_updates'); + $this->moduleInstall('test_automatic_updates'); + + // Confirm we are running correct Drupal version. + $finder = new Finder(); + $finder->files()->in($this->getWorkspaceDirectory())->path('core/lib/Drupal.php'); + $finder->contains("/const VERSION = '$starting_version'/"); + $this->assertTrue($finder->hasResults(), "Expected version $starting_version does not exist in {$this->getWorkspaceDirectory()}/core/lib/Drupal.php"); + + // Assert that the site is functional after install. + $this->visit(); + $this->assertDrupalVisit(); + } + /** * Helper that uses Drupal's user/login form to log in. * diff --git a/tests/src/Functional/AutomaticUpdatesTest.php b/tests/src/Functional/AutomaticUpdatesTest.php index 9e2bae100e..0a4ad81f3c 100644 --- a/tests/src/Functional/AutomaticUpdatesTest.php +++ b/tests/src/Functional/AutomaticUpdatesTest.php @@ -58,14 +58,12 @@ class AutomaticUpdatesTest extends BrowserTestBase { $this->drupalGet(Url::fromRoute('system.admin')); $this->assertSession()->pageTextContains('Critical Release - SA-2019-02-19'); $this->assertSession()->pageTextContains('Critical Release - PSA-Really Old'); - $this->assertSession()->pageTextContains('Seven - Moderately critical - Access bypass - SA-CONTRIB-2019'); - $this->assertSession()->pageTextContains('Standard - Moderately critical - Access bypass - SA-CONTRIB-2019'); $this->assertSession()->pageTextNotContains('Node - Moderately critical - Access bypass - SA-CONTRIB-2019'); $this->assertSession()->pageTextNotContains('Views - Moderately critical - Access bypass - SA-CONTRIB-2019'); // Test site status report. $this->drupalGet(Url::fromRoute('system.status')); - $this->assertSession()->pageTextContains('4 urgent announcements require your attention:'); + $this->assertSession()->pageTextContains('3 urgent announcements require your attention:'); // Test cache. $end_point = $this->buildUrl(Url::fromRoute('test_automatic_updates.json_test_denied_controller')); @@ -106,7 +104,7 @@ class AutomaticUpdatesTest extends BrowserTestBase { $this->assertSession()->pageTextContains('Your site does not pass some readiness checks for automatic updates. Depending on the nature of the failures, it might effect the eligibility for automatic updates.'); // Ignore specific file paths to see no readiness issues. - $ignore_paths = "core/*\nmodules/*\nthemes/*\nprofiles/*"; + $ignore_paths = "vendor/*\ncore/*\nmodules/*\nthemes/*\nprofiles/*\ncomposer.*\nautoload.php\nLICENSE.txt"; $this->config('automatic_updates.settings')->set('ignored_paths', $ignore_paths) ->save(); $this->drupalGet(Url::fromRoute('automatic_updates.settings')); diff --git a/tests/src/Functional/NotifyTest.php b/tests/src/Functional/NotifyTest.php index 42492a7dfb..783f9222b1 100644 --- a/tests/src/Functional/NotifyTest.php +++ b/tests/src/Functional/NotifyTest.php @@ -73,7 +73,7 @@ class NotifyTest extends BrowserTestBase { $notify = $this->container->get('automatic_updates.psa_notify'); $notify->send(); $this->assertCount(1, $this->getMails()); - $this->assertMailString('subject', '4 urgent Drupal announcements require your attention', 1); + $this->assertMailString('subject', '3 urgent Drupal announcements require your attention', 1); $this->assertMailString('body', 'Critical Release - SA-2019-02-19', 1); // No email should be sent if PSA's are disabled. -- GitLab