3 namespace Drupal\Tests\Core\Asset;
5 use Drupal\Core\Asset\LibraryDiscovery;
6 use Drupal\Tests\UnitTestCase;
9 * @coversDefaultClass \Drupal\Core\Asset\LibraryDiscovery
12 class LibraryDiscoveryTest extends UnitTestCase {
15 * The tested library discovery service.
17 * @var \Drupal\Core\Asset\LibraryDiscovery
19 protected $libraryDiscovery;
22 * The mocked library discovery cache collector.
24 * @var \Drupal\Core\Cache\CacheCollectorInterface|\PHPUnit_Framework_MockObject_MockObject
26 protected $libraryDiscoveryCollector;
29 * The cache tags invalidator.
31 * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject
33 protected $cacheTagsInvalidator;
40 protected $libraryData = [
58 protected function setUp() {
61 $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
62 $this->libraryDiscoveryCollector = $this->getMockBuilder('Drupal\Core\Asset\LibraryDiscoveryCollector')
63 ->disableOriginalConstructor()
65 $this->libraryDiscovery = new LibraryDiscovery($this->libraryDiscoveryCollector, $this->cacheTagsInvalidator);
69 * @covers ::getLibrariesByExtension
71 public function testGetLibrariesByExtension() {
72 $this->libraryDiscoveryCollector->expects($this->once())
75 ->willReturn($this->libraryData);
77 $this->libraryDiscovery->getLibrariesbyExtension('test');
78 // Verify that subsequent calls don't trigger hook_library_info_alter()
79 // and hook_js_settings_alter() invocations, nor do they talk to the
80 // collector again. This ensures that the alterations made by
81 // hook_library_info_alter() and hook_js_settings_alter() implementations
82 // are statically cached, as desired.
83 $this->libraryDiscovery->getLibraryByName('test', 'test_1');
84 $this->libraryDiscovery->getLibrariesbyExtension('test');