"Issue #2229011 by chx, tstoeckler: Fixed Tests are no longer modifiable."
This reverts commit 2cd0b096b9
.
8.0.x
parent
6d2ce628bc
commit
a5b79de33b
|
@ -126,6 +126,13 @@ abstract class KernelTestBase extends UnitTestBase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
$this->keyValueFactory = new KeyValueMemoryFactory();
|
$this->keyValueFactory = new KeyValueMemoryFactory();
|
||||||
|
|
||||||
|
// Allow for test-specific overrides.
|
||||||
|
$settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
|
||||||
|
if (file_exists($settings_services_file)) {
|
||||||
|
// Copy the testing-specific service overrides in place.
|
||||||
|
copy($settings_services_file, DRUPAL_ROOT . '/' . $this->siteDirectory . '/services.yml');
|
||||||
|
}
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
// Create and set new configuration directories.
|
// Create and set new configuration directories.
|
||||||
|
|
|
@ -53,6 +53,13 @@ abstract class TestBase {
|
||||||
*/
|
*/
|
||||||
protected $databasePrefix = NULL;
|
protected $databasePrefix = NULL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The site directory of the original parent site.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $originalSite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The original file directory, before it was changed for testing purposes.
|
* The original file directory, before it was changed for testing purposes.
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
namespace Drupal\simpletest\Tests;
|
namespace Drupal\simpletest\Tests;
|
||||||
|
|
||||||
use Drupal\Core\Database\Driver\pgsql\Select;
|
|
||||||
use Drupal\simpletest\WebTestBase;
|
use Drupal\simpletest\WebTestBase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +33,9 @@ class SimpleTestTest extends WebTestBase {
|
||||||
*/
|
*/
|
||||||
protected $test_ids = array();
|
protected $test_ids = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public static function getInfo() {
|
public static function getInfo() {
|
||||||
return array(
|
return array(
|
||||||
'name' => 'SimpleTest functionality',
|
'name' => 'SimpleTest functionality',
|
||||||
|
@ -44,11 +46,41 @@ class SimpleTestTest extends WebTestBase {
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
if (!$this->isInChildSite()) {
|
if (!$this->isInChildSite()) {
|
||||||
|
$php = <<<'EOD'
|
||||||
|
<?php
|
||||||
|
|
||||||
|
# Make sure that the $test_class variable is defined when this file is included.
|
||||||
|
if ($test_class) {
|
||||||
|
}
|
||||||
|
|
||||||
|
# Define a function to be able to check that this file was loaded with
|
||||||
|
# function_exists().
|
||||||
|
if (!function_exists('simpletest_test_stub_settings_function')) {
|
||||||
|
function simpletest_test_stub_settings_function() {}
|
||||||
|
}
|
||||||
|
EOD;
|
||||||
|
|
||||||
|
file_put_contents($this->siteDirectory. '/' . 'settings.testing.php', $php);
|
||||||
|
// @see \Drupal\system\Tests\DrupalKernel\DrupalKernelSiteTest
|
||||||
|
$class = __CLASS__;
|
||||||
|
$yaml = <<<EOD
|
||||||
|
services:
|
||||||
|
# Add a new service.
|
||||||
|
site.service.yml:
|
||||||
|
class: $class
|
||||||
|
# Swap out a core service.
|
||||||
|
cache.backend.database:
|
||||||
|
class: Drupal\Core\Cache\MemoryBackendFactory
|
||||||
|
EOD;
|
||||||
|
file_put_contents($this->siteDirectory . '/testing.services.yml', $yaml);
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
// Create and log in an admin user.
|
// Create and log in an admin user.
|
||||||
$this->drupalLogin($this->drupalCreateUser(array('administer unit tests')));
|
$this->drupalLogin($this->drupalCreateUser(array('administer unit tests')));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// This causes three of the five fails that are asserted in
|
||||||
|
// confirmStubResults().
|
||||||
self::$modules = array('non_existent_module');
|
self::$modules = array('non_existent_module');
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
@ -184,23 +216,42 @@ class SimpleTestTest extends WebTestBase {
|
||||||
* Test to be run and the results confirmed.
|
* Test to be run and the results confirmed.
|
||||||
*/
|
*/
|
||||||
function stubTest() {
|
function stubTest() {
|
||||||
|
// This causes the first of the ten passes asserted in confirmStubResults().
|
||||||
$this->pass($this->pass);
|
$this->pass($this->pass);
|
||||||
|
// The first three fails are caused by enabling a non-existent module in
|
||||||
|
// setUp(). This causes the fourth of the five fails asserted in
|
||||||
|
// confirmStubResults().
|
||||||
$this->fail($this->fail);
|
$this->fail($this->fail);
|
||||||
|
|
||||||
|
// This causes the second to fourth of the ten passes asserted in
|
||||||
|
// confirmStubResults().
|
||||||
$this->drupalCreateUser(array($this->valid_permission));
|
$this->drupalCreateUser(array($this->valid_permission));
|
||||||
|
// This causes the fifth of the five fails asserted in confirmStubResults().
|
||||||
$this->drupalCreateUser(array($this->invalid_permission));
|
$this->drupalCreateUser(array($this->invalid_permission));
|
||||||
|
|
||||||
|
// This causes the fifth of the ten passes asserted in confirmStubResults().
|
||||||
$this->pass(t('Test ID is @id.', array('@id' => $this->testId)));
|
$this->pass(t('Test ID is @id.', array('@id' => $this->testId)));
|
||||||
|
|
||||||
|
// These cause the sixth to ninth of the ten passes asserted in
|
||||||
|
// confirmStubResults().
|
||||||
|
$this->assertTrue(file_exists(conf_path() . '/settings.testing.php'));
|
||||||
|
// Check the settings.testing.php file got included.
|
||||||
|
$this->assertTrue(function_exists('simpletest_test_stub_settings_function'));
|
||||||
|
// Check that the test-specific service file got loaded.
|
||||||
|
$this->assertTrue($this->container->has('site.service.yml'));
|
||||||
|
$this->assertIdentical(get_class($this->container->get('cache.backend.database')), 'Drupal\Core\Cache\MemoryBackendFactory');
|
||||||
|
|
||||||
|
// These cause the two exceptions asserted in confirmStubResults().
|
||||||
// Call trigger_error() without the required argument to trigger an E_WARNING.
|
// Call trigger_error() without the required argument to trigger an E_WARNING.
|
||||||
trigger_error();
|
trigger_error();
|
||||||
|
|
||||||
// Call an assert function specific to that class.
|
|
||||||
$this->assertNothing();
|
|
||||||
|
|
||||||
// Generates a warning inside a PHP function.
|
// Generates a warning inside a PHP function.
|
||||||
array_key_exists(NULL, NULL);
|
array_key_exists(NULL, NULL);
|
||||||
|
|
||||||
|
// This causes the tenth of the ten passes asserted in
|
||||||
|
// confirmStubResults().
|
||||||
|
$this->assertNothing();
|
||||||
|
|
||||||
|
// This causes the debug message asserted in confirmStubResults().
|
||||||
debug('Foo', 'Debug');
|
debug('Foo', 'Debug');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +288,7 @@ class SimpleTestTest extends WebTestBase {
|
||||||
|
|
||||||
$this->assertAssertion("Debug: 'Foo'", 'Debug', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
|
$this->assertAssertion("Debug: 'Foo'", 'Debug', 'Fail', 'SimpleTestTest.php', 'Drupal\simpletest\Tests\SimpleTestTest->stubTest()');
|
||||||
|
|
||||||
$this->assertEqual('6 passes, 5 fails, 2 exceptions, 1 debug message', $this->childTestResults['summary']);
|
$this->assertEqual('10 passes, 5 fails, 2 exceptions, 1 debug message', $this->childTestResults['summary']);
|
||||||
|
|
||||||
$this->test_ids[] = $test_id = $this->getTestIdFromResults();
|
$this->test_ids[] = $test_id = $this->getTestIdFromResults();
|
||||||
$this->assertTrue($test_id, 'Found test ID in results.');
|
$this->assertTrue($test_id, 'Found test ID in results.');
|
||||||
|
|
|
@ -819,7 +819,8 @@ abstract class WebTestBase extends TestBase {
|
||||||
// Copy and prepare an actual settings.php, so as to resemble a regular
|
// Copy and prepare an actual settings.php, so as to resemble a regular
|
||||||
// installation.
|
// installation.
|
||||||
// Not using File API; a potential error must trigger a PHP warning.
|
// Not using File API; a potential error must trigger a PHP warning.
|
||||||
copy(DRUPAL_ROOT . '/sites/default/default.settings.php', DRUPAL_ROOT . '/' . $this->siteDirectory . '/settings.php');
|
$directory = DRUPAL_ROOT . '/' . $this->siteDirectory;
|
||||||
|
copy(DRUPAL_ROOT . '/sites/default/default.settings.php', $directory . '/settings.php');
|
||||||
|
|
||||||
// All file system paths are created by System module during installation.
|
// All file system paths are created by System module during installation.
|
||||||
// @see system_requirements()
|
// @see system_requirements()
|
||||||
|
@ -844,6 +845,21 @@ abstract class WebTestBase extends TestBase {
|
||||||
);
|
);
|
||||||
$this->writeSettings($settings);
|
$this->writeSettings($settings);
|
||||||
|
|
||||||
|
// Allow for test-specific overrides.
|
||||||
|
$settings_testing_file = DRUPAL_ROOT . '/' . $this->originalSite . '/settings.testing.php';
|
||||||
|
if (file_exists($settings_testing_file)) {
|
||||||
|
// Copy the testing-specific settings.php overrides in place.
|
||||||
|
copy($settings_testing_file, $directory . '/settings.testing.php');
|
||||||
|
// Add the name of the testing class to settings.php and include the
|
||||||
|
// testing specific overrides
|
||||||
|
file_put_contents($directory . '/settings.php', "\n\$test_class = '" . get_class($this) ."';\n" . 'include DRUPAL_ROOT . \'/\' . $conf_path . \'/settings.testing.php\';' ."\n", FILE_APPEND);
|
||||||
|
}
|
||||||
|
$settings_services_file = DRUPAL_ROOT . '/' . $this->originalSite . '/testing.services.yml';
|
||||||
|
if (file_exists($settings_services_file)) {
|
||||||
|
// Copy the testing-specific service overrides in place.
|
||||||
|
copy($settings_services_file, $directory . '/services.yml');
|
||||||
|
}
|
||||||
|
|
||||||
// Since Drupal is bootstrapped already, install_begin_request() will not
|
// Since Drupal is bootstrapped already, install_begin_request() will not
|
||||||
// bootstrap into DRUPAL_BOOTSTRAP_CONFIGURATION (again). Hence, we have to
|
// bootstrap into DRUPAL_BOOTSTRAP_CONFIGURATION (again). Hence, we have to
|
||||||
// reload the newly written custom settings.php manually.
|
// reload the newly written custom settings.php manually.
|
||||||
|
@ -865,7 +881,7 @@ abstract class WebTestBase extends TestBase {
|
||||||
// directory has to be writable.
|
// directory has to be writable.
|
||||||
// TestBase::restoreEnvironment() will delete the entire site directory.
|
// TestBase::restoreEnvironment() will delete the entire site directory.
|
||||||
// Not using File API; a potential error must trigger a PHP warning.
|
// Not using File API; a potential error must trigger a PHP warning.
|
||||||
chmod(DRUPAL_ROOT . '/' . $this->siteDirectory, 0777);
|
chmod($directory, 0777);
|
||||||
|
|
||||||
$this->rebuildContainer();
|
$this->rebuildContainer();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue