9 use \Magento\RequireJs\Model\FileManager;
47 private $assetRepoMock;
51 $this->configMock = $this->createMock(\
Magento\Framework\RequireJs\Config::class);
52 $this->fileSystem = $this->createMock(\
Magento\Framework\Filesystem::class);
53 $this->appState = $this->createMock(\
Magento\Framework\
App\State::class);
54 $this->assetRepoMock = $this->createMock(\
Magento\Framework\View\Asset\Repository::class);
55 $this->
object =
new FileManager($this->configMock, $this->fileSystem, $this->appState, $this->assetRepoMock);
56 $this->dir = $this->getMockForAbstractClass(\
Magento\Framework\Filesystem\Directory\WriteInterface::class);
57 $this->asset = $this->createMock(\
Magento\Framework\View\Asset\File::class);
66 $this->configMock->expects($this->once())
67 ->method(
'getConfigFileRelativePath')
68 ->will($this->returnValue(
'requirejs/file.js'));
69 $this->fileSystem->expects($this->once())
70 ->method(
'getDirectoryWrite')
72 ->will($this->returnValue($this->dir));
73 $this->assetRepoMock->expects($this->once())
74 ->method(
'createArbitrary')
75 ->with(
'requirejs/file.js',
'')
76 ->will($this->returnValue($this->asset));
78 $this->appState->expects($this->once())->method(
'getMode')->will($this->returnValue(
'anything'));
79 $this->dir->expects($this->once())
81 ->with(
'requirejs/file.js')
82 ->will($this->returnValue($exists));
84 $this->configMock->expects($this->never())->method(
'getConfig');
85 $this->dir->expects($this->never())->method(
'writeFile');
87 $data =
'requirejs config data';
88 $this->configMock->expects($this->once())->method(
'getConfig')->will($this->returnValue(
$data));
89 $this->dir->expects($this->once())->method(
'writeFile')->with(
'requirejs/file.js',
$data);
91 $this->assertSame($this->asset, $this->object->createRequireJsConfigAsset());
99 return [[
true], [
false]];
104 $this->configMock->expects($this->once())
105 ->method(
'getConfigFileRelativePath')
106 ->will($this->returnValue(
'requirejs/file.js'));
107 $this->fileSystem->expects($this->once())
108 ->method(
'getDirectoryWrite')
110 ->will($this->returnValue($this->dir));
111 $this->assetRepoMock->expects($this->once())
112 ->method(
'createArbitrary')
113 ->with(
'requirejs/file.js',
'')
114 ->will($this->returnValue($this->asset));
116 $this->appState->expects($this->once())
118 ->will($this->returnValue(\
Magento\Framework\
App\State::MODE_DEVELOPER));
119 $this->dir->expects($this->never())->method(
'isExist');
120 $data =
'requirejs config data';
121 $this->configMock->expects($this->once())->method(
'getConfig')->will($this->returnValue(
$data));
122 $this->dir->expects($this->once())->method(
'writeFile')->with(
'requirejs/file.js',
$data);
123 $this->assertSame($this->asset, $this->object->createRequireJsConfigAsset());
128 unset($this->configMock);
129 $dirRead = $this->getMockBuilder(\
Magento\Framework\Filesystem\Directory\Read::class)
130 ->setMockClassName(
'libDir')
131 ->disableOriginalConstructor()
133 $context = $this->createMock(\
Magento\Framework\View\Asset\File\FallbackContext::class);
134 $assetRepo = $this->createMock(\
Magento\Framework\View\Asset\Repository::class);
135 $config = $this->createMock(\
Magento\Framework\RequireJs\Config::class);
138 ->expects($this->never())
139 ->method(
'getConfigFileRelativePath')
143 ->expects($this->once())
145 ->willReturn(
'path/to/bundle/dir');
148 ->expects($this->once())
150 ->with(
'path/to/bundle/dir/js/bundle')
153 ->expects($this->once())
155 ->with(
'path/to/bundle/dir/js/bundle')
156 ->willReturn([
'bundle1.js',
'bundle2.js',
'some_file.not_js']);
158 ->expects($this->exactly(2))
159 ->method(
'getRelativePath')
161 'path/to/bundle1.js',
165 ->expects($this->exactly(2))
166 ->method(
'createArbitrary')
173 ->expects($this->once())
174 ->method(
'getStaticViewFileContext')
175 ->willReturn($context);
178 ->expects($this->once())
180 ->willReturn(
'production');
183 ->expects($this->once())
184 ->method(
'getDirectoryRead')
186 ->willReturn($dirRead);
190 $result = $object->createBundleJsPool();
192 $this->assertArrayHasKey(
'0',
$result);
193 $this->assertArrayHasKey(
'1',
$result);
199 ->expects($this->any())
200 ->method(
'getMinResolverRelativePath')
201 ->willReturn(
'relative path');
203 ->expects($this->once())
204 ->method(
'createArbitrary')
205 ->with(
'relative path');
206 $this->fileSystem->expects($this->once())
207 ->method(
'getDirectoryWrite')
209 ->will($this->returnValue($this->dir));
211 $this->
object->createMinResolverAsset();
216 $path =
'relative path';
218 ->expects($this->once())
219 ->method(
'getMixinsFileRelativePath')
220 ->will($this->returnValue(
$path));
222 ->expects($this->once())
223 ->method(
'createArbitrary')
225 ->willReturn($this->asset);
227 $this->assertSame($this->asset, $this->object->createRequireJsMixinsAsset());
232 $context = $this->getMockBuilder(\
Magento\Framework\View\Asset\File\FallbackContext::class)
233 ->disableOriginalConstructor()
235 $this->fileSystem->expects($this->once())
236 ->method(
'getDirectoryWrite')
238 ->willReturn($this->dir);
240 ->expects($this->once())
241 ->method(
'getStaticViewFileContext')
242 ->willReturn($context);
243 $context->expects($this->once())
245 ->willReturn(
'/path/to/directory');
246 $this->dir->expects($this->once())
248 ->with(
'/path/to/directory/' . \
Magento\Framework\RequireJs\Config::BUNDLE_JS_DIR)
250 $this->assertTrue($this->object->clearBundleJsPool());
createRequireJsAssetDataProvider()
testCreateRequireJsConfigAsset($exists)
testCreateRequireJsMixinsAsset()
testCreateRequireJsAssetDevMode()
testCreateMinResolverAsset()