123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- 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)
- */
- class TemplateTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var Template|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $model;
- /**
- * @var \Zend_Mail|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $mail;
- /**
- * @var \Magento\Framework\ObjectManagerInterface
- */
- protected $objectManager;
- protected function setUp()
- {
- $this->objectManager = Bootstrap::getObjectManager();
- }
- protected function mockModel($filesystem = null)
- {
- if (!$filesystem) {
- $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
- }
- $this->mail = $this->getMockBuilder(\Zend_Mail::class)
- ->setMethods(['send', 'addTo', 'addBcc', 'setReturnPath', 'setReplyTo'])
- ->setConstructorArgs(['utf-8'])
- ->getMock();
- $this->model = $this->getMockBuilder(\Magento\Email\Model\Template::class)
- ->setMethods(['_getMail'])
- ->setConstructorArgs([
- $this->objectManager->get(\Magento\Framework\Model\Context::class),
- $this->objectManager->get(\Magento\Framework\View\DesignInterface::class),
- $this->objectManager->get(\Magento\Framework\Registry::class),
- $this->objectManager->get(\Magento\Store\Model\App\Emulation::class),
- $this->objectManager->get(\Magento\Store\Model\StoreManager::class),
- $this->objectManager->create(\Magento\Framework\View\Asset\Repository::class),
- $filesystem,
- $this->objectManager->create(\Magento\Framework\App\Config\ScopeConfigInterface::class),
- $this->objectManager->get(\Magento\Email\Model\Template\Config::class),
- $this->objectManager->get(\Magento\Email\Model\TemplateFactory::class),
- $this->objectManager->get(\Magento\Framework\Filter\FilterManager::class),
- $this->objectManager->get(\Magento\Framework\UrlInterface::class),
- $this->objectManager->get(\Magento\Email\Model\Template\FilterFactory::class),
- ])
- ->getMock();
- $this->objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
- $this->model->expects($this->any())->method('_getMail')->will($this->returnCallback([$this, 'getMail']));
- $this->model->setSenderName('sender')->setSenderEmail('sender@example.com')->setTemplateSubject('Subject');
- }
- /**
- * Return a disposable \Zend_Mail instance
- *
- * @return \PHPUnit_Framework_MockObject_MockObject|\Zend_Mail
- */
- public function getMail()
- {
- return clone $this->mail;
- }
- public function testSetGetTemplateFilter()
- {
- $this->mockModel();
- $filter = $this->model->getTemplateFilter();
- $this->assertSame($filter, $this->model->getTemplateFilter());
- $this->assertEquals(
- $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->getStore()->getId(),
- $filter->getStoreId()
- );
- $filter = $this->objectManager->create(\Magento\Email\Model\Template\Filter::class);
- $this->model->setTemplateFilter($filter);
- $this->assertSame($filter, $this->model->getTemplateFilter());
- }
- public function testLoadDefault()
- {
- $this->mockModel();
- $this->model->loadDefault('customer_create_account_email_template');
- $this->assertNotEmpty($this->model->getTemplateText());
- $this->assertNotEmpty($this->model->getTemplateSubject());
- $this->assertNotEmpty($this->model->getOrigTemplateVariables());
- $this->assertInternalType('array', json_decode($this->model->getOrigTemplateVariables(), true));
- }
- /**
- * @magentoAppIsolation enabled
- * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
- */
- public function testGetProcessedTemplate()
- {
- $this->mockModel();
- $this->objectManager->get(\Magento\Framework\App\AreaList::class)
- ->getArea(Area::AREA_FRONTEND)
- ->load();
- $expectedViewUrl = '/frontend/Magento/blank/en_US/Magento_Theme/favicon.ico';
- $this->model->setDesignConfig([
- 'area' => 'frontend',
- 'store' => $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
- ->getStore('fixturestore')
- ->getId(),
- ]);
- $this->model->setTemplateText('{{view url="Magento_Theme::favicon.ico"}}');
- $this->setNotDefaultThemeForFixtureStore();
- $this->assertStringEndsNotWith($expectedViewUrl, $this->model->getProcessedTemplate());
- $this->setDefaultThemeForFixtureStore();
- $this->assertStringEndsWith($expectedViewUrl, $this->model->getProcessedTemplate());
- }
- /**
- * Test template directive to ensure that templates can be loaded from modules
- *
- * @param string $area
- * @param string $templateId
- * @param string $expectedOutput
- * @param bool $mockThemeFallback
- *
- * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
- * @magentoComponentsDir Magento/Email/Model/_files/design
- * @magentoAppIsolation enabled
- * @magentoDbIsolation enabled
- * @dataProvider templateFallbackDataProvider
- */
- public function testTemplateFallback($area, $templateId, $expectedOutput, $mockThemeFallback = false)
- {
- $this->mockModel();
- if ($mockThemeFallback == BackendFrontNameResolver::AREA_CODE) {
- $this->setUpAdminThemeFallback();
- } elseif ($mockThemeFallback == Area::AREA_FRONTEND) {
- $this->setUpThemeFallback($area);
- }
- $this->model->setId($templateId);
- $this->assertContains($expectedOutput, $this->model->processTemplate());
- }
- /**
- * @return array
- */
- public function templateFallbackDataProvider()
- {
- return [
- 'Template from module - admin' => [
- BackendFrontNameResolver::AREA_CODE,
- 'customer_create_account_email_template',
- 'To sign in to our site, use these credentials during checkout',
- ],
- 'Template from module - frontend' => [
- Area::AREA_FRONTEND,
- 'customer_create_account_email_template',
- 'To sign in to our site, use these credentials during checkout',
- ],
- 'Template from theme - frontend' => [
- Area::AREA_FRONTEND,
- 'customer_create_account_email_template',
- 'customer_create_account_email_template template from Vendor/custom_theme',
- Area::AREA_FRONTEND,
- ],
- 'Template from parent theme - frontend' => [
- Area::AREA_FRONTEND,
- 'customer_create_account_email_confirmation_template',
- 'customer_create_account_email_confirmation_template template from Vendor/default',
- Area::AREA_FRONTEND,
- ],
- 'Template from grandparent theme - frontend' => [
- Area::AREA_FRONTEND,
- 'customer_create_account_email_confirmed_template',
- 'customer_create_account_email_confirmed_template template from Magento/default',
- Area::AREA_FRONTEND,
- ],
- 'Template from grandparent theme - adminhtml' => [
- BackendFrontNameResolver::AREA_CODE,
- 'catalog_productalert_cron_error_email_template',
- 'catalog_productalert_cron_error_email_template template from Magento/default',
- BackendFrontNameResolver::AREA_CODE,
- ],
- ];
- }
- /**
- * Test template directive to ensure that templates can be loaded from modules, overridden in backend, and
- * overridden in themes
- *
- * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
- * @magentoComponentsDir Magento/Email/Model/_files/design
- * @magentoAppIsolation enabled
- * @magentoDbIsolation enabled
- * @dataProvider templateDirectiveDataProvider
- *
- * @param string $area
- * @param int $templateType
- * @param string $templateText
- * @param string $assertContains
- * @param string $assertNotContains
- * @param string $storeConfigPath
- * @param bool $mockAdminTheme
- */
- public function testTemplateDirective(
- $area,
- $templateType,
- $templateText,
- $assertContains,
- $assertNotContains = null,
- $storeConfigPath = null,
- $mockAdminTheme = false
- ) {
- $this->mockModel();
- if ($mockAdminTheme) {
- $this->setUpAdminThemeFallback();
- } else {
- $this->setUpThemeFallback($area);
- }
- $this->model->setTemplateType($templateType);
- $this->model->setTemplateText($templateText);
- // Allows for testing of templates overridden in backend
- if ($storeConfigPath) {
- $template = $this->objectManager->create(\Magento\Email\Model\Template::class);
- $templateData = [
- 'template_code' => 'some_unique_code',
- 'template_type' => $templateType,
- 'template_text' => $assertContains,
- ];
- $template->setData($templateData);
- $template->save();
- // 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::class)
- ->setValue($storeConfigPath, $template->getId(), ScopeInterface::SCOPE_STORE, 'fixturestore');
- }
- $this->assertContains($assertContains, $this->model->getProcessedTemplate());
- if ($assertNotContains) {
- $this->assertNotContains($assertNotContains, $this->model->getProcessedTemplate());
- }
- }
- /**
- * @return array
- */
- public function templateDirectiveDataProvider()
- {
- return [
- 'Template from module folder - adminhtml' => [
- BackendFrontNameResolver::AREA_CODE,
- TemplateTypesInterface::TYPE_HTML,
- '{{template config_path="design/email/footer_template"}}',
- "</table>\n<!-- End wrapper table -->",
- ],
- 'Template from module folder - frontend' => [
- Area::AREA_FRONTEND,
- TemplateTypesInterface::TYPE_HTML,
- '{{template config_path="design/email/footer_template"}}',
- "</table>\n<!-- End wrapper table -->",
- ],
- 'Template from module folder - plaintext' => [
- Area::AREA_FRONTEND,
- TemplateTypesInterface::TYPE_TEXT,
- '{{template config_path="design/email/footer_template"}}',
- 'Thank you',
- "</table>\n<!-- End wrapper table -->",
- ],
- 'Template overridden in backend - adminhtml' => [
- BackendFrontNameResolver::AREA_CODE,
- TemplateTypesInterface::TYPE_HTML,
- '{{template config_path="design/email/footer_template"}}',
- '<b>Footer configured in backend - email loaded via adminhtml</b>',
- null,
- 'design/email/footer_template',
- ],
- 'Template overridden in backend - frontend' => [
- Area::AREA_FRONTEND,
- TemplateTypesInterface::TYPE_HTML,
- '{{template config_path="design/email/footer_template"}}',
- '<b>Footer configured in backend - email loaded via frontend</b>',
- null,
- 'design/email/footer_template',
- ],
- 'Template from theme - frontend' => [
- Area::AREA_FRONTEND,
- TemplateTypesInterface::TYPE_HTML,
- '{{template config_path="customer/create_account/email_template"}}',
- '<strong>customer_create_account_email_template template from Vendor/custom_theme</strong>',
- ],
- 'Template from parent theme - frontend' => [
- Area::AREA_FRONTEND,
- TemplateTypesInterface::TYPE_HTML,
- '{{template config_path="customer/create_account/email_confirmation_template"}}',
- '<strong>customer_create_account_email_confirmation_template template from Vendor/default</strong',
- ],
- 'Template from grandparent theme - frontend' => [
- Area::AREA_FRONTEND,
- TemplateTypesInterface::TYPE_HTML,
- '{{template config_path="customer/create_account/email_confirmed_template"}}',
- '<strong>customer_create_account_email_confirmed_template template from Magento/default</strong',
- ],
- 'Template from grandparent theme - adminhtml' => [
- BackendFrontNameResolver::AREA_CODE,
- TemplateTypesInterface::TYPE_HTML,
- '{{template config_path="catalog/productalert_cron/error_email_template"}}',
- '<strong>catalog_productalert_cron_error_email_template template from Magento/default</strong',
- null,
- null,
- true,
- ],
- ];
- }
- /**
- * Ensure that the template_styles variable contains styles from either <!--@styles @--> or the "Template Styles"
- * textarea in backend, depending on whether template was loaded from filesystem or DB.
- *
- * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
- * @magentoComponentsDir Magento/Email/Model/_files/design
- * @magentoAppIsolation enabled
- * @magentoDbIsolation enabled
- * @dataProvider templateStylesVariableDataProvider
- *
- * @param string $area
- * @param string $expectedOutput
- * @param array $unexpectedOutputs
- * @param array $templateForDatabase
- */
- public function testTemplateStylesVariable($area, $expectedOutput, $unexpectedOutputs, $templateForDatabase = [])
- {
- if (count($templateForDatabase)) {
- $this->mockModel();
- $this->setUpThemeFallback($area);
- $template = $this->objectManager->create(\Magento\Email\Model\Template::class);
- $template->setData($templateForDatabase);
- $template->save();
- $templateId = $template->getId();
- $this->model->load($templateId);
- } else {
- // <!--@styles @--> parsing only via the loadDefault method. Since email template files won't contain
- // @styles comments by default, it is necessary to mock an object to return testable contents
- $themeDirectory = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\ReadInterface::class)
- ->disableOriginalConstructor()
- ->setMethods([
- 'readFile',
- ])
- ->getMockForAbstractClass();
- $themeDirectory->expects($this->once())
- ->method('readFile')
- ->will($this->returnValue('<!--@styles p { color: #111; } @--> {{var template_styles}}'));
- $filesystem = $this->getMockBuilder(\Magento\Framework\Filesystem::class)
- ->disableOriginalConstructor()
- ->setMethods(['getDirectoryRead'])
- ->getMock();
- $filesystem->expects($this->once())
- ->method('getDirectoryRead')
- ->with(DirectoryList::ROOT)
- ->will($this->returnValue($themeDirectory));
- $this->mockModel($filesystem);
- $this->model->loadDefault('design_email_header_template');
- }
- $processedTemplate = $this->model->getProcessedTemplate();
- foreach ($unexpectedOutputs as $unexpectedOutput) {
- $this->assertNotContains($unexpectedOutput, $processedTemplate);
- }
- $this->assertContains($expectedOutput, $processedTemplate);
- }
- /**
- * @return array
- */
- public function templateStylesVariableDataProvider()
- {
- return [
- 'Styles from <!--@styles @--> comment - adminhtml' => [
- BackendFrontNameResolver::AREA_CODE,
- 'p { color: #111; }',
- [
- '<!--@styles',
- '{{var template_styles}}',
- ],
- ],
- 'Styles from <!--@styles @--> comment - frontend' => [
- Area::AREA_FRONTEND,
- 'p { color: #111; }',
- [
- '<!--@styles',
- '{{var template_styles}}',
- ],
- ],
- 'Styles from "Template Styles" textarea from backend - adminhtml' => [
- BackendFrontNameResolver::AREA_CODE,
- 'p { color: #222; }',
- ['{{var template_styles}}'],
- [
- 'template_code' => 'some_unique_code',
- 'template_type' => Template::TYPE_HTML,
- 'template_text' => 'Footer from database {{var template_styles}}',
- 'template_styles' => 'p { color: #222; }',
- ],
- ],
- 'Styles from "Template Styles" textarea from backend - frontend' => [
- Area::AREA_FRONTEND,
- 'p { color: #333; }',
- ['{{var template_styles}}'],
- [
- 'template_code' => 'some_unique_code',
- 'template_type' => Template::TYPE_HTML,
- 'template_text' => 'Footer from database {{var template_styles}}',
- 'template_styles' => 'p { color: #333; }',
- ],
- ],
- ];
- }
- /**
- * Setup the theme fallback structure and set the Vendor_EmailTest/custom_theme as the current theme for
- * 'fixturestore' store
- */
- protected function setUpAdminThemeFallback()
- {
- $themes = [BackendFrontNameResolver::AREA_CODE => 'Vendor_EmailTest/custom_theme'];
- $design = $this->objectManager->create(\Magento\Theme\Model\View\Design::class, ['themes' => $themes]);
- $this->objectManager->addSharedInstance($design, \Magento\Theme\Model\View\Design::class);
- /** @var \Magento\Theme\Model\Theme\Registration $registration */
- $registration = $this->objectManager->get(
- \Magento\Theme\Model\Theme\Registration::class
- );
- $registration->register();
- // The Vendor_EmailTest/custom_theme adminhtml theme is set in the
- // dev/tests/integration/testsuite/Magento/Email/Model/_files/design/themes.php file, as it must be set
- // before the adminhtml area is loaded below.
- Bootstrap::getInstance()->loadArea(BackendFrontNameResolver::AREA_CODE);
- /** @var \Magento\Store\Model\Store $adminStore */
- $adminStore = $this->objectManager->create(\Magento\Store\Model\Store::class)
- ->load(Store::ADMIN_CODE);
- $this->model->setDesignConfig([
- 'area' => 'adminhtml',
- 'store' => $adminStore->getId(),
- ]);
- }
- /**
- * Setup the theme fallback structure and set the Vendor_EmailTest/custom_theme as the current theme
- * for 'fixturestore' store
- *
- * @param $area
- */
- protected function setUpThemeFallback($area)
- {
- /** @var \Magento\Theme\Model\Theme\Registration $registration */
- $registration = $this->objectManager->get(
- \Magento\Theme\Model\Theme\Registration::class
- );
- $registration->register();
- // It is important to test from both areas, as emails will get sent from both, so we need to ensure that the
- // inline CSS files get loaded properly from both areas.
- Bootstrap::getInstance()->loadArea($area);
- $collection = $this->objectManager->create(\Magento\Theme\Model\ResourceModel\Theme\Collection::class);
- // Hard-coding theme as we want to test the fallback structure to ensure that the parent/grandparent themes of
- // Vendor_EmailTest/custom_theme will be checked for CSS files
- $themeId = $collection->getThemeByFullPath('frontend/Vendor_EmailTest/custom_theme')->getId();
- $this->objectManager->get(\Magento\Framework\App\Config\MutableScopeConfigInterface::class)
- ->setValue(
- DesignInterface::XML_PATH_THEME_ID,
- $themeId,
- ScopeInterface::SCOPE_STORE,
- 'fixturestore'
- );
- $this->model->setDesignConfig([
- 'area' => 'frontend',
- 'store' => $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
- ->getStore('fixturestore')
- ->getId(),
- ]);
- }
- /**
- * Set 'Magento/luma' for the 'fixturestore' store.
- * Application isolation is required, if a test uses this method.
- */
- protected function setNotDefaultThemeForFixtureStore()
- {
- /** @var \Magento\Framework\View\Design\ThemeInterface $theme */
- $theme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
- \Magento\Framework\View\Design\ThemeInterface::class
- );
- $theme->load('Magento/luma', 'theme_path');
- \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
- \Magento\Framework\App\Config\MutableScopeConfigInterface::class
- )->setValue(
- \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID,
- $theme->getId(),
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- 'fixturestore'
- );
- }
- /**
- * Set 'Magento/blank' for the 'fixturestore' store.
- * Application isolation is required, if a test uses this method.
- */
- protected function setDefaultThemeForFixtureStore()
- {
- /** @var \Magento\Framework\View\Design\ThemeInterface $theme */
- $theme = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
- \Magento\Framework\View\Design\ThemeInterface::class
- );
- $theme->load('Magento/blank', 'theme_path');
- \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
- \Magento\Framework\App\Config\MutableScopeConfigInterface::class
- )->setValue(
- \Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID,
- $theme->getId(),
- \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
- 'fixturestore'
- );
- }
- /**
- * @magentoAppIsolation enabled
- * @magentoDataFixture Magento/Store/_files/core_fixturestore.php
- */
- public function testGetProcessedTemplateSubject()
- {
- $this->mockModel();
- $this->objectManager->get(\Magento\Framework\App\AreaList::class)
- ->getArea(Area::AREA_FRONTEND)
- ->load();
- $this->model->setTemplateSubject('{{view url="Magento_Theme::favicon.ico"}}');
- $this->model->setDesignConfig([
- 'area' => 'frontend',
- 'store' => $this->objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
- ->getStore('fixturestore')
- ->getId(),
- ]);
- $this->setNotDefaultThemeForFixtureStore();
- $this->assertStringMatchesFormat(
- '%s/frontend/Magento/luma/en_US/Magento_Theme/favicon.ico',
- $this->model->getProcessedTemplateSubject([])
- );
- $this->setDefaultThemeForFixtureStore();
- $this->assertStringMatchesFormat(
- '%s/frontend/Magento/blank/en_US/Magento_Theme/favicon.ico',
- $this->model->getProcessedTemplateSubject([])
- );
- }
- /**
- * @magentoAppIsolation enabled
- */
- public function testGetDefaultEmailLogo()
- {
- $this->mockModel();
- $this->objectManager->get(\Magento\Framework\App\AreaList::class)
- ->getArea(Area::AREA_FRONTEND)
- ->load();
- $this->assertStringEndsWith(
- '/frontend/Magento/luma/en_US/Magento_Email/logo_email.png',
- $this->model->getDefaultEmailLogo()
- );
- }
- /**
- * @param $config
- * @dataProvider setDesignConfigExceptionDataProvider
- * @expectedException \Magento\Framework\Exception\LocalizedException
- */
- public function testSetDesignConfigException($config)
- {
- $this->mockModel();
- $model = $this->objectManager->create(\Magento\Email\Model\Template::class);
- $model->setDesignConfig($config);
- }
- public function setDesignConfigExceptionDataProvider()
- {
- $storeId = Bootstrap::getObjectManager()->get(\Magento\Store\Model\StoreManagerInterface::class)
- ->getStore()
- ->getId();
- return [
- [[]],
- [['area' => 'frontend']],
- [['store' => $storeId]],
- ];
- }
- public function testSetAndGetId()
- {
- $this->mockModel();
- $testId = 9999;
- $this->model->setId($testId);
- $this->assertEquals($testId, $this->model->getId());
- }
- public function testIsValidForSend()
- {
- $this->mockModel();
- $this->assertTrue($this->model->isValidForSend());
- }
- /**
- * @expectedException \UnexpectedValueException
- * @expectedExceptionMessage Email template 'foo' is not defined.
- */
- public function testGetTypeNonExistentType()
- {
- $this->mockModel();
- $this->model->setId('foo');
- $this->model->getType();
- }
- public function testGetTypeHtml()
- {
- $this->mockModel();
- $this->model->setId('customer_create_account_email_template');
- $this->assertEquals(TemplateTypesInterface::TYPE_HTML, $this->model->getType());
- }
- public function testGetType()
- {
- $this->mockModel();
- $templateTypeId = 'test_template';
- $this->model->setTemplateType($templateTypeId);
- $this->assertEquals($templateTypeId, $this->model->getType());
- }
- public function testGetSendingException()
- {
- $this->mockModel();
- $this->assertNull($this->model->getSendingException());
- }
- public function testGetVariablesOptionArray()
- {
- $this->mockModel();
- $testTemplateVariables = '{"var data.name":"Sender Name","var data.email":"Sender Email"}';
- $this->model->setOrigTemplateVariables($testTemplateVariables);
- $variablesOptionArray = $this->model->getVariablesOptionArray();
- $this->assertEquals('{{var data.name}}', $variablesOptionArray[0]['value']);
- $this->assertEquals('Sender Name', $variablesOptionArray[0]['label']->getArguments()[0]);
- $this->assertEquals('{{var data.email}}', $variablesOptionArray[1]['value']);
- $this->assertEquals('Sender Email', $variablesOptionArray[1]['label']->getArguments()[0]);
- }
- public function testGetVariablesOptionArrayInGroup()
- {
- $this->mockModel();
- $testTemplateVariables = '{"var data.name":"Sender Name","var data.email":"Sender Email"}';
- $this->model->setOrigTemplateVariables($testTemplateVariables);
- $variablesOptionArray = $this->model->getVariablesOptionArray(true);
- $this->assertEquals('Template Variables', $variablesOptionArray['label']->getText());
- $this->assertEquals($this->model->getVariablesOptionArray(), $variablesOptionArray['value']);
- }
- /**
- * @expectedException \Magento\Framework\Exception\MailException
- * @expectedExceptionMessage Please enter a template name.
- */
- public function testBeforeSaveEmptyTemplateCode()
- {
- $this->mockModel();
- $this->model->beforeSave();
- }
- public function testBeforeSave()
- {
- $this->mockModel();
- $this->model->setTemplateCode('test template code');
- $this->model->beforeSave();
- }
- public function testProcessTemplate()
- {
- $this->mockModel();
- $this->model->setId('customer_create_account_email_template');
- $this->assertContains('<body', $this->model->processTemplate());
- }
- public function testGetSubject()
- {
- $this->mockModel();
- $this->model->setVars(['foo', 'bar', 'baz']);
- $this->assertEquals('Subject', $this->model->getSubject());
- }
- public function testSetOptions()
- {
- $this->mockModel();
- $options = ['area' => 'test area', 'store' => 1];
- $this->model->setOptions($options);
- $this->assertEquals($options, $this->model->getDesignConfig()->getData());
- }
- }
|