Skip to content

Commit 5a9dea1

Browse files
author
Oleh Posyniak
committed
MAGETWO-44455: Email Templates - When new email template created, clicking Preview button, display empty page.
1 parent e0a56a7 commit 5a9dea1

File tree

6 files changed

+146
-26
lines changed

6 files changed

+146
-26
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.'));
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
->disableOriginalConstructor()
75+
->getMock();
76+
$this->pageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page')
77+
->disableOriginalConstructor()
78+
->setMethods(['getConfig'])
79+
->getMock();
80+
$this->pageConfigMock = $this->getMockBuilder('Magento\Framework\View\Page\Config')
81+
->setMethods(['getTitle'])
82+
->disableOriginalConstructor()
83+
->getMock();
84+
$this->pageTitleMock = $this->getMockBuilder('Magento\Framework\View\Page\Title')
85+
->setMethods(['prepend'])
86+
->disableOriginalConstructor()
87+
->getMock();
88+
89+
$this->context = $objectManager->getObject('Magento\Backend\App\Action\Context', [
90+
'request' => $this->requestMock,
91+
'view' => $this->viewMock
92+
]);
93+
$this->object = $objectManager->getObject('Magento\Email\Controller\Adminhtml\Email\Template\Preview', [
94+
'context' => $this->context,
95+
'coreRegistry' => $this->coreRegistryMock,
96+
]);
97+
}
98+
99+
public function testExecute()
100+
{
101+
$this->viewMock->expects($this->once())
102+
->method('getPage')
103+
->willReturn($this->pageMock);
104+
$this->pageMock->expects($this->once())
105+
->method('getConfig')
106+
->willReturn($this->pageConfigMock);
107+
$this->pageConfigMock->expects($this->once())
108+
->method('getTitle')
109+
->willReturn($this->pageTitleMock);
110+
$this->pageTitleMock->expects($this->once())
111+
->method('prepend')
112+
->willReturnSelf();
113+
114+
$this->assertNull($this->object->execute());
115+
}
116+
}
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)