More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Asset / LibraryDiscoveryTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Asset;
4
5 use Drupal\Core\Asset\LibraryDiscovery;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * @coversDefaultClass \Drupal\Core\Asset\LibraryDiscovery
10  * @group Asset
11  */
12 class LibraryDiscoveryTest extends UnitTestCase {
13
14   /**
15    * The tested library discovery service.
16    *
17    * @var \Drupal\Core\Asset\LibraryDiscovery
18    */
19   protected $libraryDiscovery;
20
21   /**
22    * The mocked library discovery cache collector.
23    *
24    * @var \Drupal\Core\Cache\CacheCollectorInterface|\PHPUnit_Framework_MockObject_MockObject
25    */
26   protected $libraryDiscoveryCollector;
27
28   /**
29    * The cache tags invalidator.
30    *
31    * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject
32    */
33   protected $cacheTagsInvalidator;
34
35   /**
36    * Test library data.
37    *
38    * @var array
39    */
40   protected $libraryData = [
41     'test_1' => [
42       'js' => [],
43       'css' => [
44         'foo.css' => [],
45       ],
46     ],
47     'test_2' => [
48       'js' => [
49         'bar.js' => [],
50       ],
51       'css' => [],
52     ],
53   ];
54
55   /**
56    * {@inheritdoc}
57    */
58   protected function setUp() {
59     parent::setUp();
60
61     $this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
62     $this->libraryDiscoveryCollector = $this->getMockBuilder('Drupal\Core\Asset\LibraryDiscoveryCollector')
63       ->disableOriginalConstructor()
64       ->getMock();
65     $this->libraryDiscovery = new LibraryDiscovery($this->libraryDiscoveryCollector, $this->cacheTagsInvalidator);
66   }
67
68   /**
69    * @covers ::getLibrariesByExtension
70    */
71   public function testGetLibrariesByExtension() {
72     $this->libraryDiscoveryCollector->expects($this->once())
73       ->method('get')
74       ->with('test')
75       ->willReturn($this->libraryData);
76
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');
85   }
86
87 }