diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index efab3b1..1543d27 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -532,13 +532,9 @@ public function discoverServiceProviders() { // Add site-specific service providers. if (!empty($GLOBALS['conf']['container_service_providers'])) { - foreach ($GLOBALS['conf']['container_service_providers'] as $key => $class) { - if (is_object($class)) { - $this->serviceProviderClasses['site'][$key] = get_class($class); - $this->serviceProviders['site'][$key] = $class; - } - elseif (class_exists($class)) { - $this->serviceProviderClasses['site'][$key] = $class; + foreach ($GLOBALS['conf']['container_service_providers'] as $class) { + if (is_object($class) || class_exists($class)) { + $this->serviceProviderClasses['site'][] = $class; } } } @@ -1080,9 +1076,12 @@ protected function initializeServiceProviders() { ); foreach ($this->serviceProviderClasses as $origin => $classes) { foreach ($classes as $name => $class) { - if (!isset($this->serviceProviders[$origin][$name])) { + if (!is_object($class)) { $this->serviceProviders[$origin][$name] = new $class; } + else { + $this->serviceProviders[$origin][$name] = $class; + } } } } diff --git a/core/lib/Drupal/Core/Render/ElementInfoManager.php b/core/lib/Drupal/Core/Render/ElementInfoManager.php index 7af0b0d..64bbb05 100644 --- a/core/lib/Drupal/Core/Render/ElementInfoManager.php +++ b/core/lib/Drupal/Core/Render/ElementInfoManager.php @@ -80,11 +80,12 @@ public function getInfo($type) { if (!isset($this->elementInfo[$theme_name])) { $this->elementInfo[$theme_name] = $this->buildInfo($theme_name); } - - if (isset($this->elementInfo[$type])) { - $info = $this->elementInfo[$type]; + $info = []; + if (isset($this->elementInfo[$theme_name][$type])) { + $info = $this->elementInfo[$theme_name][$type]; $info['#defaults_loaded'] = TRUE; } + return $info; } diff --git a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php index b708f4b..f710bf1 100644 --- a/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php +++ b/core/modules/system/src/Tests/Extension/ModuleHandlerTest.php @@ -21,6 +21,16 @@ class ModuleHandlerTest extends KernelTestBase { /** * {@inheritdoc} */ + protected function setUp() { + parent::setUp(); + + // @fixme ModuleInstaller calls system_rebuild_module_data which is part of system.module. + include_once $this->root . '/core/modules/system/system.module'; + } + + /** + * {@inheritdoc} + */ public function containerBuild(ContainerBuilder $container) { parent::containerBuild($container); // Put a fake route bumper on the container to be called during uninstall. @@ -36,9 +46,6 @@ function testModuleList() { $this->assertModuleList($module_list, 'Initial'); - // @fixme ModuleInstaller calls system_rebuild_module_data which is part of system.module. - include_once $this->root . '/core/modules/system/system.module'; - // Try to install a new module. $this->moduleInstaller()->install(array('ban')); $module_list[] = 'ban'; @@ -73,7 +80,7 @@ function testModuleList() { protected function assertModuleList(Array $expected_values, $condition) { $expected_values = array_values(array_unique($expected_values)); $enabled_modules = array_keys($this->container->get('module_handler')->getModuleList()); - $this->assertIdentical($enabled_modules, $expected_values, format_string('@condition: extension handler returns correct results', array('@condition' => $condition))); + $this->assertEqual($expected_values, $enabled_modules, format_string('@condition: extension handler returns correct results', array('@condition' => $condition))); } /** diff --git a/core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php b/core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php index 75b59ca..aa2ce25 100644 --- a/core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php @@ -136,7 +136,6 @@ public function providerTestGetInfo() { $data[] = array( 'form', array( - '#defaults_loaded' => TRUE, ), array('page' => array( '#theme' => 'page', diff --git a/core/tests/Drupal/Tests/KernelTestBase.php b/core/tests/Drupal/Tests/KernelTestBase.php index aa2769a..38c0590 100644 --- a/core/tests/Drupal/Tests/KernelTestBase.php +++ b/core/tests/Drupal/Tests/KernelTestBase.php @@ -54,11 +54,10 @@ * @todo Extend ::setRequirementsFromAnnotation() and ::checkRequirements() to * account for '@requires module'. */ -abstract class KernelTestBase extends \PHPUnit_Framework_TestCase implements ServiceProviderInterface, LoggerInterface { +abstract class KernelTestBase extends \PHPUnit_Framework_TestCase implements ServiceProviderInterface { use AssertLegacyTrait; use AssertContentTrait; - use LoggerTrait; use RandomGeneratorTrait; /** @@ -155,17 +154,17 @@ * * @var array */ - private $streamWrappers = array(); + protected $streamWrappers = array(); /** * @var int */ - private $expectedLogSeverity; + protected $expectedLogSeverity; /** * @var string */ - private $expectedLogMessage; + protected $expectedLogMessage; /** * @todo Move into Config test base class. @@ -364,8 +363,6 @@ private function bootKernel() { $this->container->get('module_handler')->loadAll(); } - $this->container->set('test.logger', $this); - // Write the core.extension configuration. // Required for ConfigInstaller::installDefaultConfig() to work. $this->container->get('config.storage')->write('core.extension', array( @@ -551,6 +548,7 @@ private function getExtensionsForModules(array $modules) { * @see \Drupal\Tests\KernelTestBase::bootKernel() */ public function register(ContainerBuilder $container) { + // Keep the container object around for tests. $this->container = $container; $container @@ -599,11 +597,6 @@ public function register(ContainerBuilder $container) { // @todo Remove this BC layer. $this->containerBuild($container); - - $container - ->register('test.logger', __CLASS__) - ->setSynthetic(TRUE) - ->addTag('logger'); } /** @@ -635,14 +628,6 @@ protected function assertPostConditions() { // Fail in case any (new) shutdown functions exist. $this->assertCount(0, drupal_register_shutdown_function(), 'Unexpected Drupal shutdown callbacks exist after running shutdown functions.'); - // Verify that any expected log message was logged. - if (isset($this->expectedLogSeverity)) { - $this->fail(vsprintf("Failed to assert expected log message:\n%s: %s", array( - $this->logSeverityToString($this->expectedLogSeverity), - $this->expectedLogMessage ?: '(no message)', - ))); - } - parent::assertPostConditions(); } @@ -1045,92 +1030,6 @@ protected function copyConfig(StorageInterface $source_storage, StorageInterface } /** - * Sets an expected severe log message. - * - * @param int $severity - * The expected log level severity constant (WATCHDOG_*). - * @param string $message - * (optional) The expected log message to assert via - * \PHPUnit_Framework_Assert::assertStringMatchesFormat(). - * - * @see \Drupal\Tests\KernelTestBase::log() - * - * @todo Add support for `@expectedLogMessage*` test method annotations. - */ - protected function setExpectedLogMessage($severity, $message = '') { - // Provide mapping from PSR log level to RFC log level. - $mapping = [ - LogLevel::EMERGENCY => RfcLogLevel::EMERGENCY, - LogLevel::ALERT => RfcLogLevel::ALERT, - LogLevel::CRITICAL => RfcLogLevel::CRITICAL, - LogLevel::ERROR => RfcLogLevel::ERROR, - LogLevel::WARNING => RfcLogLevel::WARNING, - LogLevel::NOTICE => RfcLogLevel::NOTICE, - LogLevel::INFO => RfcLogLevel::INFO, - LogLevel::DEBUG => RfcLogLevel::DEBUG, - ]; - if (isset($mapping[$severity])) { - $severity = $mapping[$severity]; - } - - $this->expectedLogSeverity = $severity; - $this->expectedLogMessage = $message; - } - - /** - * {@inheritdoc} - * - * @see \Drupal\Tests\KernelTestBase::setExpectedLogMessage() - * @see \Drupal\Tests\LogException - */ - public function log($level, $message, array $context = array()) { - if (in_array($level, [RfcLogLevel::INFO, RfcLogLevel::NOTICE, RfcLogLevel::DEBUG, RfcLogLevel::ERROR, RfcLogLevel::ALERT])) { - $placeholders = $this->container->get('logger.log_message_parser') - ->parseMessagePlaceholders($message, $context); - if (!empty($placeholders)) { - $message = strtr($message, $placeholders); - } - - // Assert an expected log message. - if (isset($this->expectedLogSeverity)) { - if (!empty($this->expectedLogMessage)) { - $this->expectedLogMessage = $this->logSeverityToString($this->expectedLogSeverity) . ': ' . $this->expectedLogMessage; - $message = $this->logSeverityToString($level) . ': ' . $message; - $this->assertStringMatchesFormat($this->expectedLogMessage, $message); - } - else { - $this->assertSame($this->expectedLogSeverity, $level, vsprintf("Expected log message severity '%s' does not match actual severity '%s'.", array( - $this->logSeverityToString($this->expectedLogSeverity), - $this->logSeverityToString($level), - ))); - } - // If the test did not fail (and thus stop), reset the properties. - $this->expectedLogSeverity = NULL; - $this->expectedLogMessage = NULL; - } - } - } - - /** - * Returns a string presentation of a log severity constant. - * - * @param int $severity - * The WATCHDOG_* log severity constant to translate. - * - * @return string - * - * @throws \LogicException - * If $severity is unknown. - */ - private function logSeverityToString($severity) { - $names = ['EMERGENCY', 'ALERT', 'CRITICAL', 'ERROR', 'WARNING', 'NOTICE', 'INFO', 'DEBUG']; - if (isset($names[$severity])) { - return 'WATCHDOG_' . $names[$severity]; - } - throw new \LogicException("Unknown log message severity '$severity'"); - } - - /** * Stops test execution. */ protected function stop() { diff --git a/core/tests/Drupal/Tests/KernelTestBaseTest.php b/core/tests/Drupal/Tests/KernelTestBaseTest.php index a0deb43..e9bc882 100644 --- a/core/tests/Drupal/Tests/KernelTestBaseTest.php +++ b/core/tests/Drupal/Tests/KernelTestBaseTest.php @@ -106,10 +106,7 @@ public function testSetUp() { public function testSetUpDoesNotLeak() { $this->assertArrayNotHasKey('destroy-me', $GLOBALS); - $expected = [ - 'config' => 'config', - 'cachetags' => 'cachetags', - ]; + $expected = []; $schema = $this->container->get('database')->schema(); $this->assertEquals($expected, $schema->findTables('%')); } @@ -211,17 +208,6 @@ public function testRenderWithTheme() { } /** - * @covers ::log - * @expectedException \ErrorException - * @expectedExceptionCode WATCHDOG_WARNING - * @expectedExceptionMessage Some problem. - */ - public function testLog() { - $this->container->get('logger.factory')->get('system')->notice('Not a problem.'); - $this->container->get('logger.factory')->get('system')->notice('Some problem.'); - } - - /** * @covers ::__get * @covers ::__set * @expectedException \RuntimeException @@ -234,10 +220,7 @@ public function test__get($property) { public function provider__get() { return [ ['originalWhatever'], - ['public_files_directory'], - ['private_files_directory'], ['temp_files_directory'], - ['translation_files_directory'], ['generatedTestFiles'], ]; } diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index b030926..5718df6 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -22,7 +22,8 @@ function drupal_phpunit_find_extension_directories($scan_directory) { foreach ($dirs as $dir) { if (strpos($dir->getPathname(), '.info.yml') !== FALSE) { // Cut off ".info.yml" from the filename for use as the extension name. - $extensions[substr($dir->getFilename(), 0, -9)] = $dir->getPathInfo()->getRealPath(); + $extensions[substr($dir->getFilename(), 0, -9)] = $dir->getPathInfo() + ->getRealPath(); } } return $extensions; @@ -43,19 +44,16 @@ function drupal_phpunit_contrib_extension_directory_roots() { $root . '/profiles', ); $sites_path = $root . '/sites'; + // Note this also checks sites/../modules and sites/../profiles. foreach (scandir($sites_path) as $site) { if ($site[0] === '.' || $site === 'simpletest') { continue; } $path = "$sites_path/$site"; - if (is_dir("$path/modules")) { - $paths[] = "$path/modules"; - } - if (is_dir("$path/profiles")) { - $paths[] = "$path/profiles"; - } + $paths[] = is_dir("$path/modules") ? realpath("$path/modules") : NULL; + $paths[] = is_dir("$path/profiles") ? realpath("$path/profiles") : NULL; } - return $paths; + return array_filter($paths); } /** @@ -73,7 +71,7 @@ function drupal_phpunit_get_extension_namespaces($dirs) { } if (is_dir($dir . '/tests/src')) { // Register the PSR-4 directory for PHPUnit test classes. - $namespaces['Drupal\\' . $extension . '\Tests\\'][] = $dir . '/tests/src'; + $namespaces['Drupal\\Tests\\' . $extension . '\\'][] = $dir . '/tests/src'; } } return $namespaces;