Commit 48fb187d authored by catch's avatar catch

Issue #2196241 by sun, alexpott: Remove string translation services from TestBase container.

parent 40723e19
......@@ -8,8 +8,11 @@
namespace Drupal\simpletest;
use Drupal\Core\DrupalKernel;
use Drupal\Core\Language\Language;
use Drupal\Core\Session\UserSession;
use Drupal\Core\Site\Settings;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -94,6 +97,25 @@ protected function setUp() {
// @see WebTestBase::translatePostValues()
$this->parameters = $this->installParameters();
// Set up a minimal container (required by WebTestBase).
// @see install_begin_request()
$request = Request::create($GLOBALS['base_url'] . '/core/install.php');
$this->container = new ContainerBuilder();
$this->container
->set('request', $request);
$this->container
->setParameter('language.default_values', Language::$defaultValues);
$this->container
->register('language.default', 'Drupal\Core\Language\LanguageDefault')
->addArgument('%language.default_values%');
$this->container
->register('language_manager', 'Drupal\Core\Language\LanguageManager')
->addArgument(new Reference('language.default'));
$this->container
->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager')
->addArgument(new Reference('language_manager'));
\Drupal::setContainer($this->container);
$this->drupalGet($GLOBALS['base_url'] . '/core/install.php');
// Select language.
......
......@@ -1071,29 +1071,9 @@ private function prepareEnvironment() {
// Reset statics.
drupal_static_reset();
// Reset and create a new service container.
$this->container = new ContainerBuilder();
// @todo Remove this once this class has no calls to t() and format_plural()
$this->container->setParameter('language.default_values', Language::$defaultValues);
$this->container->register('language.default', 'Drupal\Core\Language\LanguageDefault')
->addArgument('%language.default_values%');
$this->container->register('language_manager', 'Drupal\Core\Language\LanguageManager')
->addArgument(new Reference('language.default'));
$this->container->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager')
->addArgument(new Reference('language_manager'));
// Register info parser.
$this->container->register('info_parser', 'Drupal\Core\Extension\InfoParser');
$request = Request::create('/');
$this->container->set('request', $request);
// Run all tests as a anonymous user by default, web tests will replace that
// during the test set up.
$this->container->set('current_user', new AnonymousUserSession());
\Drupal::setContainer($this->container);
// Ensure there is no service container.
$this->container = NULL;
\Drupal::setContainer(NULL);
// Unset globals.
unset($GLOBALS['config_directories']);
......@@ -1161,7 +1141,7 @@ private function restoreEnvironment() {
// which means they may need to access its filesystem and database.
drupal_static_reset();
if ($this->container->has('state') && $state = $this->container->get('state')) {
if ($this->container && $this->container->has('state') && $state = $this->container->get('state')) {
$captured_emails = $state->get('system.test_mail_collector') ?: array();
$emailCount = count($captured_emails);
if ($emailCount) {
......@@ -1236,9 +1216,6 @@ private function restoreEnvironment() {
// Restore original shutdown callbacks.
$callbacks = &drupal_register_shutdown_function();
$callbacks = $this->originalShutdownCallbacks;
// Restore original user session.
$this->container->set('current_user', $this->originalUser);
}
/**
......
......@@ -20,6 +20,6 @@ class MissingDependentModuleUnitTest extends UnitTestBase {
* Ensure that this test will not be loaded despite its dependency.
*/
function testFail() {
$this->fail(t('Running test with missing required module.'));
$this->fail('Running test with missing required module.');
}
}
......@@ -7,8 +7,7 @@
namespace Drupal\system\Tests\Common;
use Drupal\simpletest\UnitTestBase;
use Symfony\Component\HttpFoundation\Request;
use Drupal\simpletest\KernelTestBase;
/**
* Tests the functions drupal_html_class(), drupal_html_id() and
......@@ -16,19 +15,7 @@
*
* @group Common
*/
class HtmlIdentifierUnitTest extends UnitTestBase {
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$container = \Drupal::getContainer();
$request = new Request();
$container->set('request', $request);
\Drupal::setContainer($container);
}
class HtmlIdentifierUnitTest extends KernelTestBase {
/**
* Tests that drupal_clean_css_identifier() cleans the identifier properly.
*/
......
......@@ -8,7 +8,7 @@
namespace Drupal\system\Tests\Common;
use Drupal\Component\Utility\Bytes;
use Drupal\simpletest\UnitTestBase;
use Drupal\simpletest\KernelTestBase;
/**
* Parse a predefined amount of bytes and compare the output with the expected
......@@ -16,11 +16,12 @@
*
* @group Common
*/
class SizeUnitTest extends UnitTestBase {
class SizeUnitTest extends KernelTestBase {
protected $exact_test_cases;
protected $rounded_test_cases;
function setUp() {
parent::setUp();
$kb = Bytes::KILOBYTE;
$this->exact_test_cases = array(
'1 byte' => 1,
......@@ -40,7 +41,6 @@ function setUp() {
round(67234178751368124 / ($this->exact_test_cases['1 PB']), 2) . ' PB' => 67234178751368124, // petabytes
round(235346823821125814962843827 / ($this->exact_test_cases['1 YB']), 2) . ' YB' => 235346823821125814962843827, // yottabytes
);
parent::setUp();
}
/**
......
......@@ -8,7 +8,7 @@
namespace Drupal\system\Tests\Common;
use Drupal\Component\Utility\String;
use Drupal\simpletest\UnitTestBase;
use Drupal\simpletest\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -16,7 +16,7 @@
*
* @group Common
*/
class TableSortExtenderUnitTest extends UnitTestBase {
class TableSortExtenderUnitTest extends KernelTestBase {
/**
* Tests tablesort_init().
......
......@@ -8,12 +8,12 @@
namespace Drupal\system\Tests\Plugin\Discovery;
use Drupal\Core\StringTranslation\TranslationWrapper;
use Drupal\simpletest\UnitTestBase;
use Drupal\simpletest\KernelTestBase;
/**
* Base class for plugin discovery tests.
*/
abstract class DiscoveryTestBase extends UnitTestBase {
abstract class DiscoveryTestBase extends KernelTestBase {
/**
* The discovery component to test.
......@@ -46,7 +46,9 @@ function testDiscoveryInterface() {
// Ensure that getDefinitions() returns the expected definitions.
// For the arrays to be identical (instead of only equal), they must be
// sorted equally, which seems unnecessary here.
$this->assertEqual($this->discovery->getDefinitions(), $this->expectedDefinitions);
// The discovered definitions may contain circular references; use a custom
// assertion message to prevent var_export() from getting called.
$this->assertEqual($this->discovery->getDefinitions(), $this->expectedDefinitions, 'Expected definitions found.');
// Ensure that getDefinition() returns the expected definition.
foreach ($this->expectedDefinitions as $id => $definition) {
......
......@@ -8,7 +8,7 @@
namespace Drupal\system\Tests\Plugin;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\simpletest\UnitTestBase;
use Drupal\simpletest\KernelTestBase;
use Drupal\plugin_test\Plugin\TestPluginManager;
use Drupal\plugin_test\Plugin\MockBlockManager;
use Drupal\plugin_test\Plugin\DefaultsTestPluginManager;
......@@ -18,7 +18,15 @@
/**
* Base class for Plugin API unit tests.
*/
abstract class PluginTestBase extends UnitTestBase {
abstract class PluginTestBase extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('plugin_test');
protected $testPluginManager;
protected $testPluginExpectedDefinitions;
protected $mockBlockManager;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment