Skip to content

Commit 7592059

Browse files
author
Karpenko, Oleksandr
committed
MAGETWO-57656: Base url should be processed while sending email
1 parent 2ac859e commit 7592059

File tree

4 files changed

+80
-4
lines changed

4 files changed

+80
-4
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66
namespace Magento\Email\Model\Template;
77

8+
use Magento\Framework\App\Filesystem\DirectoryList;
89
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Filesystem;
911
use Magento\Framework\View\Asset\ContentProcessorException;
1012
use Magento\Framework\View\Asset\ContentProcessorInterface;
1113

@@ -159,6 +161,11 @@ class Filter extends \Magento\Framework\Filter\Template
159161
*/
160162
private $cssProcessor;
161163

164+
/**
165+
* @var \Magento\Framework\Filesystem\Directory\ReadInterface
166+
*/
167+
private $pubDirectory;
168+
162169
/**
163170
* @param \Magento\Framework\Stdlib\StringUtils $string
164171
* @param \Psr\Log\LoggerInterface $logger
@@ -221,6 +228,18 @@ private function getCssProcessor()
221228
return $this->cssProcessor;
222229
}
223230

231+
/**
232+
* @deprecated
233+
* @return Filesystem\Directory\ReadInterface
234+
*/
235+
private function getPubDirectory()
236+
{
237+
if (!$this->pubDirectory) {
238+
$this->pubDirectory = ObjectManager::getInstance()->get(Filesystem::class)->getDirectoryRead(DirectoryList::STATIC_VIEW);
239+
}
240+
return $this->pubDirectory;
241+
}
242+
224243
/**
225244
* Set use absolute links flag
226245
*
@@ -909,7 +928,12 @@ public function getCssFilesContent(array $files)
909928
try {
910929
foreach ($files as $file) {
911930
$asset = $this->_assetRepo->createAsset($file, $designParams);
912-
$css .= $asset->getContent();
931+
$filePath = $asset->getContext()->getPath() . '/' . $file;
932+
if ($this->getPubDirectory()->isExist($filePath)) {
933+
$css .= $this->getPubDirectory()->readFile($filePath);
934+
} else {
935+
$css .= $asset->getContent();
936+
}
913937
}
914938
} catch (ContentProcessorException $exception) {
915939
$css = $exception->getMessage();

app/code/Magento/Email/Test/Unit/Model/Template/FilterTest.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
namespace Magento\Email\Test\Unit\Model\Template;
77
use Magento\Email\Model\Template\Css\Processor;
88
use Magento\Email\Model\Template\Filter;
9+
use Magento\Framework\App\Area;
10+
use Magento\Framework\Filesystem\Directory\ReadInterface;
911

1012
/**
1113
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -269,7 +271,7 @@ public function testApplyInlineCss($html, $css, $expectedResults)
269271
->will($this->returnValue($css));
270272

271273
$designParams = [
272-
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
274+
'area' => Area::AREA_FRONTEND,
273275
'theme' => 'themeId',
274276
'locale' => 'localeId',
275277
];
@@ -280,6 +282,56 @@ public function testApplyInlineCss($html, $css, $expectedResults)
280282
}
281283
}
282284

285+
public function testGetCssFilesContent()
286+
{
287+
$file = 'css/email.css';
288+
$path = Area::AREA_FRONTEND . '/themeId/localeId';
289+
$css = 'p{color:black}';
290+
$designParams = [
291+
'area' => Area::AREA_FRONTEND,
292+
'theme' => 'themeId',
293+
'locale' => 'localeId',
294+
];
295+
296+
$filter = $this->getModel();
297+
298+
$asset = $this->getMockBuilder(\Magento\Framework\View\Asset\File::class)
299+
->disableOriginalConstructor()
300+
->getMock();
301+
$fallbackContext = $this->getMockBuilder(\Magento\Framework\View\Asset\File\FallbackContext::class)
302+
->disableOriginalConstructor()
303+
->getMock();
304+
$fallbackContext->expects($this->once())
305+
->method('getPath')
306+
->willReturn($path);
307+
$asset->expects($this->atLeastOnce())
308+
->method('getContext')
309+
->willReturn($fallbackContext);
310+
$this->assetRepo->expects($this->once())
311+
->method('createAsset')
312+
->with($file, $designParams)
313+
->willReturn($asset);
314+
315+
$pubDirectory = $this->getMockBuilder(ReadInterface::class)
316+
->getMockForAbstractClass();
317+
$reflectionClass = new \ReflectionClass(Filter::class);
318+
$reflectionProperty = $reflectionClass->getProperty('pubDirectory');
319+
$reflectionProperty->setAccessible(true);
320+
$reflectionProperty->setValue($filter, $pubDirectory);
321+
$pubDirectory->expects($this->once())
322+
->method('isExist')
323+
->with($path . '/' . $file)
324+
->willReturn(true);
325+
$pubDirectory->expects($this->once())
326+
->method('readFile')
327+
->with($path . '/' . $file)
328+
->willReturn($css);
329+
330+
$filter->setDesignParams($designParams);
331+
332+
$this->assertEquals($css, $filter->getCssFilesContent([$file]));
333+
}
334+
283335
/**
284336
* @return array
285337
*/

lib/internal/Magento/Framework/View/Asset/NotationResolver/Variable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function getPlaceholderValue($placeholder)
7070

7171
switch ($placeholder) {
7272
case self::VAR_BASE_URL_PATH:
73-
return '{{' . self::VAR_BASE_URL_PATH . '}}/' . $context->getAreaCode() .
73+
return '{{' . self::VAR_BASE_URL_PATH . '}}' . $context->getAreaCode() .
7474
($context->getThemePath() ? '/' . $context->getThemePath() . '/' : '') .
7575
'{{locale}}';
7676
default:

lib/internal/Magento/Framework/View/Test/Unit/Asset/NotationResolver/VariableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testConvertVariableNotation($path, $expectedResult)
6969
public function convertVariableNotationDataProvider()
7070
{
7171
return [
72-
['{{base_url_path}}/file.ext', '{{base_url_path}}/frontend/Magento/blank/{{locale}}/file.ext'],
72+
['{{base_url_path}}/file.ext', '{{base_url_path}}frontend/Magento/blank/{{locale}}/file.ext'],
7373
];
7474
}
7575
}

0 commit comments

Comments
 (0)