diff -u b/core/lib/Drupal/Core/Utility/ThemeRegistry.php b/core/lib/Drupal/Core/Utility/ThemeRegistry.php --- b/core/lib/Drupal/Core/Utility/ThemeRegistry.php +++ b/core/lib/Drupal/Core/Utility/ThemeRegistry.php @@ -88,6 +88,16 @@ } /** + * Sets the cid. + * + * @param string $cid + * The cid for the array being cached. + */ + public function setCid($cid) { + $this->cid = $cid; + } + + /** * Gets the persistable. * * @return bool diff -u b/core/modules/system/src/Tests/Theme/RegistryTest.php b/core/modules/system/src/Tests/Theme/RegistryTest.php --- b/core/modules/system/src/Tests/Theme/RegistryTest.php +++ b/core/modules/system/src/Tests/Theme/RegistryTest.php @@ -68,6 +68,36 @@ } /** + * Tests the behavior of theme registry class when cid is set manually. + */ + public function testManualCidSet() { + // The theme registry is not marked as persistable in case we don't have a + // proper request. + \Drupal::request()->setMethod('GET'); + + // Directly instantiate the theme registry, this will cause a base cache + // entry to be written in __construct(). + $cache = \Drupal::cache(); + $lock_backend = \Drupal::lock(); + $theme = \Drupal::theme(); + $cid = 'kitten_theme_registry'; + $registry = new ThemeRegistry($cache, $lock_backend, $theme->getActiveTheme(), array('theme_registry'), $this->container->get('module_handler')->isLoaded()); + $registry->setCid($cid); + + $this->assertFalse(\Drupal::cache()->get($cid), 'Cache entry was not created by default.'); + + // Trigger a cache miss for an offset. + $this->assertTrue($registry->get('theme_test_template_test'), 'Offset was returned correctly from the theme registry.'); + $this->assertTrue(\Drupal::cache()->get($cid), 'Cache entry was created.'); + \Drupal::cache()->delete($cid); + + // Destroy the class so that it triggers a cache write for the offset. + $registry->destruct(); + + $this->assertTrue(\Drupal::cache()->get($cid), 'Cache entry was created.'); + } + + /** * Tests the theme registry with multiple subthemes. */ public function testMultipleSubThemes() {