function TestSiteApplicationTest::testUserLogin
Same name in other branches
- 9 core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php \Drupal\Tests\Scripts\TestSiteApplicationTest::testUserLogin()
- 10 core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php \Drupal\Tests\Scripts\TestSiteApplicationTest::testUserLogin()
- 11.x core/tests/Drupal/Tests/Scripts/TestSiteApplicationTest.php \Drupal\Tests\Scripts\TestSiteApplicationTest::testUserLogin()
- 11.x core/tests/Drupal/KernelTests/Scripts/TestSiteApplicationTest.php \Drupal\KernelTests\Scripts\TestSiteApplicationTest::testUserLogin()
@coversNothing
File
-
core/
tests/ Drupal/ Tests/ Scripts/ TestSiteApplicationTest.php, line 257
Class
- TestSiteApplicationTest
- Tests core/scripts/test-site.php.
Namespace
Drupal\Tests\ScriptsCode
public function testUserLogin() {
$this->markTestIncomplete('Fix this test in https://www.drupal.org/project/drupal/issues/2962157.');
$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");
}
// Install a site using the JSON output.
$command_line = $this->php . ' core/scripts/test-site.php install --json --setup-file core/tests/Drupal/TestSite/TestSiteInstallTestScript.php --db-url "' . getenv('SIMPLETEST_DB') . '"';
$process = new Process($command_line, $this->root);
// Set the timeout to a value that allows debugging.
$process->setTimeout(500);
$process->run();
$this->assertSame(0, $process->getExitCode());
$result = json_decode($process->getOutput(), TRUE);
$db_prefix = $result['db_prefix'];
$site_path = $result['site_path'];
$this->assertSame('sites/simpletest/' . str_replace('test', '', $db_prefix), $site_path);
// Test the user login command with valid uid.
$command_line = $this->php . ' core/scripts/test-site.php user-login 1 --site-path ' . $site_path;
$process = new Process($command_line, $this->root);
$process->run();
$this->assertSame(0, $process->getExitCode());
$this->assertStringContainsString('/user/reset/1/', $process->getOutput());
$http_client = new Client();
$request = (new Request('GET', getenv('SIMPLETEST_BASE_URL') . trim($process->getOutput())))
->withHeader('User-Agent', trim($result['user_agent']));
$response = $http_client->send($request);
// Ensure the response sets a new session.
$this->assertTrue($response->getHeader('Set-Cookie'));
// Test the user login command with invalid uid.
$command_line = $this->php . ' core/scripts/test-site.php user-login invalid-uid --site-path ' . $site_path;
$process = new Process($command_line, $this->root);
$process->run();
$this->assertSame(1, $process->getExitCode());
$this->assertStringContainsString('The "uid" argument needs to be an integer, but it is "invalid-uid".', $process->getErrorOutput());
// Now tear down the test site.
$command_line = $this->php . ' core/scripts/test-site.php tear-down ' . $db_prefix . ' --db-url "' . getenv('SIMPLETEST_DB') . '"';
$process = new Process($command_line, $this->root);
// Set the timeout to a value that allows debugging.
$process->setTimeout(500);
$process->run();
$this->assertSame(0, $process->getExitCode());
$this->assertStringContainsString("Successfully uninstalled {$db_prefix} test site", $process->getOutput());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.