Skip to content

Commit 502ba1c

Browse files
author
Bohdan Korablov
committed
Merge remote-tracking branch 'tangoc/MAGETWO-44455' into new_pr_bugs
2 parents b3b23d4 + 96e0d09 commit 502ba1c

File tree

7 files changed

+168
-51
lines changed

7 files changed

+168
-51
lines changed

app/code/Magento/Email/Block/Adminhtml/Template/Preview.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class Preview extends \Magento\Backend\Block\Widget
2323
*/
2424
protected $_emailFactory;
2525

26+
/**
27+
* @var string
28+
*/
29+
protected $profilerName = 'email_template_proccessing';
30+
2631
/**
2732
* @param \Magento\Backend\Block\Template\Context $context
2833
* @param \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode
@@ -48,16 +53,10 @@ public function __construct(
4853
protected function _toHtml()
4954
{
5055
$storeId = $this->getAnyStoreView()->getId();
51-
5256
/** @var $template \Magento\Email\Model\Template */
53-
$template = $this->_emailFactory->create(
54-
['data' => [
55-
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
56-
'store' => $storeId
57-
]]
58-
);
59-
$id = (int) $this->getRequest()->getParam('id');
60-
if ($id) {
57+
$template = $this->_emailFactory->create();
58+
59+
if ($id = (int)$this->getRequest()->getParam('id')) {
6160
$template->load($id);
6261
} else {
6362
$template->setTemplateType($this->getRequest()->getParam('type'));
@@ -67,7 +66,7 @@ protected function _toHtml()
6766

6867
$template->setTemplateText($this->_maliciousCode->filter($template->getTemplateText()));
6968

70-
\Magento\Framework\Profiler::start("email_template_proccessing");
69+
\Magento\Framework\Profiler::start($this->profilerName);
7170

7271
$template->emulateDesign($storeId);
7372
$templateProcessed = $this->_appState->emulateAreaCode(
@@ -80,7 +79,7 @@ protected function _toHtml()
8079
$templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
8180
}
8281

83-
\Magento\Framework\Profiler::stop("email_template_proccessing");
82+
\Magento\Framework\Profiler::stop($this->profilerName);
8483

8584
return $templateProcessed;
8685
}

app/code/Magento/Email/Controller/Adminhtml/Email/Template/Preview.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class Preview extends \Magento\Email\Controller\Adminhtml\Email\Template
1616
public function execute()
1717
{
1818
try {
19-
$this->_view->loadLayout('systemPreview');
19+
$this->_view->loadLayout();
20+
$this->_view->getPage()->getConfig()->getTitle()->prepend(__('Email Preview'));
2021
$this->_view->renderLayout();
2122
} catch (\Exception $e) {
2223
$this->messageManager->addError(__('An error occurred. The email template can not be opened for preview.'));

app/code/Magento/Email/Test/Unit/Block/Adminhtml/Template/PreviewTest.php

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,42 +46,37 @@ public function testToHtml($requestParamMap)
4646
'revertDesign'
4747
])
4848
->disableOriginalConstructor()
49-
->getMock()
50-
;
49+
->getMock();
5150
$template->expects($this->once())
5251
->method('getProcessedTemplate')
5352
->with($this->equalTo([]))
54-
->will($this->returnValue(self::MALICIOUS_TEXT));
55-
$designConfigData = [
56-
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
57-
'store' => $storeId
58-
];
53+
->willReturn(self::MALICIOUS_TEXT);
54+
$designConfigData = [];
5955
$template->expects($this->atLeastOnce())
6056
->method('getDesignConfig')
61-
->will($this->returnValue(new \Magento\Framework\DataObject(
57+
->willReturn(new \Magento\Framework\DataObject(
6258
$designConfigData
63-
)));
59+
));
6460
$emailFactory = $this->getMock('Magento\Email\Model\TemplateFactory', ['create'], [], '', false);
65-
$emailFactory->expects($this->once())
61+
$emailFactory->expects($this->any())
6662
->method('create')
67-
->with($this->equalTo(['data' => $designConfigData]))
68-
->will($this->returnValue($template));
63+
->willReturn($template);
6964

7065
$request = $this->getMock('Magento\Framework\App\RequestInterface');
71-
$request->expects($this->any())->method('getParam')->will($this->returnValueMap($requestParamMap));
66+
$request->expects($this->any())->method('getParam')->willReturnMap($requestParamMap);
7267
$eventManage = $this->getMock('Magento\Framework\Event\ManagerInterface');
7368
$scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
7469
$design = $this->getMock('Magento\Framework\View\DesignInterface');
7570
$store = $this->getMock('Magento\Store\Model\Store', ['getId', '__wakeup'], [], '', false);
76-
$store->expects($this->any())->method('getId')->will($this->returnValue($storeId));
71+
$store->expects($this->any())->method('getId')->willReturn($storeId);
7772
$storeManager = $this->getMockBuilder('\Magento\Store\Model\StoreManagerInterface')
7873
->disableOriginalConstructor()
7974
->getMock();
8075
$storeManager->expects($this->atLeastOnce())
8176
->method('getDefaultStoreView')
82-
->will($this->returnValue($store));
83-
$storeManager->expects($this->any())->method('getDefaultStoreView')->will($this->returnValue(null));
84-
$storeManager->expects($this->any())->method('getStores')->will($this->returnValue([$store]));
77+
->willReturn($store);
78+
$storeManager->expects($this->any())->method('getDefaultStoreView')->willReturn(null);
79+
$storeManager->expects($this->any())->method('getStores')->willReturn([$store]);
8580
$appState = $this->getMockBuilder('Magento\Framework\App\State')
8681
->setConstructorArgs([
8782
$scopeConfig
@@ -94,12 +89,12 @@ public function testToHtml($requestParamMap)
9489
['getRequest', 'getEventManager', 'getScopeConfig', 'getDesignPackage', 'getStoreManager', 'getAppState'],
9590
[], '', false
9691
);
97-
$context->expects($this->any())->method('getRequest')->will($this->returnValue($request));
98-
$context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManage));
99-
$context->expects($this->any())->method('getScopeConfig')->will($this->returnValue($scopeConfig));
100-
$context->expects($this->any())->method('getDesignPackage')->will($this->returnValue($design));
101-
$context->expects($this->any())->method('getStoreManager')->will($this->returnValue($storeManager));
102-
$context->expects($this->once())->method('getAppState')->will($this->returnValue($appState));
92+
$context->expects($this->any())->method('getRequest')->willReturn($request);
93+
$context->expects($this->any())->method('getEventManager')->willReturn($eventManage);
94+
$context->expects($this->any())->method('getScopeConfig')->willReturn($scopeConfig);
95+
$context->expects($this->any())->method('getDesignPackage')->willReturn($design);
96+
$context->expects($this->any())->method('getStoreManager')->willReturn($storeManager);
97+
$context->expects($this->once())->method('getAppState')->willReturn($appState);
10398

