Skip to content

Commit 6e3f2a9

Browse files
author
Erik Hansen
committed
MAGETWO-37672: Responsive Email Foundation
- Removed Object Manager injection as it was no longer needed - Added consistency to properties being private/protected (DI-injected objects are protected, everything else is private) - Updated obsolete methods in static test file
1 parent 9bc1d1c commit 6e3f2a9

File tree

9 files changed

+50
-93
lines changed

9 files changed

+50
-93
lines changed

app/code/Magento/Email/Model/AbstractTemplate.php

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
5757
*
5858
* @var \Magento\Framework\Object
5959
*/
60-
protected $_designConfig;
60+
private $designConfig;
6161

6262
/**
6363
* Whether template is child of another template
@@ -78,21 +78,21 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
7878
*
7979
* @var \Magento\Framework\Object|boolean
8080
*/
81-
protected $_emulatedDesignConfig = false;
81+
private $emulatedDesignConfig = false;
8282

8383
/**
8484
* Package area
8585
*
8686
* @var string
8787
*/
88-
protected $_area;
88+
private $area;
8989

9090
/**
9191
* Store id
9292
*
9393
* @var int
9494
*/
95-
protected $_store;
95+
private $store;
9696

9797
/**
9898
* Tracks whether design has been applied within the context of this template model. Important as there are multiple
@@ -105,50 +105,43 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
105105
/**
106106
* @var \Magento\Email\Model\TemplateFactory
107107
*/
108-
private $templateFactory = null;
108+
protected $templateFactory = null;
109109

110110
/**
111111
* Design package instance
112112
*
113113
* @var \Magento\Framework\View\DesignInterface
114114
*/
115-
protected $_design = null;
115+
protected $design = null;
116116

117117
/**
118118
* @var \Magento\Store\Model\App\Emulation
119119
*/
120-
protected $_appEmulation;
120+
protected $appEmulation;
121121

122122
/**
123123
* @var \Magento\Store\Model\StoreManagerInterface
124124
*/
125-
private $storeManager;
125+
protected $storeManager;
126126

127127
/**
128128
* Asset service
129129
*
130130
* @var \Magento\Framework\View\Asset\Repository
131131
*/
132-
private $assetRepo;
132+
protected $assetRepo;
133133

134134
/**
135135
* @var \Magento\Framework\Filesystem
136136
*/
137-
private $filesystem;
137+
protected $filesystem;
138138

139139
/**
140140
* Scope config
141141
*
142142
* @var \Magento\Framework\App\Config\ScopeConfigInterface
143143
*/
144-
protected $_scopeConfig;
145-
146-
/**
147-
* Object manager
148-
*
149-
* @var \Magento\Framework\ObjectManagerInterface
150-
*/
151-
private $objectManager;
144+
protected $scopeConfig;
152145

