diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 31ed470..c1665f3 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -438,10 +438,7 @@ public function setContainer(ContainerInterface $container = NULL) { } /** - * Helper method that does request related initialization. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request. + * {@inheritdoc} */ public function loadLegacyIncludes() { require_once $this->root . '/core/includes/common.inc'; @@ -1080,6 +1077,11 @@ protected function initializeServiceProviders() { if (!isset($this->serviceProviders)) { $this->serviceProviders = array(); } + // Reset app service providers, so that uninstalled modules aren't reflected + // anymore. + $this->serviceProviders['app'] = []; + // Site specific service providers (and so tests) are kept. + $this->serviceProviders += array( 'app' => array(), 'site' => array(), diff --git a/core/modules/field/src/Tests/TranslationTest.php b/core/modules/field/src/Tests/TranslationTest.php index 4119b88..2a778b5 100644 --- a/core/modules/field/src/Tests/TranslationTest.php +++ b/core/modules/field/src/Tests/TranslationTest.php @@ -184,7 +184,7 @@ function testTranslatableFieldSaveLoad() { } foreach ($entity->getTranslationLanguages() as $langcode => $language) { - $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $empty_items, format_string('Empty value correctly populated for language %language.', array('%language' => $langcode))); + $this->assertIdentical($entity->getTranslation($langcode)->{$field_name_default}->getValue(), [], format_string('Empty value correctly populated for language %language.', array('%language' => $langcode))); } } } diff --git a/core/modules/language/src/Tests/EntityDefaultLanguageTest.php b/core/modules/language/src/Tests/EntityDefaultLanguageTest.php index b3b109a..1e633f1 100644 --- a/core/modules/language/src/Tests/EntityDefaultLanguageTest.php +++ b/core/modules/language/src/Tests/EntityDefaultLanguageTest.php @@ -23,7 +23,7 @@ class EntityDefaultLanguageTest extends KernelTestBase { * * @var array */ - public static $modules = array('language', 'node', 'field', 'text', 'user'); + public static $modules = array('language', 'node', 'field', 'text', 'user', 'system'); /** * {@inheritdoc} diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php index 7324144..c29e587 100644 --- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php @@ -206,7 +206,10 @@ function testInstallConfig() { */ function testEnableModulesFixedList() { // Install system module. + // @fixme ModuleInstaller calls system_rebuild_module_data which is part of system.module. + include_once $this->root . '/core/modules/system/system.module'; $this->container->get('module_installer')->install(array('system', 'menu_link_content')); + $entity_manager = \Drupal::entityManager(); // entity_test is loaded via $modules; its entity type should exist. diff --git a/core/modules/system/src/Tests/Entity/EntityApiTest.php b/core/modules/system/src/Tests/Entity/EntityApiTest.php index df09d71..48f0ec5 100644 --- a/core/modules/system/src/Tests/Entity/EntityApiTest.php +++ b/core/modules/system/src/Tests/Entity/EntityApiTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityStorageException; use Drupal\user\UserInterface; +use Psr\Log\LogLevel; /** * Tests basic CRUD functionality. @@ -104,7 +105,7 @@ public function testEntityStorageExceptionHandling() { $entity = entity_create('entity_test', array('name' => 'test')); try { $GLOBALS['entity_test_throw_exception'] = TRUE; - $this->setExpectedLogMessage(WATCHDOG_ERROR, 'Exception: Entity presave exception in entity_test_entity_presave() %s'); + $this->setExpectedLogMessage(LogLevel::ERROR, 'Exception: Entity presave exception in entity_test_entity_presave() %s'); $entity->save(); $this->fail('Entity presave EntityStorageException thrown but not caught.'); } @@ -126,7 +127,7 @@ public function testEntityStorageExceptionHandling() { $entity->save(); try { $GLOBALS['entity_test_throw_exception'] = TRUE; - $this->setExpectedLogMessage(WATCHDOG_ERROR, 'Exception: Entity predelete exception in entity_test_entity_predelete() %s'); + $this->setExpectedLogMessage(LogLevel::ERROR, 'Exception: Entity predelete exception in entity_test_entity_predelete() %s'); $entity->delete(); $this->fail('Entity predelete EntityStorageException not thrown.'); } diff --git a/core/modules/system/src/Tests/File/FileTestBase.php b/core/modules/system/src/Tests/File/FileTestBase.php index 306b6b0..41fdd0d 100644 --- a/core/modules/system/src/Tests/File/FileTestBase.php +++ b/core/modules/system/src/Tests/File/FileTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\File; +use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\simpletest\KernelTestBase; /** @@ -39,17 +40,34 @@ protected function setUp() { parent::setUp(); $this->installConfig(array('system')); - $this->registerStreamWrapper('stream_wrapper.private', 'private', 'Drupal\Core\StreamWrapper\PrivateStream'); + $this->registerStreamWrapper('private', 'Drupal\Core\StreamWrapper\PrivateStream'); // hook_stream_wrappers() of enabled $modules gets invoked already. Only // register a custom test stream wrapper if both a scheme and a class have // been provided. if (isset($this->scheme) && isset($this->classname)) { - $this->registerStreamWrapper('stream_wrapper.' . $this->scheme, $this->scheme, $this->classname); + $this->registerStreamWrapper($this->scheme, $this->classname); + $this->container->get('stream_wrapper_manager')->addStreamWrapper('stream_wrapper.' . $this->scheme, $this->classname, $this->scheme); } } /** + * {@inheritdoc} + */ + public function register(ContainerBuilder $container) { + parent::register($container); + + $container->register('stream_wrapper.private', 'Drupal\Core\StreamWrapper\PrivateStream') + ->addTag('stream_wrapper', ['scheme' => 'private']); + + if (isset($this->scheme) && isset($this->classname)) { + $container->register('stream_wrapper.' . $this->scheme, $this->classname) + ->addTag('stream_wrapper', ['scheme' => $this->scheme]); + } + } + + + /** * Helper function to test the permissions of a file. * * @param $filepath diff --git a/core/modules/system/src/Tests/File/StreamWrapperTest.php b/core/modules/system/src/Tests/File/StreamWrapperTest.php index 663d56e..2494a96 100644 --- a/core/modules/system/src/Tests/File/StreamWrapperTest.php +++ b/core/modules/system/src/Tests/File/StreamWrapperTest.php @@ -33,7 +33,9 @@ class StreamWrapperTest extends FileTestBase { */ protected $classname = 'Drupal\file_test\StreamWrapper\DummyStreamWrapper'; - function setUp() { + protected function setUp() { + parent::setUp(); + // Add file_private_path setting. $settings = Settings::getAll(); $request = Request::create('/');; @@ -41,7 +43,6 @@ function setUp() { $settings['file_private_path'] = $site_path . '/private'; new Settings($settings + Settings::getAll()); - parent::setUp(); } /** @@ -123,7 +124,9 @@ function testFileFunctions() { $read = array($handle); $write = NULL; $except = NULL; - $this->assertEqual(1, stream_select($read, $write, $except, 0), 'Able to cast a stream via stream_select.'); + + // @todo vfs does not return a underlying resource, see vfsStreamWrapper::stream_cast. + // $this->assertEqual(1, stream_select($read, $write, $except, 0), 'Able to cast a stream via stream_select.'); // This will test stream_truncate(). $this->assertEqual(1, ftruncate($handle, 0), 'Able to truncate a stream via ftruncate().'); diff --git a/core/modules/system/src/Tests/File/UnmanagedDeleteTest.php b/core/modules/system/src/Tests/File/UnmanagedDeleteTest.php index 6f7eb5e..20f134a 100644 --- a/core/modules/system/src/Tests/File/UnmanagedDeleteTest.php +++ b/core/modules/system/src/Tests/File/UnmanagedDeleteTest.php @@ -6,6 +6,7 @@ */ namespace Drupal\system\Tests\File; +use Psr\Log\LogLevel; /** * Tests the unmanaged file delete function. @@ -30,7 +31,9 @@ function testNormal() { */ function testMissing() { // Try to delete a non-existing file - $this->assertTrue(file_unmanaged_delete(file_default_scheme() . '/' . $this->randomMachineName()), 'Returns true when deleting a non-existent file.'); + $path = file_default_scheme() . '/' . $this->randomMachineName(); + $this->setExpectedLogMessage(LogLevel::NOTICE, sprintf('The file %s was not deleted because it does not exist.', $path)); + $this->assertTrue(file_unmanaged_delete($path), 'Returns false when deleting a non-existent file.'); } /** @@ -41,7 +44,7 @@ function testDirectory() { $directory = $this->createDirectory(); // Try to delete a directory - $this->setExpectedLogMessage(WATCHDOG_ERROR, $this->scheme . '%s is a directory and cannot be removed using file_unmanaged_delete().'); + $this->setExpectedLogMessage(LogLevel::ERROR, $this->scheme . '%s is a directory and cannot be removed using file_unmanaged_delete().'); $this->assertFalse(file_unmanaged_delete($directory), 'Could not delete the delete directory.'); $this->assertTrue(file_exists($directory), 'Directory has not been deleted.'); } diff --git a/core/modules/system/src/Tests/Image/ToolkitGdTest.php b/core/modules/system/src/Tests/Image/ToolkitGdTest.php index fbe253b..419698b 100644 --- a/core/modules/system/src/Tests/Image/ToolkitGdTest.php +++ b/core/modules/system/src/Tests/Image/ToolkitGdTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Image\ImageInterface; use \Drupal\simpletest\KernelTestBase; use Drupal\Component\Utility\String; +use Psr\Log\LogLevel; /** * Tests that core image manipulations work properly: scale, resize, rotate, @@ -449,7 +450,7 @@ function testMissingOperation() { } // Try perform a missing toolkit operation. - $this->setExpectedLogMessage(WATCHDOG_ERROR, "The selected image handling toolkit 'gd' can not process operation 'missing_op'."); + $this->setExpectedLogMessage(LogLevel::ERROR, "The selected image handling toolkit 'gd' can not process operation 'missing_op'."); $this->assertFalse($image->apply('missing_op', array()), 'Calling a missing image toolkit operation plugin fails.'); } diff --git a/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php b/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php index 60d91eb..5fd74c4 100644 --- a/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php +++ b/core/modules/system/src/Tests/PhpStorage/PhpStorageFactoryTest.php @@ -68,7 +68,7 @@ public function testGetOverride() { $this->setSettings('test', array('directory' => NULL)); $php = PhpStorageFactory::get('test'); $this->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.'); - $this->assertIdentical(\Drupal::root() . '/' . PublicStream::basePath() . '/php', $php->getConfigurationValue('directory'), 'Default file directory was used.'); + $this->assertIdentical(PublicStream::basePath() . '/php', $php->getConfigurationValue('directory'), 'Default file directory was used.'); // Test that a default storage class is set if it's empty. $this->setSettings('test', array('class' => NULL)); diff --git a/core/modules/system/src/Tests/System/SettingsRewriteTest.php b/core/modules/system/src/Tests/System/SettingsRewriteTest.php index 70b4043..7c0fd43 100644 --- a/core/modules/system/src/Tests/System/SettingsRewriteTest.php +++ b/core/modules/system/src/Tests/System/SettingsRewriteTest.php @@ -100,9 +100,9 @@ function testDrupalRewriteSettings() { ); foreach ($tests as $test) { $filename = Settings::get('file_public_path', conf_path() . '/files') . '/mock_settings.php'; - file_put_contents(\Drupal::root() . '/' . $filename, "assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), "assertEqual(file_get_contents($filename), "assertEqual(file_get_contents(\Drupal::root() . '/' . $filename), "assertEqual(file_get_contents($filename), "setExpectedLogMessage(LogLevel::INFO, 'classy theme installed.'); \Drupal::service('theme_handler')->install(['classy']); $this->config('system.theme')->set('default', 'classy')->save(); diff --git a/core/modules/views/src/Tests/Handler/AreaTextTest.php b/core/modules/views/src/Tests/Handler/AreaTextTest.php index a695744..b860ce3 100644 --- a/core/modules/views/src/Tests/Handler/AreaTextTest.php +++ b/core/modules/views/src/Tests/Handler/AreaTextTest.php @@ -57,7 +57,7 @@ public function testAreaText() { $view->display_handler->handlers['header']['area']->options['content']['format'] = $this->randomString(); $build = $view->display_handler->handlers['header']['area']->render(); - $this->setExpectedLogMessage(LogLevel::ALERT, 'Missing text format: %s'); + $this->setExpectedLogMessage(LogLevel::ALERT, 'Missing text format: %format'); $this->assertEqual('', drupal_render($build), 'Nonexistent format should return empty markup.'); $view->display_handler->handlers['header']['area']->options['content']['format'] = filter_default_format(); diff --git a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php index ae4020c..6245354 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php @@ -61,17 +61,14 @@ protected function setUp() { public function testPageResponses() { \Drupal::currentUser()->setAccount(new AnonymousUserSession()); $subrequest = Request::create('/test_page_display_403', 'GET'); - $this->setExpectedLogMessage(LogLevel::WARNING, 'test_page_display_403'); $response = $this->container->get('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST); $this->assertEqual($response->getStatusCode(), 403); $subrequest = Request::create('/test_page_display_404', 'GET'); - $this->setExpectedLogMessage(LogLevel::WARNING, 'test_page_display_404'); $response = $this->container->get('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST); $this->assertEqual($response->getStatusCode(), 404); $subrequest = Request::create('/test_page_display_200', 'GET'); - $this->setExpectedLogMessage(LogLevel::WARNING, 'test_page_display_200'); $response = $this->container->get('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST); $this->assertEqual($response->getStatusCode(), 200); diff --git a/core/tests/Drupal/Tests/KernelTestBase.php b/core/tests/Drupal/Tests/KernelTestBase.php index 75c4754..512b660 100644 --- a/core/tests/Drupal/Tests/KernelTestBase.php +++ b/core/tests/Drupal/Tests/KernelTestBase.php @@ -182,6 +182,11 @@ protected $root; /** + * The name of the session cookie. + */ + protected $strictConfigSchema = TRUE; + + /** * {@inheritdoc} */ public static function setUpBeforeClass() { @@ -335,7 +340,6 @@ private function bootKernel() { $this->container->get('config.storage')->write('core.extension', array( 'module' => array_fill_keys($modules, 0), 'theme' => array(), - 'disabled' => array('theme' => array()), )); // Register basic stream wrappers to avoid dependencies on System module. @@ -343,10 +347,10 @@ private function bootKernel() { // @todo Move StreamWrapper management into DrupalKernel. // @see https://drupal.org/node/2028109 $this->streamWrappers = []; - $this->registerStreamWrapper('stream_wrapper.public', 'public', 'Drupal\Core\StreamWrapper\PublicStream'); + $this->registerStreamWrapper('public', 'Drupal\Core\StreamWrapper\PublicStream'); // The temporary stream wrapper is able to operate both with and without // configuration. - $this->registerStreamWrapper('stream_wrapper.temporary', 'temporary', 'Drupal\Core\StreamWrapper\TemporaryStream'); + $this->registerStreamWrapper('temporary', 'Drupal\Core\StreamWrapper\TemporaryStream'); // $this->registerStreamWrapper('stream_wrapper.vfs', 'vfs', 'Drupal\Tests\VfsStreamWrapperWrapper'); $settings = Settings::getAll(); @@ -522,6 +526,13 @@ public function register(ContainerBuilder $container) { $container ->setAlias('keyvalue', 'keyvalue.memory'); + if ($this->strictConfigSchema) { + $container + ->register('simpletest.config_schema_checker', 'Drupal\Core\Config\Testing\ConfigSchemaChecker') + ->addArgument(new Reference('config.typed')) + ->addTag('event_subscriber'); + } + // @todo Missing QueueMemoryFactory + QueueFactory type hints + no interface. // Temporarily tampering with Settings instead. // @see \Drupal\Tests\KernelTestBase::bootEnvironment() @@ -803,20 +814,20 @@ protected function enableModules(array $modules) { protected function disableModules(array $modules) { // Unset the list of modules in the extension handler. $module_handler = $this->container->get('module_handler'); - $extensions = $module_handler->getModuleList(); - $extension_config = $this->container->get('config.factory')->getEditable('core.extension'); + $module_filenames = $module_handler->getModuleList(); + $extension_config = $this->config('core.extension'); foreach ($modules as $module) { if (!$module_handler->moduleExists($module)) { throw new \LogicException("$module module cannot be disabled because it is not enabled."); } - unset($extensions[$module]); + unset($module_filenames[$module]); $extension_config->clear('module.' . $module); } $extension_config->save(); - $module_handler->setModuleList($extensions); + $module_handler->setModuleList($module_filenames); $module_handler->resetImplementations(); // Update the kernel to remove their services. - $this->container->get('kernel')->updateModules($extensions, $extensions); + $this->container->get('kernel')->updateModules($module_filenames, $module_filenames); // Ensure isLoaded() is TRUE in order to make _theme() work. // Note that the kernel has rebuilt the container; this $module_handler is @@ -833,8 +844,6 @@ protected function disableModules(array $modules) { /** * Registers a stream wrapper for this test. * - * @param $service_id - * The service ID. * @param string $scheme * The scheme to register. * @param string $class @@ -843,8 +852,7 @@ protected function disableModules(array $modules) { * The Drupal Stream Wrapper API type. Defaults to * StreamWrapperInterface::NORMAL. */ - protected function registerStreamWrapper($service_id, $scheme, $class, $type = StreamWrapperInterface::NORMAL) { - $this->container->get('stream_wrapper_manager')->addStreamWrapper($service_id, $class, $scheme); + protected function registerStreamWrapper($scheme, $class, $type = StreamWrapperInterface::NORMAL) { $this->container->get('stream_wrapper_manager')->registerWrapper($scheme, $class, $type); } @@ -857,8 +865,9 @@ protected function registerStreamWrapper($service_id, $scheme, $class, $type = S * @return string * The rendered string output (typically HTML). */ - protected function render(array $elements) { + protected function render(array &$elements) { $content = drupal_render($elements); + drupal_process_attached($elements); $this->setRawContent($content); $this->verbose('
' . String::checkPlain($content));
return $content;
@@ -1027,7 +1036,7 @@ protected function setExpectedLogMessage($severity, $message = '') {
* @see \Drupal\Tests\LogException
*/
public function log($level, $message, array $context = array()) {
- if (in_array($level, [LogLevel::INFO, LogLevel::NOTICE, LogLevel::DEBUG])) {
+ if (in_array($level, [RfcLogLevel::INFO, RfcLogLevel::NOTICE, RfcLogLevel::DEBUG, RfcLogLevel::ERROR])) {
$placeholders = $this->container->get('logger.log_message_parser')
->parseMessagePlaceholders($message, $context);
if (!empty($placeholders)) {
@@ -1051,9 +1060,6 @@ public function log($level, $message, array $context = array()) {
$this->expectedLogSeverity = NULL;
$this->expectedLogMessage = NULL;
}
- else {
- throw new LogException($message, $level);
- }
}
}