1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\RequireJs\Test\Unit\Block\Html\Head;
use \Magento\RequireJs\Block\Html\Head\Config;
class ConfigTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\View\Element\Context|\PHPUnit_Framework_MockObject_MockObject
*/
private $context;
/**
* @var \Magento\Framework\RequireJs\Config|\PHPUnit_Framework_MockObject_MockObject
*/
private $config;
/**
* @var \Magento\RequireJs\Model\FileManager|\PHPUnit_Framework_MockObject_MockObject
*/
private $fileManager;
/**
* @var \Magento\Framework\View\Page\Config|\PHPUnit_Framework_MockObject_MockObject
*/
protected $pageConfig;
/**
* @var Config
*/
protected $blockConfig;
/**
* @var \Magento\Framework\View\Asset\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $bundleConfig;
/**
* @var \Magento\Framework\View\Asset\Minification|\PHPUnit_Framework_MockObject_MockObject
*/
private $minificationMock;
protected function setUp()
{
$this->context = $this->createMock(\Magento\Framework\View\Element\Context::class);
$this->config = $this->createMock(\Magento\Framework\RequireJs\Config::class);
$this->fileManager = $this->createMock(\Magento\RequireJs\Model\FileManager::class);
$this->pageConfig = $this->createMock(\Magento\Framework\View\Page\Config::class);
$this->bundleConfig = $this->createMock(\Magento\Framework\View\Asset\ConfigInterface::class);
}
public function testSetLayout()
{
$this->bundleConfig
->expects($this->once())
->method('isBundlingJsFiles')
->willReturn(true);
$filePath = 'require_js_fie_path';
$asset = $this->getMockForAbstractClass(\Magento\Framework\View\Asset\LocalInterface::class);
$asset->expects($this->atLeastOnce())
->method('getFilePath')
->willReturn($filePath);
$requireJsAsset = $this->getMockForAbstractClass(\Magento\Framework\View\Asset\LocalInterface::class);
$requireJsAsset
->expects($this->atLeastOnce())
->method('getFilePath')
->willReturn('/path/to/require/require.js');
$minResolverAsset = $this->getMockForAbstractClass(\Magento\Framework\View\Asset\LocalInterface::class);
$minResolverAsset
->expects($this->atLeastOnce())
->method('getFilePath')
->willReturn('/path/to/require/require-min-resolver.js');
$this->fileManager
->expects($this->once())
->method('createRequireJsConfigAsset')
->will($this->returnValue($requireJsAsset));
$this->fileManager
->expects($this->once())
->method('createRequireJsMixinsAsset')
->will($this->returnValue($requireJsAsset));
$this->fileManager
->expects($this->once())
->method('createStaticJsAsset')
->will($this->returnValue($requireJsAsset));
$this->fileManager
->expects($this->once())
->method('createBundleJsPool')
->will($this->returnValue([$asset]));
$this->fileManager
->expects($this->once())
->method('createMinResolverAsset')
->will($this->returnValue($minResolverAsset));
$layout = $this->createMock(\Magento\Framework\View\LayoutInterface::class);
$assetCollection = $this->getMockBuilder(\Magento\Framework\View\Asset\GroupedCollection::class)
->disableOriginalConstructor()
->getMock();
$this->pageConfig->expects($this->atLeastOnce())
->method('getAssetCollection')
->willReturn($assetCollection);
$assetCollection
->expects($this->atLeastOnce())
->method('insert')
->willReturn(true);
$this->minificationMock = $this->getMockBuilder(\Magento\Framework\View\Asset\Minification::class)
->disableOriginalConstructor()
->getMock();
$this->minificationMock
->expects($this->any())
->method('isEnabled')
->with('js')
->willReturn(true);
$object = new Config(
$this->context,
$this->config,
$this->fileManager,
$this->pageConfig,
$this->bundleConfig,
$this->minificationMock
);
$object->setLayout($layout);
}
}