Skip to content

Commit f04803e

Browse files
author
Yuri Kovsher
committed
Merge remote-tracking branch 'tango-ce/MAGETWO-21201' into Tango_Pull_Request_Bug_Fixing
Conflicts: dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php
2 parents e3e80a0 + 9b6d019 commit f04803e

File tree

9 files changed

+463
-22
lines changed

9 files changed

+463
-22
lines changed

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Directive.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22
/**
3-
*
43
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
54
*/
65
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg;
@@ -37,15 +36,16 @@ public function execute()
3736
{
3837
$directive = $this->getRequest()->getParam('___directive');
3938
$directive = $this->urlDecoder->decode($directive);
40-
$url = $this->_objectManager->create('Magento\Email\Model\Template\Filter')->filter($directive);
39+
$imagePath = $this->_objectManager->create('Magento\Cms\Model\Template\Filter')->filter($directive);
4140
/** @var \Magento\Framework\Image\Adapter\AdapterInterface $image */
4241
$image = $this->_objectManager->get('Magento\Framework\Image\AdapterFactory')->create();
4342
$response = $this->getResponse();
4443
try {
45-
$image->open($url);
44+
$image->open($imagePath);
4645
$response->setHeader('Content-Type', $image->getMimeType())->setBody($image->getImage());
4746
} catch (\Exception $e) {
48-
$image->open($this->_objectManager->get('Magento\Cms\Model\Wysiwyg\Config')->getSkinImagePlaceholderUrl());
47+
$imagePath = $this->_objectManager->get('Magento\Cms\Model\Wysiwyg\Config')->getSkinImagePlaceholderPath();
48+
$image->open($imagePath);
4949
$response->setHeader('Content-Type', $image->getMimeType())->setBody($image->getImage());
5050
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
5151
}

app/code/Magento/Cms/Model/Template/Filter.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,16 @@ public function setUseSessionInUrl($flag)
2727
$this->_useSessionInUrl = (bool)$flag;
2828
return $this;
2929
}
30+
31+
/**
32+
* Retrieve media file URL directive
33+
*
34+
* @param string[] $construction
35+
* @return string
36+
*/
37+
public function mediaDirective($construction)
38+
{
39+
$params = $this->_getIncludeParameters($construction[2]);
40+
return $this->_storeManager->getStore()->getBaseMediaDir() . '/' . $params['url'];
41+
}
3042
}

app/code/Magento/Cms/Model/Wysiwyg/Config.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class Config extends \Magento\Framework\Object
1919
*/
2020
const WYSIWYG_STATUS_CONFIG_PATH = 'cms/wysiwyg/enabled';
2121

22+
/**
23+
*
24+
*/
25+
const WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID = 'Magento_Cms::images/wysiwyg_skin_image.png';
26+
2227
/**
2328
* Wysiwyg status hidden
2429
*/
@@ -78,6 +83,11 @@ class Config extends \Magento\Framework\Object
7883
*/
7984
protected $_backendUrl;
8085

86+
/**
87+
* @var \Magento\Store\Model\StoreManagerInterface
88+
*/
89+
protected $_storeManager;
90+
8191
/**
8292
* @param \Magento\Backend\Model\UrlInterface $backendUrl
8393
* @param \Magento\Framework\Event\ManagerInterface $eventManager
@@ -86,6 +96,7 @@ class Config extends \Magento\Framework\Object
8696
* @param \Magento\Core\Model\Variable\Config $variableConfig
8797
* @param \Magento\Widget\Model\Widget\Config $widgetConfig
8898
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
99+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
89100
* @param array $windowSize
90101
* @param array $data
91102
*/
@@ -97,6 +108,7 @@ public function __construct(
97108
\Magento\Core\Model\Variable\Config $variableConfig,
98109
\Magento\Widget\Model\Widget\Config $widgetConfig,
99110
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
111+
\Magento\Store\Model\StoreManagerInterface $storeManager,
100112
array $windowSize = [],
101113
array $data = []
102114
) {
@@ -108,6 +120,7 @@ public function __construct(
108120
$this->_variableConfig = $variableConfig;
109121
$this->_widgetConfig = $widgetConfig;
110122
$this->_windowSize = $windowSize;
123+
$this->_storeManager = $storeManager;
111124
parent::__construct($data);
112125
}
113126

@@ -183,13 +196,15 @@ public function getConfig($data = [])
183196
}
184197

