Update to Drupal 8.1.5. For more information, see https://www.drupal.org/project/drupal/releases/8.1.5

This commit is contained in:
Pantheon Automation 2016-07-07 09:44:38 -07:00 committed by Greg Anderson
parent 13b6ca7cc2
commit 38ba7c357d
342 changed files with 7814 additions and 1534 deletions

View file

@ -122,23 +122,23 @@ function _simpletest_format_summary_line($summary) {
* The test ID.
*/
function simpletest_run_tests($test_list) {
// We used to separate PHPUnit and Simpletest tests for a performance
// optimization. In order to support backwards compatibility check if these
// keys are set and create a single test list.
// @todo https://www.drupal.org/node/2748967 Remove BC support in Drupal 9.
if (isset($test_list['simpletest'])) {
$test_list = array_merge($test_list, $test_list['simpletest']);
unset($test_list['simpletest']);
}
if (isset($test_list['phpunit'])) {
$test_list = array_merge($test_list, $test_list['phpunit']);
unset($test_list['phpunit']);
}
$test_id = db_insert('simpletest_test_id')
->useDefaults(array('test_id'))
->execute();
if (!empty($test_list['phpunit'])) {
$phpunit_results = simpletest_run_phpunit_tests($test_id, $test_list['phpunit']);
simpletest_process_phpunit_results($phpunit_results);
}
// Early return if there are no further tests to run.
if (empty($test_list['simpletest'])) {
return $test_id;
}
// Continue with SimpleTests only.
$test_list = $test_list['simpletest'];
// Clear out the previous verbose files.
file_unmanaged_delete_recursive('public://simpletest/verbose');
@ -190,7 +190,7 @@ function simpletest_run_phpunit_tests($test_id, array $unescaped_test_classnames
// Something broke during the execution of phpunit.
// Return an error record of all failed classes.
$rows[] = [
'test_id' => '1',
'test_id' => $test_id,
'test_class' => implode(",", $unescaped_test_classnames),
'status' => 'fail',
'message' => 'PHPunit Test failed to complete',
@ -223,6 +223,48 @@ function simpletest_process_phpunit_results($phpunit_results) {
}
}
/**
* Maps phpunit results to a data structure for batch messages and run-tests.sh.
*
* @param array $results
* The output from simpletest_run_phpunit_tests().
*
* @return array
* The test result summary. A row per test class.
*/
function simpletest_summarize_phpunit_result($results) {
$summaries = [];
foreach ($results as $result) {
if (!isset($summaries[$result['test_class']])) {
$summaries[$result['test_class']] = array(
'#pass' => 0,
'#fail' => 0,
'#exception' => 0,
'#debug' => 0,
);
}
switch ($result['status']) {
case 'pass':
$summaries[$result['test_class']]['#pass']++;
break;
case 'fail':
$summaries[$result['test_class']]['#fail']++;
break;
case 'exception':
$summaries[$result['test_class']]['#exception']++;
break;
case 'debug':
$summaries[$result['test_class']]['#debug']++;
break;
}
}
return $summaries;
}
/**
* Returns the path to use for PHPUnit's --log-junit option.
*
@ -259,12 +301,21 @@ function simpletest_phpunit_configuration_filepath() {
* this variable.
*
* @return string
* The results as returned by exec().
* The results as returned by exec().
*/
function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpunit_file, &$status = NULL) {
global $base_url;
// Setup an environment variable containing the database connection so that
// functional tests can connect to the database.
putenv('SIMPLETEST_DB=' . Database::getConnectionInfoAsUrl());
// Setup an environment variable containing the base URL, if it is available.
// This allows functional tests to browse the site under test. When running
// tests via CLI, core/phpunit.xml.dist or core/scripts/run-tests.sh can set
// this variable.
if ($base_url) {
putenv('SIMPLETEST_BASE_URL=' . $base_url);
}
$phpunit_bin = simpletest_phpunit_command();
$command = array(
@ -302,6 +353,9 @@ function simpletest_phpunit_run_command(array $unescaped_test_classnames, $phpun
chdir($old_cwd);
putenv('SIMPLETEST_DB=');
if ($base_url) {
putenv('SIMPLETEST_BASE_URL=');
}
return $ret;
}
@ -352,15 +406,21 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
// Perform the next test.
$test_class = array_shift($test_list);
$test = new $test_class($test_id);
$test->run();
if (is_subclass_of($test_class, \PHPUnit_Framework_TestCase::class)) {
$phpunit_results = simpletest_run_phpunit_tests($test_id, [$test_class]);
simpletest_process_phpunit_results($phpunit_results);
$test_results[$test_class] = simpletest_summarize_phpunit_result($phpunit_results)[$test_class];
}
else {
$test = new $test_class($test_id);
$test->run();
\Drupal::moduleHandler()->invokeAll('test_finished', array($test->results));
$test_results[$test_class] = $test->results;
}
$size = count($test_list);
$info = TestDiscovery::getTestInfo($test_class);
\Drupal::moduleHandler()->invokeAll('test_finished', array($test->results));
// Gather results and compose the report.
$test_results[$test_class] = $test->results;
foreach ($test_results[$test_class] as $key => $value) {
$test_results[$key] += $value;
}

View file

@ -1241,6 +1241,24 @@ trait AssertContentTrait {
return $this->assertTrue(isset($options[0]), $message ? $message : SafeMarkup::format('Option @option for field @id exists.', array('@option' => $option, '@id' => $id)), $group);
}
/**
* Asserts that a select option with the visible text exists.
*
* @param string $id
* The ID of the select field to assert.
* @param string $text
* The text for the option tag to assert.
* @param string $message
* (optional) A message to display with the assertion.
*
* @return bool
* TRUE on pass, FALSE on fail.
*/
protected function assertOptionByText($id, $text, $message = '') {
$options = $this->xpath('//select[@id=:id]//option[normalize-space(text())=:text]', [':id' => $id, ':text' => $text]);
return $this->assertTrue(isset($options[0]), $message ?: 'Option with text label ' . $text . ' for select field ' . $id . ' exits.');
}
/**
* Asserts that a select option in the current page exists.
*

View file

@ -9,7 +9,7 @@ use Drupal\Tests\BrowserTestBase as BaseBrowserTestBase;
*
* Tests extending BrowserTestBase must exist in the
* Drupal\Tests\yourmodule\Functional namespace and live in the
* modules/yourmodule/Tests/Functional directory.
* modules/yourmodule/tests/src/Functional directory.
*
* @ingroup testing
*

View file

@ -214,7 +214,7 @@ class SimpletestResultsForm extends FormBase {
* The test_id to retrieve results of.
*
* @return array
* Array of results grouped by test_class.
* Array of results grouped by test_class.
*/
protected function getResults($test_id) {
return $this->database->select('simpletest')

View file

@ -199,7 +199,6 @@ class SimpletestTestForm extends FormBase {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
global $base_url;
// Test discovery does not run upon form submission.
simpletest_classloader_register();
@ -217,20 +216,8 @@ class SimpletestTestForm extends FormBase {
$form_state->setValue('tests', $user_input['tests']);
}
$tests_list = array();
foreach ($form_state->getValue('tests') as $class_name => $value) {
if ($value === $class_name) {
if (is_subclass_of($class_name, 'PHPUnit_Framework_TestCase')) {
$test_type = 'phpunit';
}
else {
$test_type = 'simpletest';
}
$tests_list[$test_type][] = $class_name;
}
}
$tests_list = array_filter($form_state->getValue('tests'));
if (!empty($tests_list)) {
putenv('SIMPLETEST_BASE_URL=' . $base_url);
$test_id = simpletest_run_tests($tests_list, 'drupal');
$form_state->setRedirect(
'simpletest.result_form',

View file

@ -20,8 +20,7 @@ use Drupal\Tests\SessionTestTrait;
/**
* Base class for Drupal tests.
*
* Do not extend this class directly; use either
* \Drupal\simpletest\WebTestBase or \Drupal\simpletest\KernelTestBase.
* Do not extend this class directly; use \Drupal\simpletest\WebTestBase.
*/
abstract class TestBase {

View file

@ -2,7 +2,7 @@
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\KernelTestBase;
use Drupal\simpletest\WebTestBase;
/**
* This test should not load since it requires a module that is not found.
@ -10,7 +10,7 @@ use Drupal\simpletest\KernelTestBase;
* @group simpletest
* @dependencies simpletest_missing_module
*/
class MissingDependentModuleUnitTest extends KernelTestBase {
class MissingDependentModuleUnitTest extends WebTestBase {
/**
* Ensure that this test will not be loaded despite its dependency.

View file

@ -127,7 +127,7 @@ class SimpleTestBrowserTest extends WebTestBase {
$tests = array(
// A KernelTestBase test.
'Drupal\system\Tests\DrupalKernel\DrupalKernelTest',
'Drupal\KernelTests\KernelTestBaseTest',
// A PHPUnit unit test.
'Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest',
// A PHPUnit functional test.

View file

@ -2680,7 +2680,7 @@ abstract class WebTestBase extends TestBase {
* Options to be passed to Url::fromUri().
*
* @return string
* An absolute URL stsring.
* An absolute URL string.
*/
protected function buildUrl($path, array $options = array()) {
if ($path instanceof Url) {

View file

@ -33,6 +33,9 @@ class BrowserTestBaseTest extends BrowserTestBase {
// Test page contains some text.
$this->assertSession()->pageTextContains('Test page text.');
// Response includes cache tags that we can assert.
$this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'rendered');
// Test drupalGet with a url object.
$url = Url::fromRoute('test_page_test.render_title');
$this->drupalGet($url);

View file

@ -5,6 +5,7 @@ namespace Drupal\Tests\simpletest\Unit;
use Drupal\Tests\UnitTestCase;
/**
* @requires extension curl
* @coversDefaultClass \Drupal\simpletest\TestBase
* @group simpletest
*/

View file

@ -5,6 +5,7 @@ namespace Drupal\Tests\simpletest\Unit;
use Drupal\Tests\UnitTestCase;
/**
* @requires extension curl
* @coversDefaultClass \Drupal\simpletest\WebTestBase
* @group simpletest
*/