10499
$maliciousCode = $this->getMock(
105100
'Magento\Framework\Filter\Input\MaliciousCode',
@@ -108,9 +103,12 @@ public function testToHtml($requestParamMap)
108103
'',
109104
false
110105
);
111-
$maliciousCode->expects($this->once())->method('filter')->with($this->equalTo($requestParamMap[1][2]))
112-
->will($this->returnValue(self::MALICIOUS_TEXT));
106+
$maliciousCode->expects($this->once())
107+
->method('filter')
108+
->with($this->equalTo($requestParamMap[1][2]))
109+
->willReturn(self::MALICIOUS_TEXT);
113110

111+
/** @var \Magento\Email\Block\Adminhtml\Template\Preview $preview */
114112
$preview = $this->objectManagerHelper->getObject(
115113
'Magento\Email\Block\Adminhtml\Template\Preview',
116114
[
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Email\Test\Unit\Controller\Adminhtml\Email\Template;
7+
8+
use Magento\Email\Controller\Adminhtml\Email\Template\Preview;
9+
use Magento\Framework\App\Action\Context;
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\App\View;
12+
use Magento\Framework\Registry;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use Magento\Framework\View\Config;
15+
use Magento\Framework\View\Page\Title;
16+
use Magento\Framework\View\Result\Page;
17+
18+
/**
19+
* Preview Test
20+
*/
21+
class PreviewTest extends \PHPUnit_Framework_TestCase
22+
{
23+
/**
24+
* @var Preview
25+
*/
26+
protected $object;
27+
28+
/**
29+
* @var Context
30+
*/
31+
protected $context;
32+
33+
/**
34+
* @var Registry|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
protected $coreRegistryMock;
37+
38+
/**
39+
* @var View|\PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
protected $viewMock;
42+
43+
/**
44+
* @var RequestInterface|\PHPUnit_Framework_MockObject_MockObject
45+
*/
46+
protected $requestMock;
47+
48+
/**
49+
* @var Page|\PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
protected $pageMock;
52+
53+
/**
54+
* @var Config|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
protected $pageConfigMock;
57+
58+
/**
59+
* @var Title|\PHPUnit_Framework_MockObject_MockObject
60+
*/
61+
protected $pageTitleMock;
62+
63+
protected function setUp()
64+
{
65+
$objectManager = new ObjectManager($this);
66+
67+
$this->coreRegistryMock = $this->getMockBuilder('Magento\Framework\Registry')
68+
->disableOriginalConstructor()
69+
->getMock();
70+
$this->viewMock = $this->getMockBuilder('Magento\Framework\App\View')
71+
->disableOriginalConstructor()
72+
->getMock();
73+
$this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface')
74+
->getMock();
75+
$this->pageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page')
76+
->disableOriginalConstructor()
77+
->setMethods(['getConfig'])
78+
->getMock();
79+
$this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config')
80+
->setMethods(['getTitle'])
81+
->disableOriginalConstructor()
82+
->getMock();
83+
$this->pageTitleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title')
84+
->setMethods(['prepend'])
85+
->disableOriginalConstructor()
86+
->getMock();
87+
88+
$this->context = $objectManager->getObject('Magento\Backend\App\Action\Context', [
89+
'request' => $this->requestMock,
90+
'view' => $this->viewMock
91+
]);
92+
$this->object = $objectManager->getObject('Magento\Email\Controller\Adminhtml\Email\Template\Preview', [
93+
'context' => $this->context,
94+
'coreRegistry' => $this->coreRegistryMock,
95+
]);
96+
}
97+
98+
public function testExecute()
99+
{
100+
$this->viewMock->expects($this->once())
101+
->method('getPage')
102+
->willReturn($this->pageMock);
103+
$this->pageMock->expects($this->once())
104+
->method('getConfig')
105+
->willReturn($this->pageConfigMock);
106+
$this->pageConfigMock->expects($this->once())
107+
->method('getTitle')
108+
->willReturn($this->pageTitleMock);
109+
$this->pageTitleMock->expects($this->once())
110+
->method('prepend')
111+
->willReturnSelf();
112+
113+
$this->assertNull($this->object->execute());
114+
}
115+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9+
<body>
10+
<referenceContainer name="page.content">
11+
<block name="preview.page.content" class="Magento\Framework\View\Element\Template" template="Magento_Email::template/preview.phtml">
12+
<block class="Magento\Email\Block\Adminhtml\Template\Preview" name="content" as="content"/>
13+
</block>
14+
</referenceContainer>
15+
</body>
16+
</page>

app/code/Magento/Email/view/adminhtml/layout/systemPreview.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/code/Magento/Email/view/adminhtml/templates/template/preview.phtml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © 2015 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
/* @var $block \Magento\Email\Block\Adminhtml\Template\Preview */
68
?>
79
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
810
<html lang="en">

0 commit comments

Comments
 (0)