153146
/**
154147
* @var \Magento\Email\Model\Template\Config
@@ -164,8 +157,6 @@ abstract class AbstractTemplate extends AbstractModel implements TemplateTypesIn
164157
* @param \Magento\Framework\View\Asset\Repository $assetRepo
165158
* @param \Magento\Framework\Filesystem $filesystem
166159
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
167-
* @param \Magento\Framework\ObjectManagerInterface $objectManager
168-
* @param \Magento\Framework\ObjectManagerInterface $objectManager
169160
* @param Template\Config $emailConfig
170161
* @param \Magento\Email\Model\TemplateFactory $templateFactory
171162
* @param array $data
@@ -181,20 +172,18 @@ public function __construct(
181172
\Magento\Framework\View\Asset\Repository $assetRepo,
182173
\Magento\Framework\Filesystem $filesystem,
183174
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
184-
\Magento\Framework\ObjectManagerInterface $objectManager,
185175
Template\Config $emailConfig,
186176
TemplateFactory $templateFactory,
187177
array $data = []
188178
) {
189-
$this->_design = $design;
190-
$this->_area = isset($data['area']) ? $data['area'] : null;
191-
$this->_store = isset($data['store']) ? $data['store'] : null;
192-
$this->_appEmulation = $appEmulation;
179+
$this->design = $design;
180+
$this->area = isset($data['area']) ? $data['area'] : null;
181+
$this->store = isset($data['store']) ? $data['store'] : null;
182+
$this->appEmulation = $appEmulation;
193183
$this->storeManager = $storeManager;
194184
$this->assetRepo = $assetRepo;
195185
$this->filesystem = $filesystem;
196-
$this->_scopeConfig = $scopeConfig;
197-
$this->objectManager = $objectManager;
186+
$this->scopeConfig = $scopeConfig;
198187
$this->emailConfig = $emailConfig;
199188
$this->templateFactory = $templateFactory;
200189
parent::__construct($context, $registry, null, null, $data);
@@ -244,7 +233,7 @@ protected function getTemplateInstance()
244233
*/
245234
public function loadByConfigPath($configPath)
246235
{
247-
$templateId = $this->_scopeConfig->getValue(
236+
$templateId = $this->scopeConfig->getValue(
248237
$configPath,
249238
ScopeInterface::SCOPE_STORE,
250239
$this->getDesignConfig()->getStore()
@@ -393,7 +382,7 @@ public function getDefaultEmailLogo()
393382
protected function getLogoUrl($store)
394383
{
395384
$store = $this->storeManager->getStore($store);
396-
$fileName = $this->_scopeConfig->getValue(
385+
$fileName = $this->scopeConfig->getValue(
397386
self::XML_PATH_DESIGN_EMAIL_LOGO,
398387
ScopeInterface::SCOPE_STORE,
399388
$store
@@ -419,7 +408,7 @@ protected function getLogoUrl($store)
419408
protected function getLogoAlt($store)
420409
{
421410
$store = $this->storeManager->getStore($store);
422-
$alt = $this->_scopeConfig->getValue(
411+
$alt = $this->scopeConfig->getValue(
423412
self::XML_PATH_DESIGN_EMAIL_LOGO_ALT,
424413
ScopeInterface::SCOPE_STORE,
425414
$store
@@ -453,35 +442,35 @@ protected function addEmailVariables($variables, $storeId)
453442
$variables['logo_alt'] = $this->getLogoAlt($storeId);
454443
}
455444
if (!isset($variables['logo_width'])) {
456-
$variables['logo_width'] = $this->_scopeConfig->getValue(
445+
$variables['logo_width'] = $this->scopeConfig->getValue(
457446
self::XML_PATH_DESIGN_EMAIL_LOGO_WIDTH,
458447
ScopeInterface::SCOPE_STORE,
459448
$store
460449
);
461450
}
462451
if (!isset($variables['logo_height'])) {
463-
$variables['logo_height'] = $this->_scopeConfig->getValue(
452+
$variables['logo_height'] = $this->scopeConfig->getValue(
464453
self::XML_PATH_DESIGN_EMAIL_LOGO_HEIGHT,
465454
ScopeInterface::SCOPE_STORE,
466455
$store
467456
);
468457
}
469458
if (!isset($variables['store_phone'])) {
470-
$variables['store_phone'] = $this->_scopeConfig->getValue(
459+
$variables['store_phone'] = $this->scopeConfig->getValue(
471460
\Magento\Store\Model\Store::XML_PATH_STORE_STORE_PHONE,
472461
ScopeInterface::SCOPE_STORE,
473462
$store
474463
);
475464
}
476465
if (!isset($variables['store_hours'])) {
477-
$variables['store_hours'] = $this->_scopeConfig->getValue(
466+
$variables['store_hours'] = $this->scopeConfig->getValue(
478467
\Magento\Store\Model\Store::XML_PATH_STORE_STORE_HOURS,
479468
ScopeInterface::SCOPE_STORE,
480469
$store
481470
);
482471
}
483472
if (!isset($variables['store_email'])) {
484-
$variables['store_email'] = $this->_scopeConfig->getValue(
473+
$variables['store_email'] = $this->scopeConfig->getValue(
485474
'trans_email/ident_support/email',
486475
ScopeInterface::SCOPE_STORE,
487476
$store
@@ -514,7 +503,7 @@ protected function applyDesignConfig()
514503
if ($storeId !== null) {
515504
// Force emulation in case email is being sent from same store so that theme will be loaded. Helpful
516505
// for situations where emails may be sent from bootstrap files that load frontend store, but not theme
517-
$this->_appEmulation->startEnvironmentEmulation($storeId, $area, true);
506+
$this->appEmulation->startEnvironmentEmulation($storeId, $area, true);
518507
}
519508
return true;
520509
}
@@ -526,7 +515,7 @@ protected function applyDesignConfig()
526515
*/
527516
protected function cancelDesignConfig()
528517
{
529-
$this->_appEmulation->stopEnvironmentEmulation();
518+
$this->appEmulation->stopEnvironmentEmulation();
530519
$this->hasDesignBeenApplied = false;
531520
return $this;
532521
}
@@ -542,9 +531,9 @@ public function getDesignParams()
542531
// Retrieve area from getDesignConfig, rather than the getDesignTheme->getArea(), as the latter doesn't
543532
// return the emulated area
544533
'area' => $this->getDesignConfig()->getArea(),
545-
'theme' => $this->_design->getDesignTheme()->getCode(),
546-
'themeModel' => $this->_design->getDesignTheme(),
547-
'locale' => $this->_design->getLocale(),
534+
'theme' => $this->design->getDesignTheme()->getCode(),
535+
'themeModel' => $this->design->getDesignTheme(),
536+
'locale' => $this->design->getLocale(),
548537
];
549538
}
550539

@@ -555,18 +544,18 @@ public function getDesignParams()
555544
*/
556545
public function getDesignConfig()
557546
{
558-
if ($this->_designConfig === null) {
559-
if ($this->_area === null) {
560-
$this->_area = $this->_design->getArea();
547+
if ($this->designConfig === null) {
548+
if ($this->area === null) {
549+
$this->area = $this->design->getArea();
561550
}
562-
if ($this->_store === null) {
563-
$this->_store = $this->storeManager->getStore()->getId();
551+
if ($this->store === null) {
552+
$this->store = $this->storeManager->getStore()->getId();
564553
}
565-
$this->_designConfig = new \Magento\Framework\Object(
566-
['area' => $this->_area, 'store' => $this->_store]
554+
$this->designConfig = new \Magento\Framework\Object(
555+
['area' => $this->area, 'store' => $this->store]
567556
);
568557
}
569-
return $this->_designConfig;
558+
return $this->designConfig;
570559
}
571560

572561
/**
@@ -649,7 +638,7 @@ public function emulateDesign($storeId, $area = self::DEFAULT_DESIGN_AREA)
649638
{
650639
if ($storeId) {
651640
// save current design settings
652-
$this->_emulatedDesignConfig = clone $this->getDesignConfig();
641+
$this->emulatedDesignConfig = clone $this->getDesignConfig();
653642
if (
654643
$this->getDesignConfig()->getStore() != $storeId
655644
|| $this->getDesignConfig()->getArea() != $area
@@ -658,7 +647,7 @@ public function emulateDesign($storeId, $area = self::DEFAULT_DESIGN_AREA)
658647
$this->applyDesignConfig();
659648
}
660649
} else {
661-
$this->_emulatedDesignConfig = false;
650+
$this->emulatedDesignConfig = false;
662651
}
663652
}
664653

@@ -669,10 +658,10 @@ public function emulateDesign($storeId, $area = self::DEFAULT_DESIGN_AREA)
669658
*/
670659
public function revertDesign()
671660
{
672-
if ($this->_emulatedDesignConfig) {
673-
$this->setDesignConfig($this->_emulatedDesignConfig->getData());
661+
if ($this->emulatedDesignConfig) {
662+
$this->setDesignConfig($this->emulatedDesignConfig->getData());
674663
$this->cancelDesignConfig();
675-
$this->_emulatedDesignConfig = false;
664+
$this->emulatedDesignConfig = false;
676665
}
677666
}
678667

app/code/Magento/Email/Model/BackendTemplate.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class BackendTemplate extends Template
2828
* @param \Magento\Framework\View\Asset\Repository $assetRepo
2929
* @param \Magento\Framework\Filesystem $filesystem
3030
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
31-
* @param \Magento\Framework\ObjectManagerInterface $objectManager
3231
* @param \Magento\Email\Model\Template\Config $emailConfig
3332
* @param \Magento\Email\Model\TemplateFactory $templateFactory
3433
* @param \Magento\Email\Model\Template\FilterFactory $filterFactory
@@ -46,7 +45,6 @@ public function __construct(
4645
\Magento\Framework\View\Asset\Repository $assetRepo,
4746
\Magento\Framework\Filesystem $filesystem,
4847
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
49-
\Magento\Framework\ObjectManagerInterface $objectManager,
5048
\Magento\Email\Model\Template\Config $emailConfig,
5149
\Magento\Email\Model\TemplateFactory $templateFactory,
5250
\Magento\Email\Model\Template\FilterFactory $filterFactory,
@@ -63,7 +61,6 @@ public function __construct(
6361
$assetRepo,
6462
$filesystem,
6563
$scopeConfig,
66-
$objectManager,
6764
$emailConfig,
6865
$templateFactory,
6966
$filterFactory,
@@ -83,7 +80,7 @@ public function getSystemConfigPathsWhereUsedAsDefault()
8380
return [];
8481
}
8582

86-
$configData = $this->_scopeConfig->getValue(null, ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
83+
$configData = $this->scopeConfig->getValue(null, ScopeConfigInterface::SCOPE_TYPE_DEFAULT);
8784
$paths = $this->_findEmailTemplateUsages($templateCode, $configData, '');
8885
return $paths;
8986
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class Template extends AbstractTemplate implements \Magento\Framework\Mail\Templ
115115
* @param \Magento\Framework\View\Asset\Repository $assetRepo
116116
* @param \Magento\Framework\Filesystem $filesystem
117117
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
118-
* @param \Magento\Framework\ObjectManagerInterface $objectManager
119118
* @param Template\Config $emailConfig
120119
* @param \Magento\Email\Model\TemplateFactory $templateFactory
121120
* @param \Magento\Email\Model\Template\FilterFactory $filterFactory
@@ -132,7 +131,6 @@ public function __construct(
132131
\Magento\Framework\View\Asset\Repository $assetRepo,
133132
\Magento\Framework\Filesystem $filesystem,
134133
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
135-
\Magento\Framework\ObjectManagerInterface $objectManager,
136134
\Magento\Email\Model\Template\Config $emailConfig,
137135
\Magento\Email\Model\TemplateFactory $templateFactory,
138136
\Magento\Email\Model\Template\FilterFactory $filterFactory,
@@ -148,7 +146,6 @@ public function __construct(
148146
$assetRepo,
149147
$filesystem,
150148
$scopeConfig,
151-
$objectManager,
152149
$emailConfig,
153150
$templateFactory,
154151
$data
@@ -193,7 +190,7 @@ public function setId($value)
193190
*/
194191
public function isValidForSend()
195192
{
196-
return !$this->_scopeConfig->isSetFlag(
193+
return !$this->scopeConfig->isSetFlag(
197194
\Magento\Email\Model\Template::XML_PATH_SYSTEM_SMTP_DISABLE,
198195
ScopeInterface::SCOPE_STORE
199196
) && $this->getSenderName() && $this->getSenderEmail() && $this->getTemplateSubject();

app/code/Magento/Email/Test/Unit/Model/AbstractTemplateTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ class AbstractTemplateTest extends \PHPUnit_Framework_TestCase
6161
*/
6262
private $scopeConfig;
6363

64-
/**
65-
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
66-
*/
67-
private $objectManager;
68-
6964
/**
7065
* @var \Magento\Email\Model\Template\FilterFactory|\PHPUnit_Framework_MockObject_MockObject
7166
*/
@@ -122,9 +117,6 @@ public function setUp()
122117
$this->scopeConfig = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')
123118
->disableOriginalConstructor()
124119
->getMock();
125-
$this->objectManager = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
126-
->disableOriginalConstructor()
127-
->getMock();
128120
$this->emailConfig = $this->getMockBuilder('Magento\Email\Model\Template\Config')
129121
->disableOriginalConstructor()
130122
->getMock();
@@ -159,7 +151,6 @@ protected function getModelMock(array $mockedMethods = [])
159151
'filesystem' => $this->filesystem,
160152
'assetRepo' => $this->assetRepo,
161153
'scopeConfig' => $this->scopeConfig,
162-
'objectManager' => $this->objectManager,
163154
'emailConfig' => $this->emailConfig,
164155
'filterFactory' => $this->filterFactory,
165156
'templateFactory' => $this->templateFactory

0 commit comments

Comments
 (0)