83 $this->customizationPath =
'/' . implode(
'/', [
'var',
'theme']);
85 $this->request = $this->createMock(\
Magento\Framework\
App\Request\Http::class);
86 $this->filesystem = $this->createMock(\
Magento\Framework\Filesystem::class);
87 $this->session = $this->createMock(\
Magento\Backend\Model\Session::class);
88 $this->contextHelper = $this->createMock(\
Magento\Framework\
App\Helper\Context::class);
89 $this->directoryWrite = $this->createMock(\
Magento\Framework\Filesystem\Directory\Write::class);
90 $this->themeFactory = $this->createMock(\
Magento\Framework\View\Design\Theme\FlyweightFactory::class);
91 $this->theme = $this->createMock(\
Magento\Theme\Model\Theme::class);
92 $this->customization = $this->createMock(\
Magento\Framework\View\Design\Theme\Customization::class);
94 $this->filesystem->expects($this->any())
95 ->method(
'getDirectoryWrite')
96 ->will($this->returnValue($this->directoryWrite));
97 $this->urlEncoder = $this->getMockBuilder(\
Magento\Framework\Url\EncoderInterface::class)->getMock();
98 $this->urlDecoder = $this->getMockBuilder(\
Magento\Framework\Url\DecoderInterface::class)->getMock();
100 $this->directoryWrite->expects($this->any())->method(
'create')->willReturn(
true);
101 $this->contextHelper->expects($this->any())->method(
'getRequest')->willReturn($this->request);
102 $this->contextHelper->expects($this->any())->method(
'getUrlEncoder')->willReturn($this->urlEncoder);
103 $this->contextHelper->expects($this->any())->method(
'getUrlDecoder')->willReturn($this->urlDecoder);
104 $this->themeFactory->expects($this->any())->method(
'create')->willReturn($this->theme);
106 $this->theme->expects($this->any())
107 ->method(
'getCustomization')
108 ->will($this->returnValue($this->customization));
110 $this->request->expects($this->at(0))
113 ->will($this->returnValue(6));
114 $this->request->expects($this->at(1))
117 ->will($this->returnValue(\
Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE));
119 $this->helper = new \Magento\Theme\Helper\Storage(
120 $this->contextHelper,
129 $this->request =
null;
130 $this->filesystem =
null;
131 $this->session =
null;
132 $this->contextHelper =
null;
133 $this->directoryWrite =
null;
134 $this->themeFactory =
null;
136 $this->customization =
null;
145 $longFileName =
'veryLongFileNameMoreThanTwenty';
146 $expectedFileName =
'veryLongFileNameMore...';
147 $this->assertEquals($expectedFileName, $this->helper->getShortFilename($longFileName, 20));
153 $this->assertEquals($expectedStorageRoot, $this->helper->getStorageRoot());
158 $imagePath = implode(
'/', [
'root',
'image',
'image_name.jpg']);
159 $thumbnailDir = implode(
161 [
'root',
'image', \
Magento\Theme\Model\Wysiwyg\Storage::THUMBNAIL_DIRECTORY]
164 $this->assertEquals($thumbnailDir, $this->helper->getThumbnailDirectory($imagePath));
169 $image =
'image_name.jpg';
170 $thumbnailPath =
'/' . implode(
173 \
Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE,
174 \
Magento\Theme\Model\Wysiwyg\Storage::THUMBNAIL_DIRECTORY,
179 $this->customization->expects(
182 'getCustomizationPath' 184 $this->returnValue($this->customizationPath)
187 $this->directoryWrite->expects($this->any())->method(
'isExist')->will($this->returnValue(
true));
189 $this->assertEquals($thumbnailPath, $this->helper->getThumbnailPath(
$image));
194 $this->request->expects(
201 $this->returnValue(6)
203 $this->request->expects(
210 $this->returnValue(
'image')
212 $this->request->expects(
219 $this->returnValue(
'node')
227 $this->assertEquals($expectedResult, $this->helper->getRequestParams());
232 $this->request->expects(
239 $this->returnValue(\
Magento\Theme\Model\Wysiwyg\Storage::TYPE_FONT)
242 $this->request->expects(
249 $this->returnValue(\
Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE)
252 $fontTypes = $this->helper->getAllowedExtensionsByType();
253 $this->assertEquals([
'ttf',
'otf',
'eot',
'svg',
'woff'], $fontTypes);
255 $imagesTypes = $this->helper->getAllowedExtensionsByType();
256 $this->assertEquals([
'jpg',
'jpeg',
'gif',
'png',
'xbm',
'wbmp'], $imagesTypes);
267 $image =
'notFoundImage.png';
269 $sourceNode =
'/not/a/root';
270 $node = base64_encode($sourceNode);
271 $this->request->expects($this->at(0))
283 \
Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE
292 $this->urlDecoder->expects($this->once())
295 ->willReturnCallback(
function (
$path) {
296 return base64_decode(
$path);
298 $this->directoryWrite->expects($this->once())
299 ->method(
'isDirectory')
300 ->with($root . $sourceNode)
302 $this->directoryWrite->expects($this->once())
303 ->method(
'getRelativePath')
304 ->with($root . $sourceNode)
305 ->willReturn($sourceNode);
306 $this->directoryWrite->expects($this->once())
308 ->with($sourceNode .
'/' .
$image);
310 $this->helper->getThumbnailPath(
$image);
319 $path =
'/image/path/to';
320 $this->urlEncoder->expects($this->once())
323 ->willReturnCallback(
function (
$path) {
324 return base64_encode(
$path);
326 $this->urlDecoder->expects($this->once())
328 ->with(base64_encode(
'/path/to'))
329 ->willReturnCallback(
function (
$path) {
330 return base64_decode(
$path);
334 $this->assertEquals(base64_encode(
'/path/to'),
$value);
335 $this->assertEquals(
$path, $this->helper->convertIdToPath(
$value));
340 $this->assertInstanceOf(\
Magento\Backend\Model\Session::class, $this->helper->getSession());
345 $filename = base64_encode(
'filename.ext');
346 $notRoot = base64_encode(
'not/a/root');
347 $this->request->expects($this->any())
354 \
Magento\Theme\Model\Wysiwyg\Storage::TYPE_IMAGE,
368 $decode =
function (
$value) {
369 return base64_decode(
$value);
371 $this->urlDecoder->expects($this->at(0))
374 ->willReturnCallback($decode);
375 $this->urlDecoder->expects($this->at(1))
378 ->willReturnCallback($decode);
381 '../image/not/a/root/filename.ext',
382 $this->helper->getRelativeUrl()
406 $this->request->expects($this->once())
411 $this->assertEquals(
$name, $this->helper->getStorageTypeName());
422 $this->helper->getStorageTypeName();
433 $this->themeFactory->expects($this->once())
436 $helper = new \Magento\Theme\Helper\Storage(
437 $this->contextHelper,
testConvertPathToIdAndIdToPath()
testGetStorageTypeNameInvalid()
getStorageTypeForNameDataProvider()
testGetThumbnailPathNotFound()
testGetAllowedExtensionsByType()
testGetStorageTypeName($type, $name)
testGetThumbnailDirectory()
if(!isset($_GET['name'])) $name