From 1ec5d168475dcbbfeab5de122f7e5fcc62851821 Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 16 Jul 2015 17:11:11 -0500 Subject: [PATCH 01/24] REL-12 HTML markup in Plain Text Templates - code formatting issues --- .../Customer/Model/AccountManagement.php | 88 +++++++------------ .../Magento/Email/Model/AbstractTemplate.php | 9 +- 2 files changed, 37 insertions(+), 60 deletions(-) diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index aa5a30ea4c53b..3ceb2eb9d094c 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -20,6 +20,7 @@ use Magento\Customer\Model\Customer as CustomerModel; use Magento\Customer\Model\Metadata\Validator; use Magento\Framework\Api\ExtensibleDataObjectConverter; +use Magento\Framework\App\Area; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Encryption\EncryptorInterface as Encryptor; use Magento\Framework\Event\ManagerInterface; @@ -34,6 +35,7 @@ use Magento\Framework\Exception\State\InvalidTransitionException; use Magento\Framework\ObjectFactory; use Magento\Framework\Registry; +use Magento\Store\Model\ScopeInterface; use Psr\Log\LoggerInterface as PsrLogger; use Magento\Framework\Exception\MailException; use Magento\Framework\Mail\Template\TransportBuilder; @@ -567,20 +569,11 @@ protected function sendEmailConfirmation(CustomerInterface $customer, $redirectU { try { if ($this->isConfirmationRequired($customer)) { - $this->sendNewAccountEmail( - $customer, - self::NEW_ACCOUNT_EMAIL_CONFIRMATION, - $redirectUrl, - $customer->getStoreId() - ); + $templateType = self::NEW_ACCOUNT_EMAIL_CONFIRMATION; } else { - $this->sendNewAccountEmail( - $customer, - self::NEW_ACCOUNT_EMAIL_REGISTERED, - $redirectUrl, - $customer->getStoreId() - ); + $templateType = self::NEW_ACCOUNT_EMAIL_REGISTERED; } + $this->sendNewAccountEmail($customer, $templateType, $redirectUrl, $customer->getStoreId()); } catch (MailException $e) { // If we are not able to send a new account email, this should be ignored $this->logger->critical($e); @@ -682,10 +675,11 @@ protected function createPasswordHash($password) /** * {@inheritdoc} */ - public function validate(\Magento\Customer\Api\Data\CustomerInterface $customer) + public function validate(CustomerInterface $customer) { $customerErrors = $this->validator->validateData( - $this->extensibleDataObjectConverter->toFlatArray($customer, [], '\Magento\Customer\Api\Data\CustomerInterface'), + $this->extensibleDataObjectConverter + ->toFlatArray($customer, [], '\Magento\Customer\Api\Data\CustomerInterface'), [], 'customer' ); @@ -852,27 +846,24 @@ protected function sendPasswordResetNotificationEmail($customer) } $customerEmailData = $this->getFullCustomerObject($customer); - /** @var \Magento\Framework\Mail\TransportInterface $transport */ - $transport = $this->transportBuilder->setTemplateIdentifier( - $this->scopeConfig->getValue( - self::XML_PATH_RESET_PASSWORD_TEMPLATE, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - $storeId - ) - )->setTemplateOptions( - ['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId] - )->setTemplateVars( - ['customer' => $customerEmailData, 'store' => $this->storeManager->getStore($storeId)] - )->setFrom( - $this->scopeConfig->getValue( + + $templateId = $this->scopeConfig->getValue( + self::XML_PATH_RESET_PASSWORD_TEMPLATE, + ScopeInterface::SCOPE_STORE, + $storeId + ); + + $transport = $this->transportBuilder->setTemplateIdentifier($templateId) + ->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId]) + ->setTemplateVars(['customer' => $customerEmailData, 'store' => $this->storeManager->getStore($storeId)]) + ->setFrom($this->scopeConfig->getValue( self::XML_PATH_FORGOT_EMAIL_IDENTITY, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + ScopeInterface::SCOPE_STORE, $storeId - ) - )->addTo( - $customer->getEmail(), - $this->customerViewHelper->getCustomerName($customer) - )->getTransport(); + )) + ->addTo($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer)) + ->getTransport(); + $transport->sendMessage(); return $this; @@ -925,19 +916,14 @@ protected function getTemplateTypes() */ protected function sendEmailTemplate($customer, $template, $sender, $templateParams = [], $storeId = null) { - /** @var \Magento\Framework\Mail\TransportInterface $transport */ - $transport = $this->transportBuilder->setTemplateIdentifier( - $this->scopeConfig->getValue($template, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId) - )->setTemplateOptions( - ['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId] - )->setTemplateVars( - $templateParams - )->setFrom( - $this->scopeConfig->getValue($sender, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId) - )->addTo( - $customer->getEmail(), - $this->customerViewHelper->getCustomerName($customer) - )->getTransport(); + $templateId = $this->scopeConfig->getValue($template, ScopeInterface::SCOPE_STORE, $storeId); + $transport = $this->transportBuilder->setTemplateIdentifier($templateId) + ->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId]) + ->setTemplateVars($templateParams) + ->setFrom($this->scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId)) + ->addTo($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer)) + ->getTransport(); + $transport->sendMessage(); return $this; @@ -956,11 +942,7 @@ protected function isConfirmationRequired($customer) } $storeId = $customer->getStoreId() ? $customer->getStoreId() : null; - return (bool)$this->scopeConfig->getValue( - self::XML_PATH_IS_CONFIRM, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - $storeId - ); + return (bool)$this->scopeConfig->getValue(self::XML_PATH_IS_CONFIRM, ScopeInterface::SCOPE_STORE, $storeId); } /** @@ -1038,9 +1020,7 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken) if (is_string($passwordLinkToken) && !empty($passwordLinkToken)) { $customerSecure = $this->customerRegistry->retrieveSecureData($customer->getId()); $customerSecure->setRpToken($passwordLinkToken); - $customerSecure->setRpTokenCreatedAt( - (new \DateTime())->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT) - ); + $customerSecure->setRpTokenCreatedAt((new \DateTime())->format(DateTime::DATETIME_PHP_FORMAT)); $this->customerRepository->save($customer); } return true; diff --git a/app/code/Magento/Email/Model/AbstractTemplate.php b/app/code/Magento/Email/Model/AbstractTemplate.php index 308e3273ea6a4..dca62fd0709f2 100644 --- a/app/code/Magento/Email/Model/AbstractTemplate.php +++ b/app/code/Magento/Email/Model/AbstractTemplate.php @@ -160,7 +160,7 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn * @param \Magento\Framework\View\Asset\Repository $assetRepo * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param Template\Config $emailConfig + * @param \Magento\Email\Model\Template\Config $emailConfig * @param \Magento\Email\Model\TemplateFactory $templateFactory * @param \Magento\Framework\Url $urlModel * @param array $data @@ -236,11 +236,8 @@ protected function getTemplateInstance() */ public function loadByConfigPath($configPath) { - $templateId = $this->scopeConfig->getValue( - $configPath, - ScopeInterface::SCOPE_STORE, - $this->getDesignConfig()->getStore() - ); + $storeId = $this->getDesignConfig()->getStore(); + $templateId = $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId); if (is_numeric($templateId)) { // Template was overridden in backend, so load template from database From 8812f317d591b78874d826fdc236fc57cf70f4ef Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 16 Jul 2015 17:11:42 -0500 Subject: [PATCH 02/24] REL-12 HTML markup in Plain Text Templates - removed duplicate / unnecessary code --- .../Magento/Email/Model/AbstractTemplate.php | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/app/code/Magento/Email/Model/AbstractTemplate.php b/app/code/Magento/Email/Model/AbstractTemplate.php index dca62fd0709f2..75e80cd64e8f9 100644 --- a/app/code/Magento/Email/Model/AbstractTemplate.php +++ b/app/code/Magento/Email/Model/AbstractTemplate.php @@ -247,19 +247,6 @@ public function loadByConfigPath($configPath) $this->loadDefault($templateId); } - // Templates loaded via the {{template config_path=""}} syntax don't support the subject/vars/styles - // comment blocks, so strip them out - $templateText = preg_replace('//us', '', $this->getTemplateText()); - // trim copyright message - if (preg_match('/^/m', $templateText, $matches) - && strpos($matches[0], 'Copyright') > 0 - ) { - $templateText = str_replace($matches[0], '', $templateText); - } - // Remove comment lines and extra spaces - $templateText = trim(preg_replace('#\{\*.*\*\}#suU', '', $templateText)); - - $this->setTemplateText($templateText); return $this; } @@ -283,9 +270,7 @@ public function loadDefault($templateId) /** * trim copyright message */ - if (preg_match('/^/m', $templateText, $matches) - && strpos($matches[0], 'Copyright') > 0 - ) { + if (preg_match('/^/m', $templateText, $matches) && strpos($matches[0], 'Copyright') > 0) { $templateText = str_replace($matches[0], '', $templateText); } From 00627fa46d1aabeb946896aa14b42e43caa3fe46 Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 16 Jul 2015 17:49:36 -0500 Subject: [PATCH 03/24] REL-12 HTML markup in Plain Text Templates - implemented tag stripping in children templates loaded into plain-text --- .../Magento/Email/Model/AbstractTemplate.php | 36 +++++++++++++------ .../Magento/Email/Model/BackendTemplate.php | 3 ++ app/code/Magento/Email/Model/Template.php | 2 ++ .../Magento/Email/Model/Template/Filter.php | 4 +++ .../Magento/Newsletter/Model/Template.php | 7 ++-- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Email/Model/AbstractTemplate.php b/app/code/Magento/Email/Model/AbstractTemplate.php index 75e80cd64e8f9..147f968426f7b 100644 --- a/app/code/Magento/Email/Model/AbstractTemplate.php +++ b/app/code/Magento/Email/Model/AbstractTemplate.php @@ -146,6 +146,11 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn */ protected $emailConfig; + /** + * @var \Magento\Framework\Filter\FilterManager + */ + protected $filterManager; + /** * @var \Magento\Framework\UrlInterface */ @@ -162,7 +167,8 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Email\Model\Template\Config $emailConfig * @param \Magento\Email\Model\TemplateFactory $templateFactory - * @param \Magento\Framework\Url $urlModel + * @param \Magento\Framework\Filter\FilterManager $filterManager + * @param \Magento\Framework\Url|\Magento\Framework\UrlInterface $urlModel * @param array $data * * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -178,6 +184,7 @@ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, Template\Config $emailConfig, TemplateFactory $templateFactory, + \Magento\Framework\Filter\FilterManager $filterManager, \Magento\Framework\UrlInterface $urlModel, array $data = [] ) { @@ -191,6 +198,7 @@ public function __construct( $this->scopeConfig = $scopeConfig; $this->emailConfig = $emailConfig; $this->templateFactory = $templateFactory; + $this->filterManager = $filterManager; $this->urlModel = $urlModel; parent::__construct($context, $registry, null, null, $data); } @@ -205,16 +213,25 @@ public function __construct( public function getTemplateContent($configPath, array $variables) { $template = $this->getTemplateInstance(); - // Ensure child templates have the same area/store context as parent - $template->setDesignConfig($this->getDesignConfig()->toArray()); - $template->loadByConfigPath($configPath, $variables); + // Ensure child templates have the same area/store context as parent + $template->setDesignConfig($this->getDesignConfig()->toArray()) + ->loadByConfigPath($configPath, $variables) + ->setTemplateType($this->getType()) + ->setIsChildTemplate(true); + + // automatically strip tags if in a plain-text parent + if ($this->isPlain()) { + $templateText = $this->filterManager->stripTags($template->getTemplateText()); + $template->setTemplateText(trim($templateText)); + } - // Indicate that this is a child template so that when the template is being filtered, directives such as - // inlinecss can respond accordingly - $template->setIsChildTemplate(true); + $processedTemplate = $template->getProcessedTemplate($variables); + if ($this->isPlain()) { + $processedTemplate = trim($processedTemplate); + } - return $template->getProcessedTemplate($variables); + return $processedTemplate; } /** @@ -240,13 +257,10 @@ public function loadByConfigPath($configPath) $templateId = $this->scopeConfig->getValue($configPath, ScopeInterface::SCOPE_STORE, $storeId); if (is_numeric($templateId)) { - // Template was overridden in backend, so load template from database $this->load($templateId); } else { - // Load from filesystem $this->loadDefault($templateId); } - return $this; } diff --git a/app/code/Magento/Email/Model/BackendTemplate.php b/app/code/Magento/Email/Model/BackendTemplate.php index dd5341f4fdebf..3904ef11e4eef 100644 --- a/app/code/Magento/Email/Model/BackendTemplate.php +++ b/app/code/Magento/Email/Model/BackendTemplate.php @@ -30,6 +30,7 @@ class BackendTemplate extends Template * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Email\Model\Template\Config $emailConfig * @param \Magento\Email\Model\TemplateFactory $templateFactory + * @param \Magento\Framework\Filter\FilterManager $filterManager * @param \Magento\Framework\UrlInterface $urlModel * @param \Magento\Email\Model\Template\FilterFactory $filterFactory * @param \Magento\Config\Model\Config\Structure $structure @@ -48,6 +49,7 @@ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Email\Model\Template\Config $emailConfig, \Magento\Email\Model\TemplateFactory $templateFactory, + \Magento\Framework\Filter\FilterManager $filterManager, \Magento\Framework\UrlInterface $urlModel, \Magento\Email\Model\Template\FilterFactory $filterFactory, \Magento\Config\Model\Config\Structure $structure, @@ -65,6 +67,7 @@ public function __construct( $scopeConfig, $emailConfig, $templateFactory, + $filterManager, $urlModel, $filterFactory, $data diff --git a/app/code/Magento/Email/Model/Template.php b/app/code/Magento/Email/Model/Template.php index 883e957ea5581..50788fc239ef4 100644 --- a/app/code/Magento/Email/Model/Template.php +++ b/app/code/Magento/Email/Model/Template.php @@ -134,6 +134,7 @@ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Email\Model\Template\Config $emailConfig, \Magento\Email\Model\TemplateFactory $templateFactory, + \Magento\Framework\Filter\FilterManager $filterManager, \Magento\Framework\UrlInterface $urlModel, \Magento\Email\Model\Template\FilterFactory $filterFactory, array $data = [] @@ -150,6 +151,7 @@ public function __construct( $scopeConfig, $emailConfig, $templateFactory, + $filterManager, $urlModel, $data ); diff --git a/app/code/Magento/Email/Model/Template/Filter.php b/app/code/Magento/Email/Model/Template/Filter.php index 64946825a5cb1..1b08d8ffddc00 100644 --- a/app/code/Magento/Email/Model/Template/Filter.php +++ b/app/code/Magento/Email/Model/Template/Filter.php @@ -753,6 +753,10 @@ public function customvarDirective($construction) */ public function cssDirective($construction) { + if ($this->isPlainTemplateMode()) { + return ''; + } + $params = $this->getParameters($construction[2]); $file = isset($params['file']) ? $params['file'] : null; if (!$file) { diff --git a/app/code/Magento/Newsletter/Model/Template.php b/app/code/Magento/Newsletter/Model/Template.php index 1aee8771fd6d6..701584e126b68 100644 --- a/app/code/Magento/Newsletter/Model/Template.php +++ b/app/code/Magento/Newsletter/Model/Template.php @@ -76,9 +76,10 @@ class Template extends \Magento\Email\Model\AbstractTemplate * @param \Magento\Email\Model\Template\Config $emailConfig * @param \Magento\Email\Model\TemplateFactory $templateFactory The template directive requires an email * template model, not newsletter model, as templates overridden in backend are loaded from email table. - * @param \Magento\Framework\Url $urlModel + * @param \Magento\Framework\Filter\FilterManager $filterManager + * @param \Magento\Framework\Url|\Magento\Framework\UrlInterface $urlModel * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Newsletter\Model\Template\FilterFactory $filterFactory, + * @param \Magento\Newsletter\Model\Template\FilterFactory $filterFactory , * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -93,6 +94,7 @@ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Email\Model\Template\Config $emailConfig, \Magento\Email\Model\TemplateFactory $templateFactory, + \Magento\Framework\Filter\FilterManager $filterManager, \Magento\Framework\UrlInterface $urlModel, \Magento\Framework\App\RequestInterface $request, \Magento\Newsletter\Model\Template\FilterFactory $filterFactory, @@ -109,6 +111,7 @@ public function __construct( $scopeConfig, $emailConfig, $templateFactory, + $filterManager, $urlModel, $data ); From fd9bff4afac952f933eaabc479fc2a1a8d89a102 Mon Sep 17 00:00:00 2001 From: David Alger Date: Mon, 20 Jul 2015 10:37:15 -0500 Subject: [PATCH 04/24] REL-12 HTML markup in Plain Text Templates - updated usages of the template type interface constants --- .../Controller/Adminhtml/Email/Template/Save.php | 6 ++++-- .../Magento/Email/Test/Unit/Model/TemplateTest.php | 10 ++++++---- .../Newsletter/Block/Adminhtml/Template/Grid.php | 5 +++-- .../Newsletter/Controller/Adminhtml/Template/Save.php | 9 ++++++--- .../Newsletter/Test/Unit/Model/TemplateTest.php | 9 +++++---- .../Magento/Newsletter/_files/newsletter_sample.php | 4 +++- .../Mail/Test/Unit/Template/TransportBuilderTest.php | 11 +++++++---- 7 files changed, 34 insertions(+), 20 deletions(-) diff --git a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php index 5ccf91202530c..ecb8f8c55ad57 100644 --- a/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php +++ b/app/code/Magento/Email/Controller/Adminhtml/Email/Template/Save.php @@ -6,6 +6,8 @@ */ namespace Magento\Email\Controller\Adminhtml\Email\Template; +use Magento\Framework\App\TemplateTypesInterface; + class Save extends \Magento\Email\Controller\Adminhtml\Email\Template { /** @@ -43,11 +45,11 @@ public function execute() ); if (!$template->getId()) { - $template->setTemplateType(\Magento\Email\Model\Template::TYPE_HTML); + $template->setTemplateType(TemplateTypesInterface::TYPE_HTML); } if ($request->getParam('_change_type_flag')) { - $template->setTemplateType(\Magento\Framework\App\TemplateTypesInterface::TYPE_TEXT); + $template->setTemplateType(TemplateTypesInterface::TYPE_TEXT); $template->setTemplateStyles(''); } diff --git a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php index b216d421cc77f..3386e833e1803 100644 --- a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php +++ b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php @@ -7,7 +7,9 @@ use Magento\Email\Model\Template\Filter; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\TemplateTypesInterface; use Magento\Framework\Filter\Template as FilterTemplate; +use Magento\Store\Model\ScopeInterface; /** * Covers \Magento\Email\Model\Template @@ -257,9 +259,9 @@ public function testLoadDefault( $model->loadDefault($templateId); if ($templateType === 'html') { - $this->assertEquals(\Magento\Email\Model\Template::TYPE_HTML, $model->getTemplateType()); + $this->assertEquals(TemplateTypesInterface::TYPE_HTML, $model->getTemplateType()); } else { - $this->assertEquals(\Magento\Email\Model\Template::TYPE_TEXT, $model->getTemplateType()); + $this->assertEquals(TemplateTypesInterface::TYPE_TEXT, $model->getTemplateType()); } $this->assertEquals($templateId, $model->getId()); $this->assertEquals($parsedTemplateText, $model->getTemplateText()); @@ -370,7 +372,7 @@ public function testLoadByConfigPath($loadFromDatabase, $templateContent, $expec $this->scopeConfig->expects($this->once()) ->method('getValue') - ->with($configPath, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId) + ->with($configPath, ScopeInterface::SCOPE_STORE, $storeId) ->will($this->returnValue($templateId)); $model->expects($this->once()) @@ -443,7 +445,7 @@ public function testIsValidForSend($isSMTPDisabled, $senderName, $senderEmail, $ { $this->scopeConfig->expects($this->once()) ->method('isSetFlag') - ->with('system/smtp/disable', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ->with('system/smtp/disable', ScopeInterface::SCOPE_STORE) ->will($this->returnValue($isSMTPDisabled)); $model = $this->getModelMock(['getSenderName', 'getSenderEmail', 'getTemplateSubject']); $model->expects($this->any()) diff --git a/app/code/Magento/Newsletter/Block/Adminhtml/Template/Grid.php b/app/code/Magento/Newsletter/Block/Adminhtml/Template/Grid.php index 62c785e2d724e..8ef15f06e4ce2 100644 --- a/app/code/Magento/Newsletter/Block/Adminhtml/Template/Grid.php +++ b/app/code/Magento/Newsletter/Block/Adminhtml/Template/Grid.php @@ -12,6 +12,7 @@ namespace Magento\Newsletter\Block\Adminhtml\Template; use Magento\Backend\Block\Widget\Grid as WidgetGrid; +use Magento\Framework\App\TemplateTypesInterface; class Grid extends \Magento\Backend\Block\Widget\Grid\Extended { @@ -127,8 +128,8 @@ protected function _prepareColumns() 'index' => 'template_type', 'type' => 'options', 'options' => [ - \Magento\Newsletter\Model\Template::TYPE_HTML => 'html', - \Magento\Newsletter\Model\Template::TYPE_TEXT => 'text', + TemplateTypesInterface::TYPE_HTML => 'html', + TemplateTypesInterface::TYPE_TEXT => 'text', ], 'header_css_class' => 'col-type', 'column_css_class' => 'col-type' diff --git a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Save.php b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Save.php index e70b3a8809cf3..4378ac6ba704c 100644 --- a/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Save.php +++ b/app/code/Magento/Newsletter/Controller/Adminhtml/Template/Save.php @@ -6,6 +6,9 @@ */ namespace Magento\Newsletter\Controller\Adminhtml\Template; +use Magento\Framework\App\TemplateTypesInterface; +use Magento\Framework\Exception\LocalizedException; + class Save extends \Magento\Newsletter\Controller\Adminhtml\Template { /** @@ -46,10 +49,10 @@ public function execute() ); if (!$template->getId()) { - $template->setTemplateType(\Magento\Newsletter\Model\Template::TYPE_HTML); + $template->setTemplateType(TemplateTypesInterface::TYPE_HTML); } if ($this->getRequest()->getParam('_change_type_flag')) { - $template->setTemplateType(\Magento\Newsletter\Model\Template::TYPE_TEXT); + $template->setTemplateType(TemplateTypesInterface::TYPE_TEXT); $template->setTemplateStyles(''); } if ($this->getRequest()->getParam('_save_as_flag')) { @@ -63,7 +66,7 @@ public function execute() $this->_redirect('*/template'); return; - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError(nl2br($e->getMessage())); $this->_getSession()->setData('newsletter_template_form_data', $this->getRequest()->getParams()); } catch (\Exception $e) { diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php index a7d71621c9c09..8335d3cc5d03c 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php @@ -4,6 +4,7 @@ * See COPYING.txt for license details. */ namespace Magento\Newsletter\Test\Unit\Model; +use Magento\Framework\App\TemplateTypesInterface; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -238,7 +239,7 @@ public function testGetProcessedTemplate($variables, $templateType, $storeId, $e ->will($this->returnSelf()); $filterTemplate->expects($this->once()) ->method('setPlainTemplateMode') - ->with($templateType === \Magento\Framework\App\TemplateTypesInterface::TYPE_TEXT) + ->with($templateType === TemplateTypesInterface::TYPE_TEXT) ->will($this->returnSelf()); $filterTemplate->expects($this->once()) ->method('setIsChildTemplate') @@ -292,7 +293,7 @@ public function testGetProcessedTemplate($variables, $templateType, $storeId, $e $model->expects($this->atLeastOnce()) ->method('isPlain') - ->will($this->returnValue($templateType === \Magento\Framework\App\TemplateTypesInterface::TYPE_TEXT)); + ->will($this->returnValue($templateType === TemplateTypesInterface::TYPE_TEXT)); $preparedTemplateText = $expectedResult; //'prepared text'; $model->expects($this->once()) @@ -315,7 +316,7 @@ public function getProcessedTemplateDataProvider() return [ 'default' => [ 'variables' => [], - 'templateType' => \Magento\Framework\App\TemplateTypesInterface::TYPE_TEXT, + 'templateType' => TemplateTypesInterface::TYPE_TEXT, 'storeId' => 1, 'expectedVariables' => [ 'logo_url' => null, @@ -334,7 +335,7 @@ public function getProcessedTemplateDataProvider() 'logo_url' => 'http://example.com/logo', 'logo_alt' => 'Logo Alt', ], - 'templateType' => \Magento\Framework\App\TemplateTypesInterface::TYPE_HTML, + 'templateType' => TemplateTypesInterface::TYPE_HTML, 'storeId' => 1, 'expectedVariables' => [ 'logo_url' => 'http://example.com/logo', diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/_files/newsletter_sample.php b/dev/tests/integration/testsuite/Magento/Newsletter/_files/newsletter_sample.php index 72597389d74b1..b78004d895185 100644 --- a/dev/tests/integration/testsuite/Magento/Newsletter/_files/newsletter_sample.php +++ b/dev/tests/integration/testsuite/Magento/Newsletter/_files/newsletter_sample.php @@ -3,12 +3,14 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ +use Magento\Framework\App\TemplateTypesInterface; + /** @var \Magento\Newsletter\Model\Template $template */ $template = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Newsletter\Model\Template'); $templateData = [ 'template_code' => 'some_unique_code', - 'template_type' => Magento\Newsletter\Model\Template::TYPE_TEXT, + 'template_type' => TemplateTypesInterface::TYPE_TEXT, 'subject' => 'test data2__22', 'template_sender_email' => 'sender@email.com', 'template_sender_name' => 'Test Sender Name 222', diff --git a/lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php b/lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php index 0a93ee2ca9ee2..135744a8ad83e 100644 --- a/lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php +++ b/lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php @@ -5,6 +5,9 @@ */ namespace Magento\Framework\Mail\Test\Unit\Template; +use Magento\Framework\App\TemplateTypesInterface; +use Magento\Framework\Mail\MessageInterface; + class TransportBuilderTest extends \PHPUnit_Framework_TestCase { /** @@ -160,13 +163,13 @@ public function getTransportDataProvider() { return [ [ - \Magento\Framework\App\TemplateTypesInterface::TYPE_TEXT, - \Magento\Framework\Mail\Message::TYPE_TEXT, + TemplateTypesInterface::TYPE_TEXT, + MessageInterface::TYPE_TEXT, 'Plain text', ], [ - \Magento\Framework\App\TemplateTypesInterface::TYPE_HTML, - \Magento\Framework\Mail\Message::TYPE_HTML, + TemplateTypesInterface::TYPE_HTML, + MessageInterface::TYPE_HTML, '

Html message

' ] ]; From 18484560b27619c753255abdd1fd13e1380699dd Mon Sep 17 00:00:00 2001 From: David Alger Date: Mon, 20 Jul 2015 10:55:08 -0500 Subject: [PATCH 05/24] REL-12 HTML markup in Plain Text Templates - fixed incorrect return type in method doc block --- app/code/Magento/Newsletter/Block/Adminhtml/Template/Edit.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Newsletter/Block/Adminhtml/Template/Edit.php b/app/code/Magento/Newsletter/Block/Adminhtml/Template/Edit.php index 11eafbcac0890..5159647aec99b 100644 --- a/app/code/Magento/Newsletter/Block/Adminhtml/Template/Edit.php +++ b/app/code/Magento/Newsletter/Block/Adminhtml/Template/Edit.php @@ -281,8 +281,7 @@ protected function isSingleStoreMode() /** * Getter for id of current store (the only one in single-store mode and current in multi-stores mode) * - * @return boolean - * @SuppressWarnings(PHPMD.BooleanGetMethodName) + * @return int */ protected function getStoreId() { From b6623c8600a575840e782f7b958534cf8d8a231a Mon Sep 17 00:00:00 2001 From: David Alger Date: Mon, 20 Jul 2015 10:56:45 -0500 Subject: [PATCH 06/24] REL-12 HTML markup in Plain Text Templates - fixed bug with assuming template type of html when JS hadn't performed a change --- .../Email/Block/Adminhtml/Template/Edit.php | 19 ++++++++++++++++++- .../adminhtml/templates/template/edit.phtml | 7 +++++-- .../Block/Adminhtml/Template/Edit.php | 18 +++++++++++++++++- .../adminhtml/templates/template/edit.phtml | 6 ++++-- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Email/Block/Adminhtml/Template/Edit.php b/app/code/Magento/Email/Block/Adminhtml/Template/Edit.php index d61d7dcf17f29..16584af041ee9 100644 --- a/app/code/Magento/Email/Block/Adminhtml/Template/Edit.php +++ b/app/code/Magento/Email/Block/Adminhtml/Template/Edit.php @@ -5,13 +5,17 @@ */ namespace Magento\Email\Block\Adminhtml\Template; +use Magento\Backend\Block\Widget; +use Magento\Backend\Block\Widget\ContainerInterface; +use Magento\Framework\App\TemplateTypesInterface; + /** * Adminhtml system template edit block * * @author Magento Core Team * @method array getTemplateOptions() */ -class Edit extends \Magento\Backend\Block\Widget implements \Magento\Backend\Block\Widget\ContainerInterface +class Edit extends Widget implements ContainerInterface { /** * @var \Magento\Framework\Registry @@ -336,6 +340,19 @@ public function isTextType() return $this->getEmailTemplate()->isPlain(); } + /** + * Return template type from template object or TYPE_HTML by default + * + * @return int + */ + public function getTemplateType() + { + if ($this->getEmailTemplate()->getTemplateType()) { + return $this->getEmailTemplate()->getTemplateType(); + } + return TemplateTypesInterface::TYPE_HTML; + } + /** * Return delete url for customer group * diff --git a/app/code/Magento/Email/view/adminhtml/templates/template/edit.phtml b/app/code/Magento/Email/view/adminhtml/templates/template/edit.phtml index 25944c62b9211..8ddf4a9484d72 100644 --- a/app/code/Magento/Email/view/adminhtml/templates/template/edit.phtml +++ b/app/code/Magento/Email/view/adminhtml/templates/template/edit.phtml @@ -4,8 +4,11 @@ * See COPYING.txt for license details. */ +use Magento\Framework\App\TemplateTypesInterface; + // @codingStandardsIgnoreFile +/** @var $block \Magento\Email\Block\Adminhtml\Template\Edit */ ?> getEditMode()): ?>
@@ -139,9 +142,9 @@ require([ }, preview: function() { if (this.typeChange) { - $('preview_type').value = 1; + $('preview_type').value = ; } else { - $('preview_type').value = 2; + $('preview_type').value = getTemplateType() ?>; } if (typeof tinyMCE == 'undefined' || !tinyMCE.getInstanceById('template_text')) { $('preview_text').value = $('template_text').value; diff --git a/app/code/Magento/Newsletter/Block/Adminhtml/Template/Edit.php b/app/code/Magento/Newsletter/Block/Adminhtml/Template/Edit.php index 5159647aec99b..5bae2860b7082 100644 --- a/app/code/Magento/Newsletter/Block/Adminhtml/Template/Edit.php +++ b/app/code/Magento/Newsletter/Block/Adminhtml/Template/Edit.php @@ -13,7 +13,10 @@ */ namespace Magento\Newsletter\Block\Adminhtml\Template; -class Edit extends \Magento\Backend\Block\Widget +use Magento\Backend\Block\Widget; +use Magento\Framework\App\TemplateTypesInterface; + +class Edit extends Widget { /** * Core registry @@ -248,6 +251,19 @@ public function isTextType() return $this->getModel()->isPlain(); } + /** + * Return template type from template object or TYPE_HTML by default + * + * @return int + */ + public function getTemplateType() + { + if ($this->getModel()->getTemplateType()) { + return $this->getModel()->getTemplateType(); + } + return TemplateTypesInterface::TYPE_HTML; + } + /** * Return delete url for customer group * diff --git a/app/code/Magento/Newsletter/view/adminhtml/templates/template/edit.phtml b/app/code/Magento/Newsletter/view/adminhtml/templates/template/edit.phtml index e7700bf62f855..492fb15f6c0d5 100644 --- a/app/code/Magento/Newsletter/view/adminhtml/templates/template/edit.phtml +++ b/app/code/Magento/Newsletter/view/adminhtml/templates/template/edit.phtml @@ -4,6 +4,8 @@ * See COPYING.txt for license details. */ +use Magento\Framework\App\TemplateTypesInterface; + // @codingStandardsIgnoreFile /* @var $block \Magento\Newsletter\Block\Adminhtml\Template\Edit */ @@ -151,9 +153,9 @@ require([ preview: function() { if (this.typeChange) { - $('preview_type').value = 1; + $('preview_type').value = ; } else { - $('preview_type').value = 2; + $('preview_type').value = getTemplateType() ?>; } if (this.isEditor() && tinyMCE.get(this.id)) { tinyMCE.triggerSave(); From 0c83fc9b1e2d3c3959d161d65d4184a62c0b704d Mon Sep 17 00:00:00 2001 From: David Alger Date: Mon, 20 Jul 2015 11:22:21 -0500 Subject: [PATCH 07/24] REL-12 HTML markup in Plain Text Templates - updated unit tests to inject new dependency --- .../Email/Test/Unit/Model/TemplateTest.php | 93 ++++++++++++------- 1 file changed, 58 insertions(+), 35 deletions(-) diff --git a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php index 3386e833e1803..21e237752ca98 100644 --- a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php +++ b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php @@ -6,9 +6,11 @@ namespace Magento\Email\Test\Unit\Model; use Magento\Email\Model\Template\Filter; +use Magento\Framework\App\Area; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\App\TemplateTypesInterface; use Magento\Framework\Filter\Template as FilterTemplate; +use Magento\Setup\Module\I18n\Locale; use Magento\Store\Model\ScopeInterface; /** @@ -63,6 +65,11 @@ class TemplateTest extends \PHPUnit_Framework_TestCase */ private $filterFactory; + /** + * @var \Magento\Framework\Filter\FilterManager + */ + private $filterManager; + /** * @var \Magento\Framework\Url|\PHPUnit_Framework_MockObject_MockObject */ @@ -83,36 +90,51 @@ public function setUp() $this->context = $this->getMockBuilder('Magento\Framework\Model\Context') ->disableOriginalConstructor() ->getMock(); + $this->design = $this->getMockBuilder('Magento\Framework\View\DesignInterface') ->disableOriginalConstructor() ->getMock(); + $this->registry = $this->getMockBuilder('Magento\Framework\Registry') ->disableOriginalConstructor() ->getMock(); + $this->appEmulation = $this->getMockBuilder('Magento\Store\Model\App\Emulation') ->disableOriginalConstructor() ->getMock(); + $this->storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface') ->disableOriginalConstructor() ->getMock(); + $this->assetRepo = $this->getMockBuilder('Magento\Framework\View\Asset\Repository') ->disableOriginalConstructor() ->getMock(); + $this->filesystem = $this->getMockBuilder('Magento\Framework\Filesystem') ->disableOriginalConstructor() ->getMock(); + $this->scopeConfig = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface') ->disableOriginalConstructor() ->getMock(); + $this->emailConfig = $this->getMockBuilder('Magento\Email\Model\Template\Config') ->disableOriginalConstructor() ->getMock(); + $this->templateFactory = $this->getMockBuilder('Magento\Email\Model\TemplateFactory') ->disableOriginalConstructor() ->getMock(); + + $this->filterManager = $this->getMockBuilder('Magento\Framework\Filter\FilterManager') + ->disableOriginalConstructor() + ->getMock(); + $this->urlModel = $this->getMockBuilder('Magento\Framework\Url') ->disableOriginalConstructor() ->getMock(); + $this->filterFactory = $this->getMockBuilder('Magento\Email\Model\Template\FilterFactory') ->setMethods(['create']) ->disableOriginalConstructor() @@ -122,29 +144,28 @@ public function setUp() /** * Return the model under test with additional methods mocked. * - * @param $mockedMethods array + * @param array $mockedMethods * @return \Magento\Email\Model\Template|\PHPUnit_Framework_MockObject_MockObject */ protected function getModelMock(array $mockedMethods = []) { return $this->getMockBuilder('Magento\Email\Model\Template') ->setMethods(array_merge($mockedMethods, ['__wakeup', '__sleep', '_init'])) - ->setConstructorArgs( - [ - $this->context, - $this->design, - $this->registry, - $this->appEmulation, - $this->storeManager, - $this->assetRepo, - $this->filesystem, - $this->scopeConfig, - $this->emailConfig, - $this->templateFactory, - $this->urlModel, - $this->filterFactory - ] - ) + ->setConstructorArgs([ + $this->context, + $this->design, + $this->registry, + $this->appEmulation, + $this->storeManager, + $this->assetRepo, + $this->filesystem, + $this->scopeConfig, + $this->emailConfig, + $this->templateFactory, + $this->filterManager, + $this->urlModel, + $this->filterFactory, + ]) ->getMock(); } @@ -217,9 +238,9 @@ public function testLoadDefault( ]); $designParams = [ - 'area' => \Magento\Framework\App\Area::AREA_FRONTEND, + 'area' => Area::AREA_FRONTEND, 'theme' => 'Magento/blank', - 'locale' => \Magento\Setup\Module\I18n\Locale::DEFAULT_SYSTEM_LOCALE, + 'locale' => Locale::DEFAULT_SYSTEM_LOCALE, ]; $model->expects($this->once()) @@ -253,7 +274,7 @@ public function testLoadDefault( $this->filesystem->expects($this->once()) ->method('getDirectoryRead') - ->with(\Magento\Framework\App\Filesystem\DirectoryList::ROOT) + ->with(DirectoryList::ROOT) ->will($this->returnValue($modulesDir)); $model->loadDefault($templateId); @@ -348,6 +369,7 @@ public function testLoadByConfigPath($loadFromDatabase, $templateContent, $expec ->setMethods(['getStore']) ->disableOriginalConstructor() ->getMock(); + $storeId = 'storeId'; $designConfig->expects($this->once()) ->method('getStore') @@ -725,19 +747,17 @@ public function testSetOptions() */ public function testGetType($templateType, $expectedResult) { - $emailConfig = $this->getMockBuilder( - '\Magento\Email\Model\Template\Config' - )->setMethods( - ['getTemplateType'] - )->disableOriginalConstructor()->getMock(); + $emailConfig = $this->getMockBuilder('\Magento\Email\Model\Template\Config') + ->setMethods(['getTemplateType']) + ->disableOriginalConstructor() + ->getMock(); + $emailConfig->expects($this->once())->method('getTemplateType')->will($this->returnValue($templateType)); - /** @var \Magento\Email\Model\Template $model */ - $model = $this->getMockBuilder( - 'Magento\Email\Model\Template' - )->setMethods( - ['_init'] - )->setConstructorArgs( - [ + + /** @var $model \Magento\Email\Model\Template */ + $model = $this->getMockBuilder('Magento\Email\Model\Template') + ->setMethods(['_init']) + ->setConstructorArgs([ $this->getMock('Magento\Framework\Model\Context', [], [], '', false), $this->getMock('Magento\Theme\Model\View\Design', [], [], '', false), $this->getMock('Magento\Framework\Registry', [], [], '', false), @@ -748,11 +768,14 @@ public function testGetType($templateType, $expectedResult) $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface'), $emailConfig, $this->getMock('Magento\Email\Model\TemplateFactory', [], [], '', false), + $this->getMock('Magento\Framework\Filter\FilterManager', [], [], '', false), $this->getMock('Magento\Framework\Url', [], [], '', false), $this->getMock('Magento\Email\Model\Template\FilterFactory', [], [], '', false), - ['template_id' => 10], - ] - )->getMock(); + ]) + ->getMock(); + + $model->setTemplateId(10); + $this->assertEquals($expectedResult, $model->getType()); } From 48719dbff1f80604b17dbf474a0721710b8b65b4 Mon Sep 17 00:00:00 2001 From: David Alger Date: Mon, 20 Jul 2015 11:22:50 -0500 Subject: [PATCH 08/24] REL-12 HTML markup in Plain Text Templates - updated unit test to reflect testing the current behavior of loadByConfigPath --- .../Email/Test/Unit/Model/TemplateTest.php | 33 ++----------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php index 21e237752ca98..00d659630c8d9 100644 --- a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php +++ b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php @@ -397,15 +397,6 @@ public function testLoadByConfigPath($loadFromDatabase, $templateContent, $expec ->with($configPath, ScopeInterface::SCOPE_STORE, $storeId) ->will($this->returnValue($templateId)); - $model->expects($this->once()) - ->method('getTemplateText') - ->will($this->returnValue($templateContent)); - - $model->expects($this->once()) - ->method('setTemplateText') - ->with($expectedOutput) - ->will($this->returnSelf()); - $model->loadByConfigPath($configPath); } @@ -420,29 +411,9 @@ public function loadByConfigPathDataProvider() 'Test template content', 'Test template content', ], - 'Load from database - @subject comment' => [ - true, - 'Test template content', - 'Test template content', - ], - 'Load from database - @vars comment' => [ - true, - 'Test template content', - 'Test template content', - ], - 'Load from database - @styles comment' => [ + 'Load from database' => [ true, - 'Test template content', 'Test template content', - ], - 'Load from database - copyright comment' => [ - true, - "Test template content\n", 'Test template content', ], ]; @@ -719,7 +690,7 @@ public function testProcessTemplateThrowsExceptionNonExistentTemplate() public function testGetSubject() { - $variables = [ 'key' => 'value' ]; + $variables = ['key' => 'value']; $model = $this->getModelMock(['getProcessedTemplateSubject']); $model->setVars($variables); $expectedResult = 'result'; From 7009628dd1002e3d8b88bb28a5f6f3a2deb47cf4 Mon Sep 17 00:00:00 2001 From: David Alger Date: Mon, 20 Jul 2015 11:38:13 -0500 Subject: [PATCH 09/24] REL-12 HTML markup in Plain Text Templates - test code formatting cleanup --- .../Email/Test/Unit/Model/TemplateTest.php | 2 +- .../Magento/Email/Model/TemplateTest.php | 228 ++++++++---------- 2 files changed, 107 insertions(+), 123 deletions(-) diff --git a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php index 00d659630c8d9..64c404a8b7aa2 100644 --- a/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php +++ b/app/code/Magento/Email/Test/Unit/Model/TemplateTest.php @@ -725,7 +725,7 @@ public function testGetType($templateType, $expectedResult) $emailConfig->expects($this->once())->method('getTemplateType')->will($this->returnValue($templateType)); - /** @var $model \Magento\Email\Model\Template */ + /** @var \Magento\Email\Model\Template $model */ $model = $this->getMockBuilder('Magento\Email\Model\Template') ->setMethods(['_init']) ->setConstructorArgs([ diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php b/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php index 2d784d7bbc3f7..68bf24119c2f8 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php +++ b/dev/tests/integration/testsuite/Magento/Email/Model/TemplateTest.php @@ -5,7 +5,14 @@ */ namespace Magento\Email\Model; +use Magento\Backend\App\Area\FrontNameResolver as BackendFrontNameResolver; +use Magento\Framework\App\Area; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\TemplateTypesInterface; +use Magento\Framework\View\DesignInterface; +use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\Store; +use Magento\TestFramework\Helper\Bootstrap; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -13,7 +20,7 @@ class TemplateTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\Email\Model\Template|\PHPUnit_Framework_MockObject_MockObject + * @var Template|\PHPUnit_Framework_MockObject_MockObject */ protected $model; @@ -29,12 +36,12 @@ class TemplateTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->objectManager = Bootstrap::getObjectManager(); } protected function mockModel($filesystem = null) { - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $objectManager = Bootstrap::getObjectManager(); if (!$filesystem) { $filesystem = $objectManager->create('Magento\Framework\Filesystem'); } @@ -44,12 +51,9 @@ protected function mockModel($filesystem = null) ['send', 'addTo', 'addBcc', 'setReturnPath', 'setReplyTo'], ['utf-8'] ); - $this->model = $this->getMockBuilder( - 'Magento\Email\Model\Template' - )->setMethods( - ['_getMail'] - )->setConstructorArgs( - [ + $this->model = $this->getMockBuilder('Magento\Email\Model\Template') + ->setMethods(['_getMail']) + ->setConstructorArgs([ $objectManager->get('Magento\Framework\Model\Context'), $objectManager->get('Magento\Framework\View\DesignInterface'), $objectManager->get('Magento\Framework\Registry'), @@ -62,8 +66,9 @@ protected function mockModel($filesystem = null) $objectManager->get('Magento\Email\Model\TemplateFactory'), $objectManager->get('Magento\Framework\UrlInterface'), $objectManager->get('Magento\Email\Model\Template\FilterFactory'), - ] - )->getMock(); + ]) + ->getMock(); + $objectManager->get('Magento\Framework\App\State')->setAreaCode('frontend'); $this->model->expects($this->any())->method('_getMail')->will($this->returnCallback([$this, 'getMail'])); $this->model->setSenderName('sender')->setSenderEmail('sender@example.com')->setTemplateSubject('Subject'); @@ -85,15 +90,11 @@ public function testSetGetTemplateFilter() $filter = $this->model->getTemplateFilter(); $this->assertSame($filter, $this->model->getTemplateFilter()); $this->assertEquals( - \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - 'Magento\Store\Model\StoreManagerInterface' - )->getStore()->getId(), + Bootstrap::getObjectManager()->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getId(), $filter->getStoreId() ); - $filter = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - 'Magento\Email\Model\Template\Filter' - ); + $filter = Bootstrap::getObjectManager()->create('Magento\Email\Model\Template\Filter'); $this->model->setTemplateFilter($filter); $this->assertSame($filter, $this->model->getTemplateFilter()); } @@ -115,11 +116,10 @@ public function testLoadDefault() public function testGetProcessedTemplate() { $this->mockModel(); - \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - 'Magento\Framework\App\AreaList' - )->getArea( - \Magento\Framework\App\Area::AREA_FRONTEND - )->load(); + Bootstrap::getObjectManager()->get('Magento\Framework\App\AreaList') + ->getArea(Area::AREA_FRONTEND) + ->load(); + $this->setNotDefaultThemeForFixtureStore(); $expectedViewUrl = 'static/frontend/Magento/luma/en_US/Magento_Theme/favicon.ico'; $this->model->setTemplateText('{{view url="Magento_Theme::favicon.ico"}}'); @@ -127,7 +127,7 @@ public function testGetProcessedTemplate() $this->model->setDesignConfig( [ 'area' => 'frontend', - 'store' => \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'store' => Bootstrap::getObjectManager()->get( 'Magento\Store\Model\StoreManagerInterface' )->getStore( 'fixturestore' @@ -154,9 +154,9 @@ public function testTemplateFallback($area, $templateId, $expectedOutput, $mockT { $this->mockModel(); - if ($mockThemeFallback == \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { + if ($mockThemeFallback == BackendFrontNameResolver::AREA_CODE) { $this->setUpAdminThemeFallback(); - } elseif ($mockThemeFallback == \Magento\Framework\App\Area::AREA_FRONTEND) { + } elseif ($mockThemeFallback == Area::AREA_FRONTEND) { $this->setUpThemeFallback($area); } @@ -172,38 +172,38 @@ public function templateFallbackDataProvider() { return [ 'Template from module - admin' => [ - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, + BackendFrontNameResolver::AREA_CODE, 'customer_create_account_email_template', 'To sign in to our site, use these credentials during checkout', ], 'Template from module - frontend' => [ - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, 'customer_create_account_email_template', 'To sign in to our site, use these credentials during checkout', ], 'Template from theme - frontend' => [ - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, 'customer_create_account_email_template', 'customer_create_account_email_template template from Vendor/custom_theme', - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, ], 'Template from parent theme - frontend' => [ - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, 'customer_create_account_email_confirmation_template', 'customer_create_account_email_confirmation_template template from Vendor/default', - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, ], 'Template from grandparent theme - frontend' => [ - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, 'customer_create_account_email_confirmed_template', 'customer_create_account_email_confirmed_template template from Magento/default', - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, ], 'Template from grandparent theme - adminhtml' => [ - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, + BackendFrontNameResolver::AREA_CODE, 'catalog_productalert_cron_error_email_template', 'catalog_productalert_cron_error_email_template template from Magento/default', - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, + BackendFrontNameResolver::AREA_CODE, ], ]; @@ -246,7 +246,7 @@ public function testTemplateDirective( $template = $this->objectManager->create('Magento\Email\Model\Template'); $templateData = [ 'template_code' => 'some_unique_code', - 'template_type' => \Magento\Email\Model\Template::TYPE_HTML, + 'template_type' => TemplateTypesInterface::TYPE_HTML, 'template_text' => $expectedOutput, ]; $template->setData($templateData); @@ -254,14 +254,13 @@ public function testTemplateDirective( $templateId = $template->getId(); // Store the ID of the newly created template in the system config so that this template will be loaded - $this->objectManager->get( - 'Magento\Framework\App\Config\MutableScopeConfigInterface' - )->setValue( - $storeConfigPath, - $templateId, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - 'fixturestore' - ); + $this->objectManager->get('Magento\Framework\App\Config\MutableScopeConfigInterface') + ->setValue( + $storeConfigPath, + $templateId, + ScopeInterface::SCOPE_STORE, + 'fixturestore' + ); } $this->assertContains($expectedOutput, $this->model->getProcessedTemplate()); @@ -274,44 +273,44 @@ public function templateDirectiveDataProvider() { return [ 'Template from module folder - adminhtml' => [ - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, + BackendFrontNameResolver::AREA_CODE, '{{template config_path="design/email/footer_template"}}', '', ], 'Template from module folder - frontend' => [ - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, '{{template config_path="design/email/footer_template"}}', '', ], 'Template overridden in backend - adminhtml' => [ - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, + BackendFrontNameResolver::AREA_CODE, '{{template config_path="design/email/footer_template"}}', 'Footer configured in backend - email loaded via adminhtml', 'design/email/footer_template', ], 'Template overridden in backend - frontend' => [ - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, '{{template config_path="design/email/footer_template"}}', 'Footer configured in backend - email loaded via frontend', 'design/email/footer_template', ], 'Template from theme - frontend' => [ - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, '{{template config_path="customer/create_account/email_template"}}', 'customer_create_account_email_template template from Vendor/custom_theme', ], 'Template from parent theme - frontend' => [ - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, '{{template config_path="customer/create_account/email_confirmation_template"}}', 'customer_create_account_email_confirmation_template template from Vendor/default', ], 'Template from grandparent theme - frontend' => [ - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, '{{template config_path="customer/create_account/email_confirmed_template"}}', 'customer_create_account_email_confirmed_template template from Magento/default', ], 'Template from grandparent theme - adminhtml' => [ - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, + BackendFrontNameResolver::AREA_CODE, '{{template config_path="catalog/productalert_cron/error_email_template"}}', 'catalog_productalert_cron_error_email_template template from Magento/default', null, @@ -391,7 +390,7 @@ public function templateStylesVariableDataProvider() { return [ 'Styles from comment - adminhtml' => [ - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, + BackendFrontNameResolver::AREA_CODE, 'p { color: #111; }', [ ' comment - frontend' => [ - \Magento\Framework\App\Area::AREA_FRONTEND, + Area::AREA_FRONTEND, 'p { color: #111; }', [ '', + "\n", ], 'Template from module folder - frontend' => [ Area::AREA_FRONTEND, + TemplateTypesInterface::TYPE_HTML, + '{{template config_path="design/email/footer_template"}}', + "\n", + ], + 'Template from module folder - plaintext' => [ + Area::AREA_FRONTEND, + TemplateTypesInterface::TYPE_TEXT, '{{template config_path="design/email/footer_template"}}', - '', + 'Thank you', + "\n", ], 'Template overridden in backend - adminhtml' => [ BackendFrontNameResolver::AREA_CODE, + TemplateTypesInterface::TYPE_HTML, '{{template config_path="design/email/footer_template"}}', - 'Footer configured in backend - email loaded via adminhtml', + 'Footer configured in backend - email loaded via adminhtml', + null, 'design/email/footer_template', ], 'Template overridden in backend - frontend' => [ Area::AREA_FRONTEND, + TemplateTypesInterface::TYPE_HTML, '{{template config_path="design/email/footer_template"}}', - 'Footer configured in backend - email loaded via frontend', + 'Footer configured in backend - email loaded via frontend', + null, 'design/email/footer_template', ], 'Template from theme - frontend' => [ Area::AREA_FRONTEND, + TemplateTypesInterface::TYPE_HTML, '{{template config_path="customer/create_account/email_template"}}', - 'customer_create_account_email_template template from Vendor/custom_theme', + 'customer_create_account_email_template template from Vendor/custom_theme', ], 'Template from parent theme - frontend' => [ Area::AREA_FRONTEND, + TemplateTypesInterface::TYPE_HTML, '{{template config_path="customer/create_account/email_confirmation_template"}}', - 'customer_create_account_email_confirmation_template template from Vendor/default', + 'customer_create_account_email_confirmation_template template from Vendor/default', ], 'Template from grandparent theme - frontend' => [ Area::AREA_FRONTEND, + TemplateTypesInterface::TYPE_HTML, '{{template config_path="customer/create_account/email_confirmed_template"}}', - 'customer_create_account_email_confirmed_template template from Magento/default', + 'customer_create_account_email_confirmed_template template from Magento/default', ], 'Template from grandparent theme - adminhtml' => [ BackendFrontNameResolver::AREA_CODE, + TemplateTypesInterface::TYPE_HTML, '{{template config_path="catalog/productalert_cron/error_email_template"}}', - 'catalog_productalert_cron_error_email_template template from Magento/default', + 'catalog_productalert_cron_error_email_template template from Magento/default', + null, null, true, ], From 880b817bf81afb8c5824c439a351422814a1e6ae Mon Sep 17 00:00:00 2001 From: David Alger Date: Mon, 20 Jul 2015 15:01:43 -0500 Subject: [PATCH 16/24] REL-12 HTML markup in Plain Text Templates - formatting update and removed (I believe) unnecessary exclusion from file --- app/code/Magento/Customer/Model/AccountManagement.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index 3ceb2eb9d094c..57ef90c2b1e18 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -4,8 +4,6 @@ * See COPYING.txt for license details. */ -// @codingStandardsIgnoreFile - namespace Magento\Customer\Model; use Magento\Customer\Api\AccountManagementInterface; @@ -779,7 +777,7 @@ private function validateResetPasswordToken($customerId, $resetPasswordLinkToken * @param int $customerId * @return bool * @throws \Magento\Framework\Exception\NoSuchEntityException If group is not found - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function isReadonly($customerId) { @@ -796,7 +794,7 @@ public function isReadonly($customerId) * @param string $storeId * @param string $sendemailStoreId * @return $this - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function sendNewAccountEmail( $customer, @@ -808,9 +806,7 @@ protected function sendNewAccountEmail( $types = $this->getTemplateTypes(); if (!isset($types[$type])) { - throw new \Magento\Framework\Exception\LocalizedException( - __('Please correct the transactional account email type.') - ); + throw new LocalizedException(__('Please correct the transactional account email type.')); } if (!$storeId) { From 76ab6b9568eb2df7bb5b71c957c1e123bf299414 Mon Sep 17 00:00:00 2001 From: David Alger Date: Mon, 20 Jul 2015 15:19:09 -0500 Subject: [PATCH 17/24] REL-12 HTML markup in Plain Text Templates - updated integration test files --- .../default/Magento_Email/templates/sample_email_content.phtml | 2 +- .../Magento/default/Magento_ProductAlert/email/cron_error.html | 2 +- .../default/Magento_Customer/email/account_new_confirmed.html | 2 +- .../default/Magento_Email/templates/sample_email_content.phtml | 2 +- .../Magento_Email/templates/sample_email_content_custom.phtml | 2 +- .../Vendor/custom_theme/Magento_Customer/email/account_new.html | 2 +- .../Magento_Customer/email/account_new_confirmation.html | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/adminhtml/Magento/default/Magento_Email/templates/sample_email_content.phtml b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/adminhtml/Magento/default/Magento_Email/templates/sample_email_content.phtml index f8d9adb618d48..66a2c782b3af4 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/adminhtml/Magento/default/Magento_Email/templates/sample_email_content.phtml +++ b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/adminhtml/Magento/default/Magento_Email/templates/sample_email_content.phtml @@ -4,4 +4,4 @@ * See COPYING.txt for license details. */ ?> -Email content for adminhtml/Magento/default theme +Email content for adminhtml/Magento/default theme diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/adminhtml/Magento/default/Magento_ProductAlert/email/cron_error.html b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/adminhtml/Magento/default/Magento_ProductAlert/email/cron_error.html index e07d7da3e554b..72015f111590c 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/adminhtml/Magento/default/Magento_ProductAlert/email/cron_error.html +++ b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/adminhtml/Magento/default/Magento_ProductAlert/email/cron_error.html @@ -4,4 +4,4 @@ * See COPYING.txt for license details. */ --> -catalog_productalert_cron_error_email_template template from Magento/default +catalog_productalert_cron_error_email_template template from Magento/default diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Customer/email/account_new_confirmed.html b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Customer/email/account_new_confirmed.html index 97b285165da64..ec9f7f63bc388 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Customer/email/account_new_confirmed.html +++ b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Customer/email/account_new_confirmed.html @@ -4,4 +4,4 @@ * See COPYING.txt for license details. */ --> -customer_create_account_email_confirmed_template template from Magento/default +customer_create_account_email_confirmed_template template from Magento/default diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Email/templates/sample_email_content.phtml b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Email/templates/sample_email_content.phtml index 00c79baba6c4e..76a0294d75387 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Email/templates/sample_email_content.phtml +++ b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Email/templates/sample_email_content.phtml @@ -4,4 +4,4 @@ * See COPYING.txt for license details. */ ?> -Email content for frontend/Magento/default theme +Email content for frontend/Magento/default theme diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Email/templates/sample_email_content_custom.phtml b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Email/templates/sample_email_content_custom.phtml index a76b8a8be9473..d4670520cc116 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Email/templates/sample_email_content_custom.phtml +++ b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Magento/default/Magento_Email/templates/sample_email_content_custom.phtml @@ -4,4 +4,4 @@ * See COPYING.txt for license details. */ ?> -Custom Email content for frontend/Magento/default theme +Custom Email content for frontend/Magento/default theme diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Vendor/custom_theme/Magento_Customer/email/account_new.html b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Vendor/custom_theme/Magento_Customer/email/account_new.html index 3605eca37ece7..80b786019a01a 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Vendor/custom_theme/Magento_Customer/email/account_new.html +++ b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Vendor/custom_theme/Magento_Customer/email/account_new.html @@ -4,4 +4,4 @@ * See COPYING.txt for license details. */ --> -customer_create_account_email_template template from Vendor/custom_theme +customer_create_account_email_template template from Vendor/custom_theme diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Vendor/default/Magento_Customer/email/account_new_confirmation.html b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Vendor/default/Magento_Customer/email/account_new_confirmation.html index 4c2b9e00a9466..8eae5b437af78 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Vendor/default/Magento_Customer/email/account_new_confirmation.html +++ b/dev/tests/integration/testsuite/Magento/Email/Model/_files/design/frontend/Vendor/default/Magento_Customer/email/account_new_confirmation.html @@ -4,4 +4,4 @@ * See COPYING.txt for license details. */ --> -customer_create_account_email_confirmation_template template from Vendor/default \ No newline at end of file +customer_create_account_email_confirmation_template template from Vendor/default From 7a212daebfa5c6846540b032c336c6aade641420 Mon Sep 17 00:00:00 2001 From: David Alger Date: Mon, 20 Jul 2015 16:01:06 -0500 Subject: [PATCH 18/24] REL-12 HTML markup in Plain Text Templates - fixed failing layout test --- .../testsuite/Magento/Email/Model/Template/FilterTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php b/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php index 85b25df272779..fb81778ea48fd 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php +++ b/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php @@ -145,22 +145,22 @@ public function layoutDirectiveDataProvider() 'area parameter - omitted' => [ 'adminhtml', 'handle="email_template_test_handle"', - 'Email content for frontend/Magento/default theme', + 'Email content for frontend/Magento/default theme', ], 'area parameter - frontend' => [ 'adminhtml', 'handle="email_template_test_handle" area="frontend"', - 'Email content for frontend/Magento/default theme', + 'Email content for frontend/Magento/default theme', ], 'area parameter - backend' => [ 'frontend', 'handle="email_template_test_handle" area="adminhtml"', - 'Email content for adminhtml/Magento/default theme', + 'Email content for adminhtml/Magento/default theme', ], 'custom parameter' => [ 'frontend', 'handle="email_template_test_handle" template="Magento_Email::sample_email_content_custom.phtml"', - 'Custom Email content for frontend/Magento/default theme', + 'Custom Email content for frontend/Magento/default theme', ], ]; return $result; From 1c46af652d2942e262895e77ee0d2793cd5d65ef Mon Sep 17 00:00:00 2001 From: David Alger Date: Mon, 20 Jul 2015 16:39:24 -0500 Subject: [PATCH 19/24] REL-12 HTML markup in Plain Text Templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - typo fix… --- .../testsuite/Magento/Email/Model/Template/FilterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php b/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php index fb81778ea48fd..eb48ce66ac0e1 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php +++ b/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php @@ -160,7 +160,7 @@ public function layoutDirectiveDataProvider() 'custom parameter' => [ 'frontend', 'handle="email_template_test_handle" template="Magento_Email::sample_email_content_custom.phtml"', - 'Custom Email content for frontend/Magento/default theme', + 'Custom Email content for frontend/Magento/default theme', ], ]; return $result; From 749e3968e58c394c737eb34c1e87d97a0666c511 Mon Sep 17 00:00:00 2001 From: David Alger Date: Wed, 29 Jul 2015 13:58:19 -0500 Subject: [PATCH 20/24] REL-12 HTML markup in Plain Text Templates - code QA fixes --- .../Customer/Model/AccountManagement.php | 28 +++++-------------- .../Magento/Email/Model/AbstractTemplate.php | 5 ++-- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index 57ef90c2b1e18..8292b15d558f6 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -675,12 +675,9 @@ protected function createPasswordHash($password) */ public function validate(CustomerInterface $customer) { - $customerErrors = $this->validator->validateData( - $this->extensibleDataObjectConverter - ->toFlatArray($customer, [], '\Magento\Customer\Api\Data\CustomerInterface'), - [], - 'customer' - ); + $customerData = $this->extensibleDataObjectConverter + ->toFlatArray($customer, [], '\Magento\Customer\Api\Data\CustomerInterface'); + $customerErrors = $this->validator->validateData($customerData, [], 'customer'); $validationResults = $this->validationResultsDataFactory->create(); if ($customerErrors !== true) { @@ -843,25 +840,14 @@ protected function sendPasswordResetNotificationEmail($customer) $customerEmailData = $this->getFullCustomerObject($customer); - $templateId = $this->scopeConfig->getValue( + $this->sendEmailTemplate( + $customer, self::XML_PATH_RESET_PASSWORD_TEMPLATE, - ScopeInterface::SCOPE_STORE, + self::XML_PATH_FORGOT_EMAIL_IDENTITY, + ['customer' => $customerEmailData, 'store' => $this->storeManager->getStore($storeId)], $storeId ); - $transport = $this->transportBuilder->setTemplateIdentifier($templateId) - ->setTemplateOptions(['area' => Area::AREA_FRONTEND, 'store' => $storeId]) - ->setTemplateVars(['customer' => $customerEmailData, 'store' => $this->storeManager->getStore($storeId)]) - ->setFrom($this->scopeConfig->getValue( - self::XML_PATH_FORGOT_EMAIL_IDENTITY, - ScopeInterface::SCOPE_STORE, - $storeId - )) - ->addTo($customer->getEmail(), $this->customerViewHelper->getCustomerName($customer)) - ->getTransport(); - - $transport->sendMessage(); - return $this; } diff --git a/app/code/Magento/Email/Model/AbstractTemplate.php b/app/code/Magento/Email/Model/AbstractTemplate.php index f24b9785c638b..f82555cabd718 100644 --- a/app/code/Magento/Email/Model/AbstractTemplate.php +++ b/app/code/Magento/Email/Model/AbstractTemplate.php @@ -171,7 +171,7 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn * @param \Magento\Email\Model\Template\Config $emailConfig * @param \Magento\Email\Model\TemplateFactory $templateFactory * @param \Magento\Framework\Filter\FilterManager $filterManager - * @param \Magento\Framework\Url|\Magento\Framework\UrlInterface $urlModel + * @param \Magento\Framework\UrlInterface $urlModel * @param array $data * * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -248,8 +248,7 @@ protected function getTemplateInstance() } /** - * Load template by XML configuration path. Loads template from database if it exists and has been overridden in - * configuration. Otherwise loads from the filesystem. + * Load template from database when overridden in configuration or load default from relevant file system location. * * @param string $configPath * @return \Magento\Email\Model\AbstractTemplate From 2a44026a7d853fc7acecedf0fe00551f5738f345 Mon Sep 17 00:00:00 2001 From: David Alger Date: Wed, 29 Jul 2015 14:34:46 -0500 Subject: [PATCH 21/24] REL-12 HTML markup in Plain Text Templates - resolving bamboo static tests --- .../Customer/Model/AccountManagement.php | 20 +++++++------------ .../Email/Block/Adminhtml/Template/Edit.php | 8 ++------ app/code/Magento/Email/Model/Template.php | 10 ++++------ .../Test/Unit/Model/TemplateTest.php | 1 + .../Email/Model/Template/FilterTest.php | 3 +++ 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/app/code/Magento/Customer/Model/AccountManagement.php b/app/code/Magento/Customer/Model/AccountManagement.php index 8292b15d558f6..0c85daa583d81 100644 --- a/app/code/Magento/Customer/Model/AccountManagement.php +++ b/app/code/Magento/Customer/Model/AccountManagement.php @@ -393,7 +393,7 @@ public function validateResetPasswordLinkToken($customerId, $resetPasswordLinkTo */ public function initiatePasswordReset($email, $template, $websiteId = null) { - if (is_null($websiteId)) { + if ($websiteId === null) { $websiteId = $this->storeManager->getStore()->getWebsiteId(); } // load customer by email @@ -463,12 +463,9 @@ public function getConfirmationStatus($customerId) /** * {@inheritdoc} */ - public function createAccount( - CustomerInterface $customer, - $password = null, - $redirectUrl = '' - ) { - if (!is_null($password)) { + public function createAccount(CustomerInterface $customer, $password = null, $redirectUrl = '') + { + if ($password !== null) { $this->checkPasswordStrength($password); } else { $password = $this->mathRandom->getRandomString(self::MIN_PASSWORD_LENGTH); @@ -482,11 +479,8 @@ public function createAccount( * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ - public function createAccountWithPasswordHash( - CustomerInterface $customer, - $hash, - $redirectUrl = '' - ) { + public function createAccountWithPasswordHash(CustomerInterface $customer, $hash, $redirectUrl = '') + { // This logic allows an existing customer to be added to a different store. No new account is created. // The plan is to move this logic into a new method called something like 'registerAccountWithStore' if ($customer->getId()) { @@ -706,7 +700,7 @@ public function validate(CustomerInterface $customer) public function isEmailAvailable($customerEmail, $websiteId = null) { try { - if (is_null($websiteId)) { + if ($websiteId === null) { $websiteId = $this->storeManager->getStore()->getWebsiteId(); } $this->customerRepository->get($customerEmail, $websiteId); diff --git a/app/code/Magento/Email/Block/Adminhtml/Template/Edit.php b/app/code/Magento/Email/Block/Adminhtml/Template/Edit.php index 16584af041ee9..0bd51528ea2e5 100644 --- a/app/code/Magento/Email/Block/Adminhtml/Template/Edit.php +++ b/app/code/Magento/Email/Block/Adminhtml/Template/Edit.php @@ -7,7 +7,6 @@ use Magento\Backend\Block\Widget; use Magento\Backend\Block\Widget\ContainerInterface; -use Magento\Framework\App\TemplateTypesInterface; /** * Adminhtml system template edit block @@ -341,16 +340,13 @@ public function isTextType() } /** - * Return template type from template object or TYPE_HTML by default + * Return template type from template object * * @return int */ public function getTemplateType() { - if ($this->getEmailTemplate()->getTemplateType()) { - return $this->getEmailTemplate()->getTemplateType(); - } - return TemplateTypesInterface::TYPE_HTML; + return $this->getEmailTemplate()->getType(); } /** diff --git a/app/code/Magento/Email/Model/Template.php b/app/code/Magento/Email/Model/Template.php index 50788fc239ef4..4a2c7b8238c50 100644 --- a/app/code/Magento/Email/Model/Template.php +++ b/app/code/Magento/Email/Model/Template.php @@ -195,16 +195,14 @@ public function setId($value) */ public function isValidForSend() { - return !$this->scopeConfig->isSetFlag( - \Magento\Email\Model\Template::XML_PATH_SYSTEM_SMTP_DISABLE, - ScopeInterface::SCOPE_STORE - ) && $this->getSenderName() && $this->getSenderEmail() && $this->getTemplateSubject(); + return !$this->scopeConfig->isSetFlag(Template::XML_PATH_SYSTEM_SMTP_DISABLE, ScopeInterface::SCOPE_STORE) + && $this->getSenderName() && $this->getSenderEmail() && $this->getTemplateSubject(); } /** * Getter for template type * - * @return int|string + * @return int */ public function getType() { @@ -213,7 +211,7 @@ public function getType() $templateType = $this->emailConfig->getTemplateType($this->getId()); $templateType = $templateType == 'html' ? self::TYPE_HTML : self::TYPE_TEXT; } - return $templateType; + return $templateType !== null ? $templateType : self::TYPE_HTML; } /** diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php index ea03527652c0c..de668564ea9b5 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php @@ -3,6 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Newsletter\Test\Unit\Model; use Magento\Framework\App\TemplateTypesInterface; diff --git a/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php b/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php index eb48ce66ac0e1..7a12e9ec12be3 100644 --- a/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php +++ b/dev/tests/integration/testsuite/Magento/Email/Model/Template/FilterTest.php @@ -16,6 +16,9 @@ use Magento\Setup\Module\I18n\Locale; use Magento\Store\Model\ScopeInterface; +/** + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class FilterTest extends \PHPUnit_Framework_TestCase { /** From 7673708e8ebab6dfe5360dd189119fcaa9c6b61b Mon Sep 17 00:00:00 2001 From: David Alger Date: Thu, 30 Jul 2015 10:29:22 -0500 Subject: [PATCH 22/24] REL-12 HTML markup in Plain Text Templates - resolving bamboo static tests --- app/code/Magento/Email/Model/Template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Email/Model/Template.php b/app/code/Magento/Email/Model/Template.php index 4a2c7b8238c50..2529c724732c2 100644 --- a/app/code/Magento/Email/Model/Template.php +++ b/app/code/Magento/Email/Model/Template.php @@ -119,7 +119,7 @@ class Template extends AbstractTemplate implements \Magento\Framework\Mail\Templ * @param \Magento\Email\Model\TemplateFactory $templateFactory * @param \Magento\Framework\UrlInterface $urlModel * @param \Magento\Email\Model\Template\FilterFactory $filterFactory - * @param array $data + * @param array $data optional generic object data * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ From 1a8d7ea58b610df18732a685577c034a980cce08 Mon Sep 17 00:00:00 2001 From: David Alger Date: Wed, 5 Aug 2015 09:34:37 -0500 Subject: [PATCH 23/24] REL-12 HTML markup in Plain Text Templates - resolved static test issue --- app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php index de668564ea9b5..d4a6f5d68a171 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/TemplateTest.php @@ -5,6 +5,7 @@ */ namespace Magento\Newsletter\Test\Unit\Model; + use Magento\Framework\App\TemplateTypesInterface; /** From dee47981ffe3e28f6ae787db33e2acc0d2b85d4c Mon Sep 17 00:00:00 2001 From: Alexander Paliarush Date: Thu, 6 Aug 2015 11:49:15 +0300 Subject: [PATCH 24/24] MAGETWO-40818: Review and accept Transactional Email Template PR --- app/code/Magento/Email/Model/Template.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Email/Model/Template.php b/app/code/Magento/Email/Model/Template.php index 2529c724732c2..4d1b0fff43aef 100644 --- a/app/code/Magento/Email/Model/Template.php +++ b/app/code/Magento/Email/Model/Template.php @@ -105,21 +105,22 @@ class Template extends AbstractTemplate implements \Magento\Framework\Mail\Templ private $filterFactory; /** - * Initialize dependencies + * Initialize dependencies. * * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\View\DesignInterface $design * @param \Magento\Framework\Registry $registry * @param \Magento\Store\Model\App\Emulation $appEmulation - * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param StoreManagerInterface $storeManager * @param \Magento\Framework\View\Asset\Repository $assetRepo * @param \Magento\Framework\Filesystem $filesystem * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param Template\Config $emailConfig - * @param \Magento\Email\Model\TemplateFactory $templateFactory + * @param TemplateFactory $templateFactory + * @param \Magento\Framework\Filter\FilterManager $filterManager * @param \Magento\Framework\UrlInterface $urlModel - * @param \Magento\Email\Model\Template\FilterFactory $filterFactory - * @param array $data optional generic object data + * @param Template\FilterFactory $filterFactory + * @param array $data * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */