diff --git a/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php index f698998f87..e5abe4e586 100644 --- a/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php +++ b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php @@ -138,6 +138,13 @@ abstract class BuildTestBase extends TestCase { */ private $commandProcess; + /** + * The PHP executable finder. + * + * @var \Symfony\Component\Process\PhpExecutableFinder + */ + private $phpFinder; + /** * {@inheritdoc} */ @@ -243,6 +250,15 @@ public function getMink() { return $this->mink; } + /** + * Get the PHP executable finder. + * + * @return \Symfony\Component\Process\PhpExecutableFinder + */ + protected function getPhpFinder() { + return $this->phpFinder; + } + /** * Full path to the workspace where this test can build. * diff --git a/core/tests/Drupal/BuildTests/QuickStart/InstallTest.php b/core/tests/Drupal/BuildTests/QuickStart/InstallTest.php index 7d3f67ef70..5ccc5a1130 100644 --- a/core/tests/Drupal/BuildTests/QuickStart/InstallTest.php +++ b/core/tests/Drupal/BuildTests/QuickStart/InstallTest.php @@ -27,20 +27,28 @@ public function testInstall($profile) { $this->copyCodebase(); // Composer tells you stuff in error output. - $this->assertCommandErrorOutputContains('Generating autoload files', 'COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); + $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); + $this->assertErrorOutputContains('Generating autoload files'); $this->installQuickStart($profile); // Visit paths with expectations. + $this->visit(); $this->assertDrupalVisit(); - $this->assertVisit('/does-not-exist', 404); + $this->visit('/does-not-exist'); + $assert = $this->getMink()->assertSession(); + $assert->statusCodeEquals(404); - $this->assertVisit('/admin', 403); + $this->visit('/admin'); + $assert->statusCodeEquals(403); $this->formLogin($this->adminUsername, $this->adminPassword); - $this->assertVisit('/admin', 200); + $this->visit('/admin'); + $assert->statusCodeEquals(200); - $this->assertVisit('/user/logout', 200); - $this->assertVisit('/admin', 403); + $this->visit('/user/logout'); + $assert->statusCodeEquals(200); + $this->visit('/admin'); + $assert->statusCodeEquals(403); } } diff --git a/core/tests/Drupal/BuildTests/QuickStart/QuickStartTestBase.php b/core/tests/Drupal/BuildTests/QuickStart/QuickStartTestBase.php index 14a1a7af51..11fcd38057 100644 --- a/core/tests/Drupal/BuildTests/QuickStart/QuickStartTestBase.php +++ b/core/tests/Drupal/BuildTests/QuickStart/QuickStartTestBase.php @@ -33,11 +33,8 @@ class QuickStartTestBase extends BuildTestBase { * execute the command. Defaults to the workspace directory. */ public function installQuickStart($profile, $working_dir = NULL) { - $install_process = $this->assertCommandOutputContains( - 'Username:', - $this->phpFinder->find() . ' ./core/scripts/drupal install ' . $profile, - $working_dir - ); + $this->executeCommand($this->phpFinder->find() . ' ./core/scripts/drupal install ' . $profile, $working_dir); + $install_process = $this->assertCommandOutputContains('Username:'); preg_match('/Username: (.+)\vPassword: (.+)/', $install_process->getOutput(), $matches); $this->assertNotEmpty($this->adminUsername = $matches[1]); $this->assertNotEmpty($this->adminPassword = $matches[2]); @@ -55,11 +52,12 @@ public function installQuickStart($profile, $working_dir = NULL) { * workspace directory. */ public function formLogin($username, $password, $working_dir = NULL) { - $this->assertVisit('/user/login', 200, $working_dir); - $assert = $this->mink->assertSession(); + $this->visit('/user/login', $working_dir); + $assert = $this->getMink()->assertSession(); + $assert->statusCodeEquals(200); $assert->fieldExists('edit-name')->setValue($username); $assert->fieldExists('edit-pass')->setValue($password); - $session = $this->mink->getSession(); + $session = $this->getMink()->getSession(); $session->getPage()->findButton('Log in')->submit(); } diff --git a/core/tests/Drupal/BuildTests/TestSiteApplication/InstallTest.php b/core/tests/Drupal/BuildTests/TestSiteApplication/InstallTest.php index 49dbe2b4bc..08bf4247ae 100644 --- a/core/tests/Drupal/BuildTests/TestSiteApplication/InstallTest.php +++ b/core/tests/Drupal/BuildTests/TestSiteApplication/InstallTest.php @@ -17,14 +17,15 @@ public function testInstall() { $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000); // Composer tells you stuff in error output. - $this->assertCommandErrorOutputContains('Generating autoload files', 'COMPOSER_DISCARD_CHANGES=true composer install --no-interaction'); + $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); + $this->assertErrorOutputContains('Generating autoload files'); // We have to stand up the server first so we can know the port number to // pass along to the install command. $this->standUpServer(); $install_command = [ - $this->phpFinder->find(), + $this->getPhpFinder()->find(), './core/scripts/test-site.php', 'install', '--base-url=http://localhost:' . $this->getPortNumber(), @@ -32,13 +33,15 @@ public function testInstall() { '--install-profile=minimal', '--json', ]; - $this->assertNotEmpty($output_json = $this->assertCommand(implode(' ', $install_command))->getOutput()); + $this->assertNotEmpty($output_json = $this->executeCommand(implode(' ', $install_command))->getOutput()); + $this->assertCommandSuccessful(); $connection_details = json_decode($output_json, TRUE); foreach (['db_prefix', 'user_agent', 'site_path'] as $key) { $this->assertArrayHasKey($key, $connection_details); } // Visit paths with expectations. + $this->visit(); $this->assertDrupalVisit(); } diff --git a/core/tests/Drupal/BuildTests/Update/UpdateSiteDrushTest.php b/core/tests/Drupal/BuildTests/Update/UpdateSiteDrushTest.php index a1191f240a..e32759407c 100644 --- a/core/tests/Drupal/BuildTests/Update/UpdateSiteDrushTest.php +++ b/core/tests/Drupal/BuildTests/Update/UpdateSiteDrushTest.php @@ -20,42 +20,57 @@ class UpdateSiteDrushTest extends BuildTestBase { public function testSiteUpdateWithDrush() { $this->copyCodebase(); // Save everything, including any applied patches. - $this->assertCommand('git config user.email "drupalci@no-reply.drupal.org"'); - $this->assertCommand('git config user.name "Drupal CI"'); - $this->assertCommand('git stash'); + $this->executeCommand('git config user.email "drupalci@no-reply.drupal.org"'); + $this->assertCommandSuccessful(); + $this->executeCommand('git config user.name "Drupal CI"'); + $this->assertCommandSuccessful(); + $this->executeCommand('git stash'); + $this->assertCommandSuccessful(); // We have to fetch the tags for this shallow repo. It might not be a - // shallow clone, therefore we use executeCommand instead of assertCommand. + // shallow clone, therefore we use executeCommand without + // assertCommandSuccessful. $this->executeCommand('git fetch --unshallow --tags'); - $this->assertCommand("git checkout 8.5.0"); + $this->executeCommand("git checkout 8.5.0"); + $this->assertCommandSuccessful(); $fs = new Filesystem(); $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000); - $this->assertCommandErrorOutputContains('Generating autoload files', 'COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); + $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); + $this->assertErrorOutputContains('Generating autoload files',); $this->executeCommand('drush site-install --db-url=sqlite://db.sqlite -y'); // Assert that it worked. + $this->visit(); $this->assertDrupalVisit(); // Return the codebase to HEAD and re-apply patches. $fs = new Filesystem(); $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000); - $this->assertCommand('git checkout - -f'); - $this->assertCommand('git reset HEAD --hard'); - $this->assertCommand('git stash pop'); - $this->assertCommandErrorOutputContains('Generating autoload files', 'COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); + $this->executeCommand('git checkout - -f'); + $this->assertCommandSuccessful(); + $this->executeCommand('git reset HEAD --hard'); + $this->assertCommandSuccessful(); + $this->executeCommand('git stash pop'); + $this->assertCommandSuccessful(); + $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); + $this->assertErrorOutputContains('Generating autoload files',); // Perform the update steps. - $this->assertCommand('drush updb -y'); + $this->executeCommand('drush updb -y'); + $this->assertCommandSuccessful(); // Assert that it worked. - $this->assertDrupalVisit('/node'); + $this->visit('/node'); + $this->assertDrupalVisit(); // Confirm Drush still works and root user can login. $hostname = 'http://localhost'; - $process = $this->assertCommand('drush uli --no-browser -l ' . $hostname); + $process = $this->executeCommand('drush uli --no-browser -l ' . $hostname); + $this->assertCommandSuccessful(); // Drush prints new lines for its commands; this removes them and trims the // hostname from the URL. $url = trim(rtrim(substr($process->getOutput(), strlen($hostname)))); - $this->assertVisit($url); + $this->visit($url); + $this->assertDrupalVisit(); } } diff --git a/core/tests/Drupal/BuildTests/Update/UpdateTest.php b/core/tests/Drupal/BuildTests/Update/UpdateTest.php index d3494a80f8..cda70e239f 100644 --- a/core/tests/Drupal/BuildTests/Update/UpdateTest.php +++ b/core/tests/Drupal/BuildTests/Update/UpdateTest.php @@ -31,33 +31,45 @@ public function provideVersions() { public function testUpdateGit($version_branch) { $this->copyCodebase(); // Save everything, including any applied patches. - $this->assertCommand('git config user.email "drupalci@no-reply.drupal.org"'); - $this->assertCommand('git config user.name "Drupal CI"'); - $this->assertCommand('git stash'); + $this->executeCommand('git config user.email "drupalci@no-reply.drupal.org"'); + $this->assertCommandSuccessful(); + $this->executeCommand('git config user.name "Drupal CI"'); + $this->assertCommandSuccessful(); + $this->executeCommand('git stash'); + $this->assertCommandSuccessful(); // We have to fetch the branch in a special way for this shallow clone repo. - $this->assertCommand("git remote set-branches origin '$version_branch'"); - $this->assertCommand("git fetch origin $version_branch"); - $this->assertCommand("git checkout $version_branch"); + $this->executeCommand("git remote set-branches origin '$version_branch'"); + $this->assertCommandSuccessful(); + $this->executeCommand("git fetch origin $version_branch"); + $this->assertCommandSuccessful(); + $this->executeCommand("git checkout $version_branch"); + $this->assertCommandSuccessful(); $fs = new Filesystem(); $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000); // Install Drupal using quick start. - $this->assertCommandErrorOutputContains('Generating autoload files', 'COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); + $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); + $this->assertErrorOutputContains('Generating autoload files',); $this->installQuickStart('minimal'); // Assert that it worked. + $this->visit(); $this->assertDrupalVisit(); // Return the codebase to HEAD and re-apply patches. $fs = new Filesystem(); $fs->chmod($this->getWorkspaceDirectory() . '/sites/default', 0700, 0000); $fs->chmod($this->getWorkspaceDirectory() . '/sites/default/settings.php', 0600, 0000); - $this->assertCommand('git checkout - -f'); - $this->assertCommand('git reset HEAD --hard'); + $this->executeCommand('git checkout - -f'); + $this->assertCommandSuccessful(); + $this->executeCommand('git reset HEAD --hard'); + $this->assertCommandSuccessful(); // Re-apply any patches. - $this->assertCommand('git stash pop'); + $this->executeCommand('git stash pop'); + $this->assertCommandSuccessful(); // Composer. - $this->assertCommandErrorOutputContains('Generating autoload files', 'COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); + $this->executeCommand('COMPOSER_DISCARD_CHANGES=true composer install --no-dev --no-interaction'); + $this->assertErrorOutputContains('Generating autoload files',); // Currently, this test has to use update_free_access because the PHP HTTP // server caches old class information. We'll need to restart the server @@ -70,11 +82,12 @@ public function testUpdateGit($version_branch) { $this->formLogin($this->adminUsername, $this->adminPassword); // Since we restarted the server, we're in a different session, but only // after we've made a request. - $session = $this->mink->getSession(); - $assert = $this->mink->assertSession(); + $session = $this->getMink()->getSession(); + $assert = $this->getMink()->assertSession(); // Perform the update steps. - $this->assertVisit('/update.php'); + $this->visit('/update.php'); + $this->assertDrupalVisit(); $assert->pageTextContains('Drupal database update'); $session->getPage()->clickLink('Continue'); @@ -85,6 +98,7 @@ public function testUpdateGit($version_branch) { } // Request the front page again and make sure it works. + $this->visit(); $this->assertDrupalVisit(); } diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php index 77e6ef7e1e..e39bbdffe4 100644 --- a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php @@ -13,6 +13,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\Filesystem\Filesystem; /** * Command to create a test Drupal site. @@ -97,6 +98,18 @@ protected function execute(InputInterface $input, OutputInterface $output) { // Manage site fixture. $this->setup($input->getOption('install-profile'), $class_name, $input->getOption('langcode')); + // Make sure there is an entry in sites.php for the new site. + $fs = new Filesystem(); + if (!$fs->exists($root . '/sites/sites.php')) { + $fs->copy($root . '/sites/example.sites.php', $root . '/sites/sites.php'); + } + $parsed = parse_url($base_url); + $port = $parsed['port'] ?? 80; + $host = $parsed['host'] ?? 'localhost'; + // Remove 'sites/' from the beginning of the path. + $site_path = substr($this->siteDirectory, 6); + file_put_contents($root . '/sites/sites.php', "\$sites['$port.$host'] = '$site_path';", FILE_APPEND); + $user_agent = drupal_generate_test_ua($this->databasePrefix); if ($input->getOption('json')) { $output->writeln(json_encode([ diff --git a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php index 4f7b39bdf2..bf0ff524ae 100644 --- a/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php +++ b/core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php @@ -49,6 +49,7 @@ protected function setUp() { * @coversNothing */ public function testInstallWithNonExistingFile() { + $this->markTestIncomplete('Replace with build test.'); // Create a connection to the DB configured in SIMPLETEST_DB. $connection = Database::getConnection('default', $this->addTestDatabase('')); @@ -67,6 +68,7 @@ public function testInstallWithNonExistingFile() { * @coversNothing */ public function testInstallWithFileWithNoClass() { + $this->markTestIncomplete('Replace with build test.'); // Create a connection to the DB configured in SIMPLETEST_DB. $connection = Database::getConnection('default', $this->addTestDatabase('')); @@ -106,6 +108,7 @@ public function testInstallWithNonSetupClass() { * @coversNothing */ public function testInstallScript() { + $this->markTestIncomplete('Replace with build test.'); $simpletest_path = $this->root . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'simpletest'; if (!is_writable($simpletest_path)) { $this->markTestSkipped("Requires the directory $simpletest_path to exist and be writable"); @@ -206,6 +209,7 @@ public function testInstallScript() { * @coversNothing */ public function testInstallInDifferentLanguage() { + $this->markTestIncomplete('Replace with build test.'); $simpletest_path = $this->root . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'simpletest'; if (!is_writable($simpletest_path)) { $this->markTestSkipped("Requires the directory $simpletest_path to exist and be writable"); @@ -243,6 +247,7 @@ public function testInstallInDifferentLanguage() { * @coversNothing */ public function testTearDownDbPrefixValidation() { + $this->markTestIncomplete('Replace with build test.'); $command_line = $this->php . ' core/scripts/test-site.php tear-down not-a-valid-prefix'; $process = new Process($command_line, $this->root); $process->setTimeout(500); @@ -317,6 +322,7 @@ public function testUserLogin() { * The database key of the added connection. */ protected function addTestDatabase($db_prefix) { + $this->markTestIncomplete('Replace with build test.'); $database = Database::convertDbUrlToConnectionInfo(getenv('SIMPLETEST_DB'), $this->root); $database['prefix'] = ['default' => $db_prefix]; $target = __CLASS__ . $db_prefix;