185198
/**
186-
* Return URL for skin images placeholder
199+
* Return path for skin images placeholder
187200
*
188201
* @return string
189202
*/
190-
public function getSkinImagePlaceholderUrl()
203+
public function getSkinImagePlaceholderPath()
191204
{
192-
return $this->_assetRepo->getUrl('Magento_Cms::images/wysiwyg_skin_image.png');
205+
$staticPath = $this->_storeManager->getStore()->getBaseStaticDir();
206+
$placeholderPath = $this->_assetRepo->createAsset(self::WYSIWYG_SKIN_IMAGE_PLACEHOLDER_ID)->getPath();
207+
return $staticPath . '/' . $placeholderPath;
193208
}
194209

195210
/**

app/code/Magento/Store/Model/Store.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,26 @@ public function getBaseUrl($type = \Magento\Framework\UrlInterface::URL_TYPE_LIN
594594
return $this->_baseUrlCache[$cacheKey];
595595
}
596596

597+
/**
598+
* Retrieve base media directory path
599+
*
600+
* @return string
601+
*/
602+
public function getBaseMediaDir()
603+
{
604+
return $this->filesystem->getUri(DirectoryList::MEDIA);
605+
}
606+
607+
/**
608+
* Retrieve base static directory path
609+
*
610+
* @return string
611+
*/
612+
public function getBaseStaticDir()
613+
{
614+
return $this->filesystem->getUri(DirectoryList::STATIC_VIEW);
615+
}
616+
597617
/**
598618
* Append script file name to url in case when server rewrites are disabled
599619
*

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,6 +2015,8 @@
20152015
['getLinksConfig', 'Magento\Downloadable\Block\Catalog\Product\Links'],
20162016
['getAuthorizationAmounts', 'Magento\Paypal\Model\Config'],
20172017
['cleanTransactions', 'Magento\Paypal\Model\Observer'],
2018+
['getSkinImagePlaceholderUrl', 'Magento\Cms\Model\Wysiwyg\Config']
2019+
['cleanTransactions', 'Magento\Paypal\Model\Observer'],
20182020
['compareIndexColumnProperties', 'Magento\Catalog\Model\Resource\Helper'],
20192021
['getIsNullNotNullCondition', 'Magento\Catalog\Model\Resource\Helper'],
20202022
['_getCategoryPath', 'Magento\Catalog\Model\Resource\Setup'],
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
4+
*/
5+
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg;
6+
7+
/**
8+
* @covers \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive
9+
*/
10+
class DirectiveTest extends \PHPUnit_Framework_TestCase
11+
{
12+
const IMAGE_PATH = 'pub/media/wysiwyg/image.jpg';
13+
14+
/**
15+
* @var \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive
16+
*/
17+
protected $wysiwygDirective;
18+
19+
/**
20+
* @var \Magento\Backend\App\Action\Context|\PHPUnit_Framework_MockObject_MockObject
21+
*/
22+
protected $actionContextMock;
23+
24+
/**
25+
* @var \Magento\Framework\App\RequestInterface|\PHPUnit_Framework_MockObject_MockObject
26+
*/
27+
protected $requestMock;
28+
29+
/**
30+
* @var \Magento\Framework\Url\DecoderInterface|\PHPUnit_Framework_MockObject_MockObject
31+
*/
32+
protected $urlDecoderMock;
33+
34+
/**
35+
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
protected $objectManagerMock;
38+
39+
/**
40+
* @var \Magento\Cms\Model\Template\Filter|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
protected $templateFilterMock;
43+
44+
/**
45+
* @var \Magento\Framework\Image\AdapterFactory|\PHPUnit_Framework_MockObject_MockObject
46+
*/
47+
protected $imageAdapterFactoryMock;
48+
49+
/**
50+
* @var \Magento\Framework\Image\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
51+
*/
52+
protected $imageAdapterMock;
53+
54+
/**
55+
* @var \Magento\Framework\App\ResponseInterface|\PHPUnit_Framework_MockObject_MockObject
56+
*/
57+
protected $responseMock;
58+
59+
/**
60+
* @var \Magento\Cms\Model\Wysiwyg\Config|\PHPUnit_Framework_MockObject_MockObject
61+
*/
62+
protected $wysiwygConfigMock;
63+
64+
/**
65+
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
66+
*/
67+
protected $loggerMock;
68+
69+
protected function setUp()
70+
{
71+
$this->actionContextMock = $this->getMockBuilder('Magento\Backend\App\Action\Context')
72+
->disableOriginalConstructor()
73+
->getMock();
74+
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
75+
->disableOriginalConstructor()
76+
->getMock();
77+
$this->urlDecoderMock = $this->getMockBuilder('Magento\Framework\Url\DecoderInterface')
78+
->disableOriginalConstructor()
79+
->getMock();
80+
$this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
81+
->disableOriginalConstructor()
82+
->getMock();
83+
$this->templateFilterMock = $this->getMockBuilder('Magento\Cms\Model\Template\Filter')
84+
->disableOriginalConstructor()
85+
->getMock();
86+
$this->imageAdapterFactoryMock = $this->getMockBuilder('Magento\Framework\Image\AdapterFactory')
87+
->disableOriginalConstructor()
88+
->getMock();
89+
$this->imageAdapterMock = $this->getMockBuilder('Magento\Framework\Image\Adapter\AdapterInterface')
90+
->disableOriginalConstructor()
91+
->setMethods(
92+
[
93+
'getMimeType',
94+
'getColorAt',
95+
'getImage',
96+
'watermark',
97+
'refreshImageDimensions',
98+
'checkDependencies',
99+
'createPngFromString',
100+
'open',
101+
'resize',
102+
'crop',
103+
'save',
104+
'rotate'
105+
]
106+
)
107+
->getMock();
108+
$this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface')
109+
->disableOriginalConstructor()
110+
->setMethods(['setHeader', 'setBody', 'sendResponse'])
111+
->getMock();
112+
$this->wysiwygConfigMock = $this->getMockBuilder('Magento\Cms\Model\Wysiwyg\Config')
113+
->disableOriginalConstructor()
114+
->getMock();
115+
$this->loggerMock = $this->getMockBuilder('Psr\Log\LoggerInterface')
116+
->disableOriginalConstructor()
117+
->getMock();
118+
119+
$this->actionContextMock->expects($this->any())
120+
->method('getRequest')
121+
->willReturn($this->requestMock);
122+
$this->actionContextMock->expects($this->any())
123+
->method('getResponse')
124+
->willReturn($this->responseMock);
125+
$this->actionContextMock->expects($this->any())
126+
->method('getObjectManager')
127+
->willReturn($this->objectManagerMock);
128+
129+
$objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
130+
$this->wysiwygDirective = $objectManager->getObject(
131+
'Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive',
132+
[
133+
'context' => $this->actionContextMock,
134+
'urlDecoder' => $this->urlDecoderMock
135+
]
136+
);
137+
}
138+
139+
/**
140+
* @covers \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::execute
141+
*/
142+
public function testExecute()
143+
{
144+
$mimeType = 'image/jpeg';
145+
$imageBody = 'abcdefghijklmnopqrstuvwxyz0123456789';
146+
$this->prepareExecuteTest();
147+
148+
$this->imageAdapterMock->expects($this->once())
149+
->method('open')
150+
->with(self::IMAGE_PATH);
151+
$this->imageAdapterMock->expects($this->once())
152+
->method('getMimeType')
153+
->willReturn($mimeType);
154+
$this->responseMock->expects($this->once())
155+
->method('setHeader')
156+
->with('Content-Type', $mimeType)
157+
->willReturnSelf();
158+
$this->imageAdapterMock->expects($this->once())
159+
->method('getImage')
160+
->willReturn($imageBody);
161+
$this->responseMock->expects($this->once())
162+
->method('setBody')
163+
->with($imageBody)
164+
->willReturnSelf();
165+
166+
$this->wysiwygDirective->execute();
167+
}
168+
169+
/**
170+
* @covers \Magento\Cms\Controller\Adminhtml\Wysiwyg\Directive::execute
171+
*/
172+
public function testExecuteException()
173+
{
174+
$exception = new \Exception('epic fail');
175+
$placeholderPath = 'pub/static/adminhtml/Magento/backend/en_US/Magento_Cms/images/wysiwyg_skin_image.png';
176+
$mimeType = 'image/png';
177+
$imageBody = '0123456789abcdefghijklmnopqrstuvwxyz';
178+
$this->prepareExecuteTest();
179+
180+
$this->imageAdapterMock->expects($this->at(0))
181+
->method('open')
182+
->with(self::IMAGE_PATH)
183+
->willThrowException($exception);
184+
$this->wysiwygConfigMock->expects($this->once())
185+
->method('getSkinImagePlaceholderPath')
186+
->willReturn($placeholderPath);
187+
$this->imageAdapterMock->expects($this->at(1))
188+
->method('open')
189+
->with($placeholderPath);
190+
$this->imageAdapterMock->expects($this->once())
191+
->method('getMimeType')
192+
->willReturn($mimeType);
193+
$this->responseMock->expects($this->once())
194+
->method('setHeader')
195+
->with('Content-Type', $mimeType)
196+
->willReturnSelf();
197+
$this->imageAdapterMock->expects($this->once())
198+
->method('getImage')
199+
->willReturn($imageBody);
200+
$this->responseMock->expects($this->once())
201+
->method('setBody')
202+
->with($imageBody)
203+
->willReturnSelf();
204+
$this->loggerMock->expects($this->once())
205+
->method('critical')
206+
->with($exception);
207+
208+
$this->wysiwygDirective->execute();
209+
}
210+
211+
protected function prepareExecuteTest()
212+
{
213+
$directiveParam = 'e3ttZWRpYSB1cmw9Ind5c2l3eWcvYnVubnkuanBnIn19';
214+
$directive = '{{media url="wysiwyg/image.jpg"}}';
215+
216+
$this->requestMock->expects($this->once())
217+
->method('getParam')
218+
->with('___directive')
219+
->willReturn($directiveParam);
220+
$this->urlDecoderMock->expects($this->once())
221+
->method('decode')
222+
->with($directiveParam)
223+
->willReturn($directive);
224+
$this->objectManagerMock->expects($this->once())
225+
->method('create')
226+
->with('Magento\Cms\Model\Template\Filter')
227+
->willReturn($this->templateFilterMock);
228+
$this->templateFilterMock->expects($this->once())
229+
->method('filter')
230+
->with($directive)
231+
->willReturn(self::IMAGE_PATH);
232+
$this->objectManagerMock->expects($this->any())
233+
->method('get')
234+
->willReturnMap(
235+
[
236+
['Magento\Framework\Image\AdapterFactory', $this->imageAdapterFactoryMock],
237+
['Magento\Cms\Model\Wysiwyg\Config', $this->wysiwygConfigMock],
238+
['Psr\Log\LoggerInterface', $this->loggerMock]
239+
]
240+
);
241+
$this->imageAdapterFactoryMock->expects($this->once())
242+
->method('create')
243+
->willReturn($this->imageAdapterMock);
244+
}
245+
}

0 commit comments

Comments
 (0)