Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MinificationTest.php
Go to the documentation of this file.
1 <?php
8 
12 
16 class MinificationTest extends \PHPUnit\Framework\TestCase
17 {
21  protected $minification;
22 
26  protected $scopeConfigMock;
27 
31  protected $appStateMock;
32 
36  protected function setUp()
37  {
38  $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
39  ->disableOriginalConstructor()
40  ->getMock();
41  $this->appStateMock = $this->getMockBuilder(\Magento\Framework\App\State::class)
42  ->disableOriginalConstructor()
43  ->getMock();
44 
45  $this->minification = new Minification(
46  $this->scopeConfigMock,
47  $this->appStateMock
48  );
49  }
50 
54  public function testIsEnabled()
55  {
56  }
57 
65  public function testIsAssetMinification($configFlag, $appMode, $result)
66  {
67  $contentType = 'content type';
68  $this->scopeConfigMock
69  ->expects($this->any())
70  ->method('isSetFlag')
71  ->with(
72  sprintf(Minification::XML_PATH_MINIFICATION_ENABLED, $contentType),
74  )
75  ->willReturn($configFlag);
76  $this->appStateMock
77  ->expects($this->any())
78  ->method('getMode')
79  ->willReturn($appMode);
80 
81  $this->assertEquals($result, $this->minification->isEnabled($contentType));
82  }
83 
87  public function isEnabledDataProvider()
88  {
89  return [
90  [false, State::MODE_DEFAULT, false],
91  [false, State::MODE_PRODUCTION, false],
92  [false, State::MODE_DEVELOPER, false],
93  [true, State::MODE_DEFAULT, true],
94  [true, State::MODE_PRODUCTION, true],
95  [true, State::MODE_DEVELOPER, false]
96  ];
97  }
98 
105  public function testAddMinifiedSign($filename, $isEnabled, $expected)
106  {
107  $this->scopeConfigMock
108  ->expects($this->any())
109  ->method('isSetFlag')
110  ->willReturn($isEnabled);
111  $this->appStateMock
112  ->expects($this->any())
113  ->method('getMode')
114  ->willReturn(State::MODE_DEFAULT);
115 
116  $this->assertEquals(
117  $expected,
118  $this->minification->addMinifiedSign($filename)
119  );
120  }
121 
125  public function addMinifiedSignDataProvider()
126  {
127  return [
128  ['test.css', true, 'test.min.css'],
129  ['test.css', false, 'test.css'],
130  ['test.min.css', true, 'test.min.css']
131  ];
132  }
133 
140  public function testRemoveMinifiedSign($filename, $isEnabled, $expected)
141  {
142  $this->scopeConfigMock
143  ->expects($this->any())
144  ->method('isSetFlag')
145  ->willReturn($isEnabled);
146  $this->appStateMock
147  ->expects($this->any())
148  ->method('getMode')
149  ->willReturn(State::MODE_DEFAULT);
150 
151  $this->assertEquals(
152  $expected,
153  $this->minification->removeMinifiedSign($filename)
154  );
155  }
156 
161  {
162  return [
163  ['test.css', true, 'test.css'],
164  ['test.min.css', true, 'test.css'],
165  ['test.min.css', false, 'test.min.css']
166  ];
167  }
168 
175  public function testIsMinifiedFilename($filename, $result)
176  {
177  $this->assertEquals(
178  $result,
179  $this->minification->isMinifiedFilename($filename)
180  );
181  }
182 
187  {
188  return [
189  ['test.min.css', true],
190  ['test.mincss', false],
191  ['testmin.css', false],
192  ['test.css', false],
193  ['test.min', false]
194  ];
195  }
196 
202  public function testGetExcludes()
203  {
204  $this->scopeConfigMock
205  ->expects($this->once())
206  ->method('getValue')
207  ->with('dev/js/minify_exclude')
208  ->willReturn([
209  'tiny_mce' => '/tiny_mce/',
210  'some_other_unique_name' => '/tiny_mce2/'
211  ]);
212 
213  $expected = ['/tiny_mce/', '/tiny_mce2/'];
214  $this->assertEquals($expected, $this->minification->getExcludes('js'));
216  $this->assertEquals($expected, $this->minification->getExcludes('js'));
217  }
218 
228  public function testGetExcludesTinyMceAsString(string $value, array $expectedValue)
229  {
230  $this->scopeConfigMock
231  ->expects($this->once())
232  ->method('getValue')
233  ->with('dev/js/minify_exclude')
234  ->willReturn($value);
235 
236  $this->assertEquals($expectedValue, $this->minification->getExcludes('js'));
238  $this->assertEquals($expectedValue, $this->minification->getExcludes('js'));
239  }
240 
245  {
246  return [
247  ["/tiny_mce/ \n /tiny_mce2/", ['/tiny_mce/', '/tiny_mce2/']],
248  ['/tiny_mce/', ['/tiny_mce/']],
249  [' /tiny_mce/', ['/tiny_mce/']],
250  ];
251  }
252 }
testRemoveMinifiedSign($filename, $isEnabled, $expected)
$value
Definition: gender.phtml:16
testGetExcludesTinyMceAsString(string $value, array $expectedValue)