diff -u b/core/lib/Drupal/Core/Asset/LibraryDiscovery.php b/core/lib/Drupal/Core/Asset/LibraryDiscovery.php --- b/core/lib/Drupal/Core/Asset/LibraryDiscovery.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscovery.php @@ -106,7 +106,7 @@ * {@inheritdoc} */ public function clearCachedDefinitions() { - $this->cacheTagInvalidator->invalidateTags(['library_discovery']); + $this->cacheTagInvalidator->invalidateTags(['library_info']); } } diff -u b/core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php b/core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php --- b/core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php +++ b/core/lib/Drupal/Core/Asset/LibraryDiscoveryCollector.php @@ -17,7 +17,13 @@ */ class LibraryDiscoveryCollector extends CacheCollector { + /** + * The cache key. + * + * @var string + */ protected $cid; + /** * The cache backend. * @@ -60,8 +66,8 @@ */ public function __construct(CacheBackendInterface $cache, LockBackendInterface $lock, LibraryDiscoveryParser $discovery_parser, ThemeManagerInterface $theme_manager) { $this->themeManager = $theme_manager; - $this->cid = 'library_discovery:' . $this->themeManager->getActiveTheme()->getName(); - parent::__construct($this->cid, $cache, $lock, ['library_discovery']); + $this->cid = 'library_info:' . $this->themeManager->getActiveTheme()->getName(); + parent::__construct($this->cid, $cache, $lock, ['library_info']); $this->discoveryParser = $discovery_parser; } diff -u b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php --- b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryTest.php @@ -43,7 +43,7 @@ * @var \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $themeManager; - + /** * The cache tags invalidator. * only in patch2: unchanged: --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryCollectorTest.php @@ -41,6 +41,13 @@ class LibraryDiscoveryCollectorTest extends UnitTestCase { protected $libraryDiscoveryCollector; /** + * The mocked theme manager. + * + * @var \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $themeManager; + + /** * Test library data. * * @var array @@ -56,17 +63,21 @@ class LibraryDiscoveryCollectorTest extends UnitTestCase { ), ); + protected $activeTheme; + /** * {@inheritdoc} */ protected function setUp() { $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface'); + $this->themeManager = $this->getMockBuilder('Drupal\Core\Theme\ThemeManagerInterface') + ->disableOriginalConstructor() + ->getMock(); $this->libraryDiscoveryParser = $this->getMockBuilder('Drupal\Core\Asset\LibraryDiscoveryParser') ->disableOriginalConstructor() ->getMock(); - $this->libraryDiscoveryCollector = new LibraryDiscoveryCollector($this->cache, $this->lock, $this->libraryDiscoveryParser); } /** @@ -75,6 +86,17 @@ protected function setUp() { * @covers ::resolveCacheMiss */ public function testResolveCacheMiss() { + $this->activeTheme = $this->getMockBuilder('Drupal\Core\Theme\ActiveTheme') + ->disableOriginalConstructor() + ->getMock(); + $this->themeManager->expects($this->once()) + ->method('getActiveTheme') + ->will($this->returnValue($this->activeTheme)); + $this->activeTheme->expects($this->once()) + ->method('getName') + ->will($this->returnValue('kitten_theme')); + $this->libraryDiscoveryCollector = new LibraryDiscoveryCollector($this->cache, $this->lock, $this->libraryDiscoveryParser, $this->themeManager); + $this->libraryDiscoveryParser->expects($this->once()) ->method('buildByExtension') ->with('test') @@ -90,12 +112,23 @@ public function testResolveCacheMiss() { * @covers ::destruct */ public function testDestruct() { + $this->activeTheme = $this->getMockBuilder('Drupal\Core\Theme\ActiveTheme') + ->disableOriginalConstructor() + ->getMock(); + $this->themeManager->expects($this->once()) + ->method('getActiveTheme') + ->will($this->returnValue($this->activeTheme)); + $this->activeTheme->expects($this->once()) + ->method('getName') + ->will($this->returnValue('kitten_theme')); + $this->libraryDiscoveryCollector = new LibraryDiscoveryCollector($this->cache, $this->lock, $this->libraryDiscoveryParser, $this->themeManager); + $this->libraryDiscoveryParser->expects($this->once()) ->method('buildByExtension') ->with('test') ->will($this->returnValue($this->libraryData)); - $lock_key = 'library_info:Drupal\Core\Cache\CacheCollector'; + $lock_key = 'library_info:kitten_theme:Drupal\Core\Cache\CacheCollector'; $this->lock->expects($this->once()) ->method('acquire') @@ -103,11 +136,11 @@ public function testDestruct() { ->will($this->returnValue(TRUE)); $this->cache->expects($this->exactly(2)) ->method('get') - ->with('library_info') + ->with('library_info:kitten_theme') ->will($this->returnValue(FALSE)); $this->cache->expects($this->once()) ->method('set') - ->with('library_info', array('test' => $this->libraryData), Cache::PERMANENT, array('library_info')); + ->with('library_info:kitten_theme', array('test' => $this->libraryData), Cache::PERMANENT, ['library_info']); $this->lock->expects($this->once()) ->method('release') ->with($lock_key);