badb981393dd462177b7422d0ddf091e996877e6
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Asset / CssCollectionGrouperUnitTest.php
1 <?php
2
3 namespace Drupal\Tests\Core\Asset;
4
5 use Drupal\Core\Asset\CssCollectionGrouper;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * Tests the CSS asset collection grouper.
10  *
11  * @group Asset
12  */
13 class CssCollectionGrouperUnitTest extends UnitTestCase {
14
15   /**
16    * A CSS asset grouper.
17    *
18    * @var \Drupal\Core\Asset\CssCollectionGrouper object.
19    */
20   protected $grouper;
21
22   protected function setUp() {
23     parent::setUp();
24
25     $this->grouper = new CssCollectionGrouper();
26   }
27
28   /**
29    * Tests \Drupal\Core\Asset\CssCollectionGrouper.
30    */
31   public function testGrouper() {
32     $css_assets = [
33       'system.base.css' => [
34         'group' => -100,
35         'type' => 'file',
36         'weight' => 0.012,
37         'media' => 'all',
38         'preprocess' => TRUE,
39         'data' => 'core/modules/system/system.base.css',
40         'browsers' => ['IE' => TRUE, '!IE' => TRUE],
41         'basename' => 'system.base.css',
42       ],
43       'js.module.css' => [
44         'group' => -100,
45         'type' => 'file',
46         'weight' => 0.013,
47         'media' => 'all',
48         'preprocess' => TRUE,
49         'data' => 'core/modules/system/js.module.css',
50         'browsers' => ['IE' => TRUE, '!IE' => TRUE],
51         'basename' => 'js.module.css',
52       ],
53       'jquery.ui.core.css' => [
54         'group' => -100,
55         'type' => 'file',
56         'weight' => 0.004,
57         'media' => 'all',
58         'preprocess' => TRUE,
59         'data' => 'core/misc/ui/themes/base/jquery.ui.core.css',
60         'browsers' => ['IE' => TRUE, '!IE' => TRUE],
61         'basename' => 'jquery.ui.core.css',
62       ],
63       'field.css' => [
64         'group' => 0,
65         'type' => 'file',
66         'weight' => 0.011,
67         'media' => 'all',
68         'preprocess' => TRUE,
69         'data' => 'core/modules/field/theme/field.css',
70         'browsers' => ['IE' => TRUE, '!IE' => TRUE],
71         'basename' => 'field.css',
72       ],
73       'external.css' => [
74         'group' => 0,
75         'type' => 'external',
76         'weight' => 0.009,
77         'media' => 'all',
78         'preprocess' => TRUE,
79         'data' => 'http://example.com/external.css',
80         'browsers' => ['IE' => TRUE, '!IE' => TRUE],
81         'basename' => 'external.css',
82       ],
83       'elements.css' => [
84         'group' => 100,
85         'media' => 'all',
86         'type' => 'file',
87         'weight' => 0.001,
88         'preprocess' => TRUE,
89         'data' => 'core/themes/bartik/css/base/elements.css',
90         'browsers' => ['IE' => TRUE, '!IE' => TRUE],
91         'basename' => 'elements.css',
92       ],
93       'print.css' => [
94         'group' => 100,
95         'media' => 'print',
96         'type' => 'file',
97         'weight' => 0.003,
98         'preprocess' => TRUE,
99         'data' => 'core/themes/bartik/css/print.css',
100         'browsers' => ['IE' => TRUE, '!IE' => TRUE],
101         'basename' => 'print.css',
102       ],
103     ];
104
105     $groups = $this->grouper->group($css_assets);
106
107     $this->assertSame(5, count($groups), "5 groups created.");
108
109     // Check group 1.
110     $group = $groups[0];
111     $this->assertSame(-100, $group['group']);
112     $this->assertSame('file', $group['type']);
113     $this->assertSame('all', $group['media']);
114     $this->assertSame(TRUE, $group['preprocess']);
115     $this->assertSame(3, count($group['items']));
116     $this->assertContains($css_assets['system.base.css'], $group['items']);
117     $this->assertContains($css_assets['js.module.css'], $group['items']);
118
119     // Check group 2.
120     $group = $groups[1];
121     $this->assertSame(0, $group['group']);
122     $this->assertSame('file', $group['type']);
123     $this->assertSame('all', $group['media']);
124     $this->assertSame(TRUE, $group['preprocess']);
125     $this->assertSame(1, count($group['items']));
126     $this->assertContains($css_assets['field.css'], $group['items']);
127
128     // Check group 3.
129     $group = $groups[2];
130     $this->assertSame(0, $group['group']);
131     $this->assertSame('external', $group['type']);
132     $this->assertSame('all', $group['media']);
133     $this->assertSame(TRUE, $group['preprocess']);
134     $this->assertSame(1, count($group['items']));
135     $this->assertContains($css_assets['external.css'], $group['items']);
136
137     // Check group 4.
138     $group = $groups[3];
139     $this->assertSame(100, $group['group']);
140     $this->assertSame('file', $group['type']);
141     $this->assertSame('all', $group['media']);
142     $this->assertSame(TRUE, $group['preprocess']);
143     $this->assertSame(1, count($group['items']));
144     $this->assertContains($css_assets['elements.css'], $group['items']);
145
146     // Check group 5.
147     $group = $groups[4];
148     $this->assertSame(100, $group['group']);
149     $this->assertSame('file', $group['type']);
150     $this->assertSame('print', $group['media']);
151     $this->assertSame(TRUE, $group['preprocess']);
152     $this->assertSame(1, count($group['items']));
153     $this->assertContains($css_assets['print.css'], $group['items']);
154   }
155
156 }