class RegistryLegacyTest
Same name in this branch
- 9 core/tests/Drupal/KernelTests/Core/Theme/RegistryLegacyTest.php \Drupal\KernelTests\Core\Theme\RegistryLegacyTest
Same name in other branches
- 8.9.x core/tests/Drupal/KernelTests/Core/Theme/RegistryLegacyTest.php \Drupal\KernelTests\Core\Theme\RegistryLegacyTest
- 8.9.x core/tests/Drupal/Tests/Core/Theme/RegistryLegacyTest.php \Drupal\Tests\Core\Theme\RegistryLegacyTest
@coversDefaultClass \Drupal\Core\Theme\Registry @group Theme @group legacy
@todo Remove in https://www.drupal.org/project/drupal/issues/3097889
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait
- class \Drupal\Tests\Core\Theme\RegistryLegacyTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of RegistryLegacyTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Theme/ RegistryLegacyTest.php, line 17
Namespace
Drupal\Tests\Core\ThemeView source
class RegistryLegacyTest extends UnitTestCase {
/**
* The mocked theme registry.
*
* @var \Drupal\Core\Theme\Registry|PHPUnit\Framework\MockObject\MockObject
*/
protected $registry;
/**
* The mocked cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $cache;
/**
* The mocked lock backend.
*
* @var \Drupal\Core\Lock\LockBackendInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $lock;
/**
* The mocked module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $moduleHandler;
/**
* The mocked theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $themeHandler;
/**
* The mocked theme initialization.
*
* @var \Drupal\Core\Theme\ThemeInitializationInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $themeInitialization;
/**
* The mocked cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $runtimeCache;
/**
* The theme manager.
*
* @var \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $themeManager;
/**
* The module extension list.
*
* @var \Drupal\Core\Extension\ModuleExtensionList|\PHPUnit\Framework\MockObject\MockObject
*/
protected $moduleList;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->cache = $this->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$this->lock = $this->createMock('Drupal\\Core\\Lock\\LockBackendInterface');
$this->moduleHandler = $this->createMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
$this->themeHandler = $this->createMock('Drupal\\Core\\Extension\\ThemeHandlerInterface');
$this->themeInitialization = $this->createMock('Drupal\\Core\\Theme\\ThemeInitializationInterface');
$this->runtimeCache = $this->createMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$this->themeManager = $this->createMock('Drupal\\Core\\Theme\\ThemeManagerInterface');
$this->moduleList = $this->createMock(ModuleExtensionList::class);
$this->setupTheme();
}
/**
* Tests getting legacy theme function registry data defined by a module.
*/
public function testGetLegacyThemeFunctionRegistryForModule() {
$this->expectDeprecation('Unsilenced deprecation: Theme functions are deprecated in drupal:8.0.0 and are removed from drupal:10.0.0. Use Twig templates instead of theme_theme_test(). See https://www.drupal.org/node/1831138');
$test_theme = new ActiveTheme([
'name' => 'test_legacy_theme',
'path' => 'core/modules/system/tests/themes/test_legacy_theme/test_legacy_theme.info.yml',
'engine' => 'twig',
'owner' => 'twig',
'stylesheets_remove' => [],
'libraries_override' => [],
'libraries_extend' => [],
'libraries' => [],
'extension' => '.twig',
'base_theme_extensions' => [],
]);
$this->themeManager
->expects($this->once())
->method('getActiveTheme')
->willReturn($test_theme);
// Include the module and theme files so that hook_theme can be called.
include_once $this->root . '/core/modules/system/tests/modules/theme_legacy_test/theme_legacy_test.module';
$this->moduleHandler
->expects($this->atLeastOnce())
->method('invokeAllWith')
->with('theme')
->willReturnCallback(function (string $hook, callable $callback) {
$callback(function () {
}, 'theme_legacy_test');
});
$this->moduleHandler
->expects($this->atLeastOnce())
->method('getModuleList')
->willReturn([]);
$this->moduleList
->expects($this->once())
->method('getPath')
->with('theme_legacy_test')
->willReturn('core/modules/system/tests/modules/theme_legacy_test');
$registry = $this->registry
->get();
// Ensure that the registry entries from the module are found.
$this->assertArrayHasKey('theme_test', $registry);
$this->assertArrayHasKey('theme_test_function_suggestions', $registry);
$this->assertArrayHasKey('theme_test_foo', $registry);
$this->assertArrayHasKey('theme_test_render_element_children', $registry);
$this->assertArrayHasKey('theme_test_function_template_override', $registry);
$this->assertArrayNotHasKey('test_theme_not_existing_function', $registry);
$info = $registry['theme_test_function_suggestions'];
$this->assertEquals('module', $info['type']);
$this->assertEquals('core/modules/system/tests/modules/theme_legacy_test', $info['theme path']);
$this->assertEquals('theme_theme_test_function_suggestions', $info['function']);
$this->assertEquals([], $info['variables']);
}
protected function setupTheme() {
$this->registry = $this->getMockBuilder(Registry::class)
->onlyMethods([
'getPath',
])
->setConstructorArgs([
$this->root,
$this->cache,
$this->lock,
$this->moduleHandler,
$this->themeHandler,
$this->themeInitialization,
$this->runtimeCache,
$this->moduleList,
])
->getMock();
$this->registry
->expects($this->any())
->method('getPath')
->willReturnCallback(function ($module) {
if ($module == 'theme_legacy_test') {
return 'core/modules/system/tests/modules/theme_legacy_test';
}
});
$this->registry
->setThemeManager($this->themeManager);
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
RegistryLegacyTest::$cache | protected | property | The mocked cache backend. | |||
RegistryLegacyTest::$lock | protected | property | The mocked lock backend. | |||
RegistryLegacyTest::$moduleHandler | protected | property | The mocked module handler. | |||
RegistryLegacyTest::$moduleList | protected | property | The module extension list. | |||
RegistryLegacyTest::$registry | protected | property | The mocked theme registry. | |||
RegistryLegacyTest::$runtimeCache | protected | property | The mocked cache backend. | |||
RegistryLegacyTest::$themeHandler | protected | property | The mocked theme handler. | |||
RegistryLegacyTest::$themeInitialization | protected | property | The mocked theme initialization. | |||
RegistryLegacyTest::$themeManager | protected | property | The theme manager. | |||
RegistryLegacyTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
RegistryLegacyTest::setupTheme | protected | function | ||||
RegistryLegacyTest::testGetLegacyThemeFunctionRegistryForModule | public | function | Tests getting legacy theme function registry data defined by a module. | |||
UnitTestCase::$randomGenerator | protected | property | The random generator. | |||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
UnitTestCase::assertArrayEquals | Deprecated | protected | function | Asserts if two arrays are equal by sorting them first. | ||
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
UnitTestCase::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::randomMachineName | public | function | Generates a unique random string containing letters and numbers. | |||
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.