Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MinifyTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class MinifyTest extends \PHPUnit\Framework\TestCase
15 {
19  protected $minify;
20 
24  protected $adapterMock;
25 
29  protected $minificationMock;
30 
34  protected function setUp()
35  {
36  $this->adapterMock = $this->getMockBuilder(\Magento\Framework\Code\Minifier\AdapterInterface::class)
37  ->setMethods(['minify'])
38  ->disableOriginalConstructor()
39  ->getMockForAbstractClass();
40  $this->minificationMock = $this->getMockBuilder(\Magento\Framework\View\Asset\Minification::class)
41  ->disableOriginalConstructor()
42  ->getMock();
43 
44  $this->minify = new Minify(
45  $this->adapterMock,
46  $this->minificationMock
47  );
48  }
49 
59  public function testProcess($targetPath, $originalPath, $minifyCalls, $setContentCalls, $isEnabled)
60  {
61  $chainMock = $this->getMockBuilder(\Magento\Framework\View\Asset\PreProcessor\Chain::class)
62  ->disableOriginalConstructor()
63  ->getMock();
64  $chainMock
65  ->expects($this->any())
66  ->method('getTargetAssetPath')
67  ->willReturn($targetPath);
68  $chainMock
69  ->expects($this->exactly($setContentCalls))
70  ->method('setContent')
71  ->with('minified content');
72  $chainMock
73  ->expects($this->any())
74  ->method('getContent')
75  ->willReturn('original content');
76  $chainMock
77  ->expects($this->any())
78  ->method('getOrigAssetPath')
79  ->willReturn($originalPath);
80 
81  $this->adapterMock
82  ->expects($this->exactly($minifyCalls))
83  ->method('minify')
84  ->with('original content')
85  ->willReturn('minified content');
86 
87  $this->minificationMock
88  ->expects($this->any())
89  ->method('isEnabled')
90  ->willReturnMap([['css', $isEnabled]]);
91 
92  $this->minificationMock
93  ->expects($this->any())
94  ->method('isMinifiedFilename')
95  ->willReturnMap(
96  [
97  ['test.min.css', true],
98  ['test.jpeg', false],
99  ['test.css', false]
100  ]
101  );
102 
103  $this->minify->process($chainMock);
104  }
105 
109  public function processDataProvider()
110  {
111  return [
112  ['test.min.css', 'test.css', 1, 1, true],
113  ['test.min.css', 'test.min.css', 0, 0, true],
114  ['test.jpeg', 'test.jpeg', 0, 0, true],
115  ['test.css', 'test.css', 0, 0, true],
116  ['test.jpeg', 'test.jpeg', 0, 0, true],
117  ['test.css', 'test.css', 0, 0, true],
118  ['test.css', 'test.css', 0, 0, false]
119  ];
120  }
121 }
testProcess($targetPath, $originalPath, $minifyCalls, $setContentCalls, $isEnabled)
Definition: MinifyTest.php:59