9 use Magento\Catalog\Model\View\Asset\PlaceholderFactory;
31 private $configFactoryMock;
36 private $syncFactoryMock;
56 private $responseMock;
61 private $filesystemMock;
66 private $directoryMock;
70 $this->closure =
function () {
73 $this->configMock = $this->createMock(\
Magento\MediaStorage\Model\File\Storage\Config::class);
74 $this->sync = $this->createMock(\
Magento\MediaStorage\Model\File\Storage\Synchronization::class);
75 $this->configFactoryMock = $this->createPartialMock(
76 \
Magento\MediaStorage\Model\File\Storage\ConfigFactory::class,
79 $this->configFactoryMock->expects($this->any())
81 ->will($this->returnValue($this->configMock));
82 $this->syncFactoryMock = $this->createPartialMock(
83 \
Magento\MediaStorage\Model\File\Storage\SynchronizationFactory::class,
86 $this->syncFactoryMock->expects($this->any())
88 ->will($this->returnValue($this->sync));
90 $this->filesystemMock = $this->createMock(\
Magento\Framework\Filesystem::class);
91 $this->directoryMock = $this->getMockForAbstractClass(
92 \
Magento\Framework\Filesystem\Directory\WriteInterface::class
95 $this->filesystemMock->expects($this->any())
96 ->method(
'getDirectoryWrite')
98 ->will($this->returnValue($this->directoryMock));
100 $this->responseMock = $this->createMock(\
Magento\MediaStorage\Model\File\Storage\Response::class);
106 'configFactory' => $this->configFactoryMock,
107 'syncFactory' => $this->syncFactoryMock,
108 'response' => $this->responseMock,
109 'isAllowed' => $this->closure,
110 'mediaDirectory' =>
false,
111 'configCacheFile' => self::CACHE_FILE_PATH,
112 'relativeFileName' => self::RELATIVE_FILE_PATH,
113 'filesystem' => $this->filesystemMock,
114 'placeholderFactory' => $this->createConfiguredMock(
115 PlaceholderFactory::class,
117 'create' => $this->createMock(Placeholder::class)
135 'configFactory' => $this->configFactoryMock,
136 'syncFactory' => $this->syncFactoryMock,
137 'response' => $this->responseMock,
138 'isAllowed' => $this->closure,
139 'mediaDirectory' =>
false,
140 'configCacheFile' => self::CACHE_FILE_PATH,
141 'relativeFileName' => self::RELATIVE_FILE_PATH,
142 'filesystem' => $this->filesystemMock
145 $filePath =
'/absolute/path/to/test/file.png';
146 $this->directoryMock->expects($this->any())
147 ->method(
'getAbsolutePath')
148 ->will($this->returnValueMap(
150 [
null, self::MEDIA_DIRECTORY],
151 [self::RELATIVE_FILE_PATH, $filePath],
154 $this->configMock->expects($this->once())->method(
'save');
155 $this->sync->expects($this->once())->method(
'synchronize')->with(self::RELATIVE_FILE_PATH);
156 $this->directoryMock->expects($this->once())
157 ->method(
'isReadable')
158 ->with(self::RELATIVE_FILE_PATH)
159 ->will($this->returnValue(
true));
160 $this->responseMock->expects($this->once())->method(
'setFilePath')->with($filePath);
161 $this->model->launch();
166 $filePath =
'/absolute/path/to/test/file.png';
167 $this->sync->expects($this->once())->method(
'synchronize')->with(self::RELATIVE_FILE_PATH);
168 $this->directoryMock->expects($this->once())
169 ->method(
'isReadable')
170 ->with(self::RELATIVE_FILE_PATH)
171 ->will($this->returnValue(
true));
172 $this->directoryMock->expects($this->any())
173 ->method(
'getAbsolutePath')
174 ->will($this->returnValueMap(
176 [
null, self::MEDIA_DIRECTORY],
177 [self::RELATIVE_FILE_PATH, $filePath],
180 $this->responseMock->expects($this->once())->method(
'setFilePath')->with($filePath);
181 $this->assertSame($this->responseMock, $this->model->launch());
186 $this->sync->expects($this->once())->method(
'synchronize')->with(self::RELATIVE_FILE_PATH);
187 $this->directoryMock->expects($this->once())
188 ->method(
'getAbsolutePath')
190 ->will($this->returnValue(self::MEDIA_DIRECTORY));
191 $this->directoryMock->expects($this->once())
192 ->method(
'isReadable')
193 ->with(self::RELATIVE_FILE_PATH)
194 ->will($this->returnValue(
false));
195 $this->assertSame($this->responseMock, $this->model->launch());
207 $exception = $this->createMock(\Exception::class);
208 $this->responseMock->expects($this->once())
209 ->method(
'setHttpResponseCode')
212 ->method(
'isDeveloperMode')
213 ->will($this->returnValue($isDeveloper));
214 $this->responseMock->expects($this->exactly($setBodyCalls))
216 $this->responseMock->expects($this->once())
217 ->method(
'sendResponse');
218 $this->model->catchException(
$bootstrap, $exception);
227 'default mode' => [
false, 0],
228 'developer mode' => [
true, 1],
if(defined('TESTS_MAGENTO_INSTALLATION') &&TESTS_MAGENTO_INSTALLATION==='enabled') $bootstrap