diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 9870754..92fed64 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -843,8 +843,10 @@ function drupal_valid_test_ua($new_prefix = NULL) { // a test environment. $test_prefix = FALSE; - // Perform a basic check on the User-Agent HTTP request header first. Any - // inbound request that uses the simpletest UA header needs to be validated. + // Perform a basic check on the Simpletest-user-agent cookie first. If it + // does not exists then perform a basic check on the User-Agent HTTP request + // header. Any inbound request that uses the simpletest UA header needs to be + // validated. $http_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : NULL; $user_agent = isset($_COOKIE['SIMPLETEST_USER_AGENT']) ? $_COOKIE['SIMPLETEST_USER_AGENT'] : $http_user_agent; if (isset($user_agent) && preg_match("/^(simpletest\d+);(.+);(.+);(.+)$/", $user_agent, $matches)) { diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php index a1d9675..6a24a05 100644 --- a/core/lib/Drupal/Core/Database/Database.php +++ b/core/lib/Drupal/Core/Database/Database.php @@ -469,12 +469,20 @@ public static function convertDbUrlToConnectionInfo($url, $root) { 'pass' => '', 'fragment' => '', ); - if ($info['path'][0] === '/') { - $info['path'] = substr($info['path'], 1); + + // A SQLite database is special because it datebase connection is directly + // to the database file. The variable $info['path'] holds the location of + // the database file. + if ($info['scheme'] === 'sqlite') { + if ($info['path'][0] !== '/') { + $info['path'] = '/' . $info['path']; + } + $info['path'] = $root . $info['path']; } - if ($info['scheme'] === 'sqlite' && $info['path'][0] !== '/') { - $info['path'] = $root . '/' . $info['path']; + elseif ($info['path'][0] === '/') { + $info['path'] = substr($info['path'], 1); } + $database = array( 'driver' => $info['scheme'], 'username' => $info['user'], @@ -500,7 +508,7 @@ public static function convertDbUrlToConnectionInfo($url, $root) { public static function getConnectionInfoAsUrl($key = 'default') { $db_info = static::getConnectionInfo($key); if ($db_info['default']['driver'] == 'sqlite') { - $db_url = $db_info['default']['driver'] . '://localhost/' . $db_info['default']['database']; + $db_url = 'sqlite://localhost/' . $db_info['default']['database']; } else { $user = ''; diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 327ff51..3b46028 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -238,8 +238,8 @@ function simpletest_phpunit_configuration_filepath() { * The results as returned by exec(). */ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file) { - // Set the up an environment variable containing the database connection so - // that functional tests can connect to the database. + // Setup an environment variable containing the database connection so that + // functional tests can connect to the database. putenv('SIMPLETEST_DB=' . Database::getConnectionInfoAsUrl()); $phpunit_bin = simpletest_phpunit_command(); diff --git a/core/modules/simpletest/src/BrowserTestBase.php b/core/modules/simpletest/src/BrowserTestBase.php index d4d3168..ac7845f 100644 --- a/core/modules/simpletest/src/BrowserTestBase.php +++ b/core/modules/simpletest/src/BrowserTestBase.php @@ -26,10 +26,11 @@ use Drupal\Core\Site\Settings; use Drupal\Core\StreamWrapper\StreamWrapperInterface; use Drupal\Core\Test\TestRunnerKernel; +use Drupal\user\UserInterface; use Symfony\Component\HttpFoundation\Request; /** - * Test case for typical Drupal tests. + * Test case for functional Drupal tests. * * @ingroup testing * @@ -68,6 +69,8 @@ /** * Time limit in seconds for the test. + * + * @var int */ protected $timeLimit = 500; @@ -150,7 +153,7 @@ protected $sessionName; /** - * The current user logged in using the internal browser. + * The current user logged in using the Mink controled browser. * * @var bool */ @@ -159,12 +162,14 @@ /** * The root user. * - * @var UserSession + * @var \Drupal\Core\Session\UserSession */ protected $rootUser; /** * The config directories used in this test. + * + * @var array */ protected $configDirectories = array(); @@ -178,7 +183,7 @@ /** * Mink session manager. * - * @var Mink + * @var \Behat\Mink\Mink */ protected $mink; @@ -228,10 +233,8 @@ protected function setUp() { $parsed_url = parse_url($base_url); $host = $parsed_url['host'] . (isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''); $path = isset($parsed_url['path']) ? rtrim(rtrim($parsed_url['path']), '/') : ''; - $port = (isset($parsed_url['port']) ? $parsed_url['port'] : 80); - if ($path == '/') { - $path = ''; - } + $port = isset($parsed_url['port']) ? $parsed_url['port'] : 80; + // If the passed URL schema is 'https' then setup the $_SERVER variables // properly so that testing will run under HTTPS. if ($parsed_url['scheme'] === 'https') { @@ -277,8 +280,8 @@ protected function setUp() { foreach ($pairs as $pair) { list($key, $value) = explode('=', $pair); // Account for key-value pairs being separated by multiple spaces. - if (trim($key, ' ') == 'idekey') { - $session->setCookie('XDEBUG_SESSION', trim($value, ' ')); + if (trim($key) == 'idekey') { + $session->setCookie('XDEBUG_SESSION', trim($value)); } } } @@ -344,8 +347,8 @@ protected function tearDown() { /** * Returns Mink session. * - * @param string|null $name - * (optional) Name of the session OR active session will be used. + * @param string $name + * (optional) Name of the session. Defaults to the active session. * * @return \Behat\Mink\Session * The active mink session object. @@ -355,9 +358,9 @@ public function getSession($name = NULL) { } /** - * Returns Mink assert session. + * Returns WebAssert object. * - * @param string|null $name + * @param string $name * (optional) Name of the session. Defaults to the active session. * * @return \Drupal\simpletest\WebAssert @@ -384,7 +387,7 @@ protected function prepareRequest() { * Retrieves a Drupal path or an absolute path. * * @param string $path - * Drupal path or URL to load into internal browser + * Drupal path or URL to load into Mink controled browser. * @param array $options * (optional) Options to be forwarded to the url generator. * @@ -418,7 +421,7 @@ protected function drupalGet($path, array $options = array()) { * Takes a path and returns an absolute path. * * @param string $path - * A path from the internal browser content. + * A path from the Mink controled browser content. * * @return string * The $path with $base_url prepended, if necessary. @@ -553,9 +556,21 @@ protected function drupalCreateRole(array $permissions, $rid = NULL, $name = NUL } return $role->id(); } - else { - return FALSE; + + return FALSE; + } + + /** + * Gets the random generator for the utility methods. + * + * @return \Drupal\Component\Utility\Random + * The random generator + */ + protected function getRandomGenerator() { + if (!is_object($this->randomGenerator)) { + $this->randomGenerator = new Random(); } + return $this->randomGenerator; } /** @@ -630,7 +645,7 @@ protected function checkPermissions(array $permissions) { } /** - * Logs in a user using the mink browser. + * Logs in a user using the mink controled browser. * * If a user is already logged in, then the current user is logged out before * logging in the specified user. @@ -677,7 +692,7 @@ protected function drupalLogin(AccountInterface $account) { } /** - * Logs a user out of the internal browser and confirms. + * Logs a user out of the Mink controled browser and confirms. * * Confirms logout by checking the login page. */ @@ -725,7 +740,7 @@ protected function submitForm($edit, $submit, $form_html_id = NULL) { // Get the form. if (isset($form_html_id)) { - $form = $assert_session->elementExists('xpath', "//form[@id='" . $form_html_id . "']"); + $form = $assert_session->elementExists('xpath', "//form[@id='$form_html_id']"); $submit_button = $assert_session->buttonExists($submit, $form); } else { @@ -750,9 +765,9 @@ protected function submitForm($edit, $submit, $form_html_id = NULL) { /** * Helper function to get the options of select field. * - * @param NodeElement|string $select + * @param \Behat\Mink\Element\NodeElement|string $select * Name, ID, or Label of select field to assert. - * @param Element $container + * @param \Behat\Mink\Element\Element $container * (optional) Container element to check against. Defaults to current page. * * @return array @@ -773,18 +788,6 @@ protected function getOptions($select, Element $container = NULL) { } /** - * {@inheritdoc} - */ - public function run(\PHPUnit_Framework_TestResult $result = NULL) { - if ($result === NULL) { - $result = $this->createResult(); - } - - parent::run($result); - return $result; - } - - /** * Override to use Mink exceptions. * * @return mixed @@ -802,37 +805,6 @@ protected function runTest() { } /** - * Generates a unique random string containing letters and numbers. - * - * Do not use this method when testing unvalidated user input. Instead, use - * \Drupal\simpletest\TestBase::randomString(). - * - * @param int $length - * (optional) Length of random string to generate. - * - * @return string - * Randomly generated unique string. - * - * @see \Drupal\Component\Utility\Random::name() - */ - public function randomName($length = 8) { - return $this->getRandomGenerator()->name($length, TRUE); - } - - /** - * Gets the random generator for the utility methods. - * - * @return \Drupal\Component\Utility\Random - * The random generator - */ - protected function getRandomGenerator() { - if (!is_object($this->randomGenerator)) { - $this->randomGenerator = new Random(); - } - return $this->randomGenerator; - } - - /** * Installs drupal into the simpletest site. */ public function installDrupal() { @@ -841,7 +813,7 @@ public function installDrupal() { 'uid' => 1, 'name' => 'admin', 'mail' => 'admin@example.com', - 'passRaw' => $this->randomName(), + 'passRaw' => $this->randomMachineName(), )); // Some tests (SessionTest and SessionHttpsTest) need to examine whether the @@ -1033,9 +1005,9 @@ protected function installParameters() { * * The generated database table prefix is used for the Drupal installation * being performed for the test. It is also used by the cookie value of - * SIMPLETEST_USER_AGENT by the mink browser. During early Drupal bootstrap, - * the cookie is parsed, and if it matches, all database queries use - * the database table prefix that has been generated here. + * SIMPLETEST_USER_AGENT by the mink controled browser. During early Drupal + * bootstrap, the cookie is parsed, and if it matches, all database queries + * use the database table prefix that has been generated here. * * @see drupal_valid_test_ua() * @see BrowserTestBase::prepareEnvironment() @@ -1202,8 +1174,6 @@ protected function writeSettings(array $settings) { include_once DRUPAL_ROOT . '/core/includes/install.inc'; $filename = $this->siteDirectory . '/settings.php'; - error_log($filename); - // system_requirements() removes write permissions from settings.php // whenever it is invoked. // Not using File API; a potential error must trigger a PHP warning. @@ -1215,9 +1185,9 @@ protected function writeSettings(array $settings) { * Rebuilds \Drupal::getContainer(). * * Use this to build a new kernel and service container. For example, when the - * list of enabled modules is changed via the internal browser, in which case - * the test process still contains an old kernel and service container with an - * old module list. + * list of enabled modules is changed via the Mink controled browser, in which + * case the test process still contains an old kernel and service container + * with an old module list. * * @see BrowserTestBase::prepareEnvironment() * @see BrowserTestBase::restoreEnvironment() @@ -1290,7 +1260,7 @@ protected function prepareRequestForGenerator($clean_urls = TRUE, $override_serv /** * Resets all data structures after having enabled new modules. * - * This method is called by \Drupal\simpletest\WebTestBase::setUp() after + * This method is called by \Drupal\simpletest\BrowserTestBase::setUp() after * enabling the requested modules. It must be called again when additional * modules are enabled later. */ @@ -1309,7 +1279,7 @@ protected function resetAll() { * Useful after a page request is made that changes configuration or state in * a different thread. * - * In other words calling a settings page with $this->drupalPostForm() with a + * In other words calling a settings page with $this->submitForm() with a * changed value would update configuration to reflect that change, but in the * thread that made the call (thread running the test) the changed values * would not be picked up. @@ -1343,7 +1313,7 @@ protected function refreshVariables() { * @return bool * Return TRUE if the user is logged in, FALSE otherwise. */ - protected function drupalUserIsLoggedIn($account) { + protected function drupalUserIsLoggedIn(UserInterface $account) { if (!isset($account->sessionId)) { return FALSE; } diff --git a/core/modules/simpletest/src/TestDiscovery.php b/core/modules/simpletest/src/TestDiscovery.php index f3a0449..60ef6ce 100644 --- a/core/modules/simpletest/src/TestDiscovery.php +++ b/core/modules/simpletest/src/TestDiscovery.php @@ -426,8 +426,8 @@ public static function isUnitTest($classname) { // A core unit test. return TRUE; } - else if ($namespace[3] == 'Unit') { - // A module unit test + elseif ($namespace[3] == 'Unit') { + // A module unit test. return TRUE; } } diff --git a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php index c86933d..adf8326 100644 --- a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php +++ b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php @@ -128,29 +128,23 @@ public function testTestingThroughUI() { // to be created. However this scenario is covered by the testception of // \Drupal\simpletest\Tests\SimpleTestTest. - $this->drupalGet('admin/config/development/testing'); - $edit = array( + $tests = array( // A KernalTestBase test. - 'tests[Drupal\field\Tests\String\StringFormatterTest]' => TRUE, - ); - $this->drupalPostForm(NULL, $edit, t('Run tests')); - $this->assertText('0 fails, 0 exceptions'); - - $this->drupalGet('admin/config/development/testing'); - $edit = array( + 'Drupal\field\Tests\String\StringFormatterTest', // A PHPUnit unit test. - 'tests[Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest]' => TRUE, - ); - $this->drupalPostForm(NULL, $edit, t('Run tests')); - $this->assertText('0 fails, 0 exceptions'); - - $this->drupalGet('admin/config/development/testing'); - $edit = array( + 'Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest', // A PHPUnit functional test. - 'tests[Drupal\Tests\simpletest\Functional\BrowserTestBaseTest]' => TRUE, + 'Drupal\Tests\simpletest\Functional\BrowserTestBaseTest', ); - $this->drupalPostForm(NULL, $edit, t('Run tests')); - $this->assertText('0 fails, 0 exceptions'); + + foreach($tests as $test) { + $this->drupalGet('admin/config/development/testing'); + $edit = array( + "tests[$test]" => TRUE, + ); + $this->drupalPostForm(NULL, $edit, t('Run tests')); + $this->assertText('0 fails, 0 exceptions'); + } } } diff --git a/core/modules/simpletest/src/WebAssert.php b/core/modules/simpletest/src/WebAssert.php index daea904..9f96260 100644 --- a/core/modules/simpletest/src/WebAssert.php +++ b/core/modules/simpletest/src/WebAssert.php @@ -22,7 +22,7 @@ class WebAssert extends MinkWebAssert { * @param string $button * One of id|name|label|value for the button. * @param \Behat\Mink\Element\TraversableElement $container - * The document to check against. + * (optional) The document to check against. Defaults to the current page. * * @return \Behat\Mink\Element\NodeElement * The matching element. @@ -34,7 +34,7 @@ public function buttonExists($button, TraversableElement $container = NULL) { $container = $container ?: $this->session->getPage(); $node = $container->findButton($button); - if (NULL === $node) { + if ($node === NULL) { throw new ElementNotFoundException($this->session, 'button', 'id|name|label|value', $button); } @@ -47,7 +47,7 @@ public function buttonExists($button, TraversableElement $container = NULL) { * @param string $select * One of id|name|label|value for the select field. * @param \Behat\Mink\Element\TraversableElement $container - * The document to check against. + * (optional) The document to check against. Defaults to the current page. * * @return \Behat\Mink\Element\NodeElement * The matching element @@ -62,7 +62,7 @@ public function selectExists($select, TraversableElement $container = NULL) { $this->session->getSelectorsHandler()->xpathLiteral($select), )); - if (NULL === $node) { + if ($node === NULL) { throw new ElementNotFoundException($this->session, 'select', 'id|name|label|value', $select); } diff --git a/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php b/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php index 99194c5..4dc5f11 100644 --- a/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php +++ b/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of \Drupal\Tests\simpletest\Functional\BrowserTestBaseTest. + * Contains \Drupal\Tests\simpletest\Functional\BrowserTestBaseTest. */ namespace Drupal\Tests\simpletest\Functional; @@ -13,7 +13,6 @@ * Tests BrowserTestBase functionality. * * @group simpletest - * @group modern * * @runTestsInSeparateProcesses */