diff --git a/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php b/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php index 79ca932..c57ff91 100644 --- a/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php +++ b/core/tests/Drupal/Tests/Core/Theme/RegistryTest.php @@ -67,13 +67,6 @@ class RegistryTest extends UnitTestCase { protected $themeManager; /** - * The theme. - * - * @var \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $theme; - - /** * The list of functions that get_defined_functions() should provide. * * @var array @@ -182,34 +175,45 @@ public function testGetRegistryForModule() { } /** - * Sets up the mocks needed for testing Registry::postProcessExtension. + * @covers ::postProcessExtension + * + * @dataProvider providerTestPostProcessExtension + * + * @param array $defined_functions + * An array of functions to be used in place of get_defined_functions(). + * @param array $hooks + * An array of theme hooks to process. + * @param array $expected + * The expected results. */ - public function setUpPostProcessExtension() { - $this->theme = $this->getMockBuilder(ActiveTheme::class) - ->disableOriginalConstructor() - ->getMock(); - $this->theme->expects($this->atLeastOnce()) - ->method('getBaseThemes') - ->will($this->returnValue([])); - $this->theme->expects($this->atLeastOnce()) - ->method('getName') - ->will($this->returnValue('test')); + public function testPostProcessExtension($defined_functions, $hooks, $expected) { + static::$functions['user'] = $defined_functions; + + $theme = $this->prophesize(ActiveTheme::class); + $theme->getBaseThemes()->willReturn([]); + $theme->getName()->willReturn('test'); + $theme->getEngine()->willReturn('twig'); $this->moduleHandler->expects($this->atLeastOnce()) ->method('getModuleList') ->willReturn([]); + + $class = new \ReflectionClass(TestRegistry::class); + $reflection_method = $class->getMethod('postProcessExtension'); + $reflection_method->setAccessible(TRUE); + $reflection_method->invokeArgs($this->registry, [&$hooks, $theme->reveal()]); + + $this->assertArrayEquals($hooks, $expected); } /** - * Tests that preprocess functions are added when base hook is specified. - * - * @covers ::postProcessExtension + * Provides test data to ::testPostProcessExtension(). */ - public function testManualBaseHook() { - static::$functions['user'] = ['cat', 'mouse', 'cheese']; - - // Define a test case registry with mock data. - $hooks = [ + public function providerTestPostProcessExtension() { + $data = []; + $data['manual_base_hook'] = [ + 'defined_functions' => ['cat', 'mouse', 'cheese'], + 'hooks' => [ 'test_hook' => [ 'preprocess functions' => ['cat', 'mouse'], ], @@ -218,9 +222,8 @@ public function testManualBaseHook() { 'base hook' => 'test_hook', 'incomplete preprocess functions' => TRUE, ], - ]; - - $expected = [ + ], + 'expected' => [ 'test_hook' => [ 'preprocess functions' => ['cat', 'mouse'], ], @@ -228,27 +231,18 @@ public function testManualBaseHook() { 'preprocess functions' => ['cat', 'mouse', 'cheese'], 'base hook' => 'test_hook', ], + ], ]; - - $this->setUpPostProcessExtension(); - - $class = new \ReflectionClass(TestRegistry::class); - $reflection_method = $class->getMethod('postProcessExtension'); - $reflection_method->setAccessible(TRUE); - $reflection_method->invokeArgs($this->registry, [ &$hooks, $this->theme]); - - $this->assertArrayEquals($hooks, $expected); - } - - /** - * Tests that a suggestion defined in hook_theme gets preprocess functions. - * - * @covers ::postProcessExtension - */ - public function testManualSuggestion() { - $this->setUpPostProcessExtension(); - - $hooks = [ + $data['manual_suggestion'] = [ + 'defined_functions' => [ + 'cat', + 'mouse', + 'cheese', + 'bread', + 'test_preprocess_test_hook__suggestion', + 'test_preprocess_test_hook__suggestion__another', + ], + 'hooks' => [ 'test_hook' => [ 'preprocess functions' => ['cat', 'mouse'], 'template' => 'test-hook', @@ -261,9 +255,8 @@ public function testManualSuggestion() { 'preprocess functions' => ['cheese'], 'incomplete preprocess functions' => TRUE, ], - ]; - - $expected = [ + ], + 'expected' => [ 'test_hook' => [ 'preprocess functions' => [ 'cat', @@ -293,23 +286,9 @@ public function testManualSuggestion() { 'base hook' => 'test_hook', 'template' => 'test-hook', ], + ], ]; - - static::$functions['user'] = [ - 'cat', - 'mouse', - 'cheese', - 'bread', - 'test_preprocess_test_hook__suggestion', - 'test_preprocess_test_hook__suggestion__another', - ]; - - $class = new \ReflectionClass(TestRegistry::class); - $reflection_method = $class->getMethod('postProcessExtension'); - $reflection_method->setAccessible(TRUE); - $reflection_method->invokeArgs($this->registry, [&$hooks, $this->theme]); - - $this->assertArrayEquals($hooks, $expected); + return $data; } protected function setupTheme() {