25 private $appEmulation;
30 private $storeManager;
55 private $filterFactory;
65 private $templateFactory;
69 $this->design = $this->getMockBuilder(\
Magento\Framework\View\DesignInterface::class)
70 ->disableOriginalConstructor()
72 $this->registry = $this->getMockBuilder(\
Magento\Framework\Registry::class)
73 ->disableOriginalConstructor()
75 $this->appEmulation = $this->getMockBuilder(\
Magento\Store\Model\
App\Emulation::class)
76 ->disableOriginalConstructor()
78 $this->storeManager = $this->getMockBuilder(\
Magento\Store\Model\StoreManagerInterface::class)
79 ->disableOriginalConstructor()
82 $this->store = $this->getMockBuilder(\
Magento\Store\Model\Store::class)
83 ->setMethods([
'getFrontendName',
'getId'])
84 ->disableOriginalConstructor()
86 $this->store->expects($this->any())
87 ->method(
'getFrontendName')
88 ->will($this->returnValue(
'frontendName'));
89 $this->store->expects($this->any())
90 ->method(
'getFrontendName')
91 ->will($this->returnValue(
'storeId'));
92 $this->storeManager->expects($this->any())
94 ->will($this->returnValue($this->store));
96 $this->filesystem = $this->getMockBuilder(\
Magento\Framework\Filesystem::class)
97 ->disableOriginalConstructor()
99 $this->assetRepo = $this->getMockBuilder(\
Magento\Framework\View\Asset\Repository::class)
100 ->disableOriginalConstructor()
102 $this->scopeConfig = $this->getMockBuilder(\
Magento\Framework\
App\Config\ScopeConfigInterface::class)
103 ->disableOriginalConstructor()
105 $this->emailConfig = $this->getMockBuilder(\
Magento\Email\Model\Template\Config::class)
106 ->disableOriginalConstructor()
108 $this->filterFactory = $this->getMockBuilder(\
Magento\Email\Model\Template\FilterFactory::class)
109 ->setMethods([
'create'])
110 ->disableOriginalConstructor()
112 $this->templateFactory = $this->getMockBuilder(\
Magento\Email\Model\TemplateFactory::class)
113 ->disableOriginalConstructor()
126 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
127 return $this->getMockForAbstractClass(
128 \
Magento\Email\Model\AbstractTemplate::class,
129 $helper->getConstructArguments(
130 \
Magento\Email\Model\AbstractTemplate::class,
132 'design' => $this->design,
133 'appEmulation' => $this->appEmulation,
134 'storeManager' => $this->storeManager,
135 'filesystem' => $this->filesystem,
136 'assetRepo' => $this->assetRepo,
137 'scopeConfig' => $this->scopeConfig,
138 'emailConfig' => $this->emailConfig,
139 'filterFactory' => $this->filterFactory,
140 'templateFactory' => $this->templateFactory,
148 array_merge($mockedMethods, [
'__wakeup',
'__sleep',
'_init'])
162 $filterTemplate = $this->getMockBuilder(\
Magento\Email\Model\Template\Filter::class)
164 'setUseSessionInUrl',
165 'setPlainTemplateMode',
166 'setIsChildTemplate',
174 ->disableOriginalConstructor()
177 $filterTemplate->expects($this->once())
178 ->method(
'setUseSessionInUrl')
180 ->will($this->returnSelf());
181 $filterTemplate->expects($this->once())
182 ->method(
'setPlainTemplateMode')
184 ->will($this->returnSelf());
185 $filterTemplate->expects($this->once())
186 ->method(
'setIsChildTemplate')
187 ->will($this->returnSelf());
188 $filterTemplate->expects($this->once())
189 ->method(
'setDesignParams')
190 ->will($this->returnSelf());
191 $filterTemplate->expects($this->any())
192 ->method(
'setStoreId')
193 ->will($this->returnSelf());
194 $filterTemplate->expects($this->any())
195 ->method(
'getStoreId')
196 ->will($this->returnValue(
$storeId));
198 $expectedVariables[
'store'] = $this->store;
206 $filterTemplate->expects($this->any())
207 ->method(
'setVariables')
208 ->with(array_merge([
'this' =>
$model], $expectedVariables));
209 $model->setTemplateFilter($filterTemplate);
214 'theme' =>
'themeId',
215 'locale' =>
'localeId',
217 $model->expects($this->any())
218 ->method(
'getDesignParams')
219 ->will($this->returnValue($designParams));
221 $model->expects($this->atLeastOnce())
225 $preparedTemplateText = $expectedResult;
226 $model->expects($this->once())
227 ->method(
'getTemplateText')
228 ->will($this->returnValue($preparedTemplateText));
230 $filterTemplate->expects($this->once())
232 ->with($preparedTemplateText)
233 ->will($this->returnValue($expectedResult));
235 $this->assertEquals($expectedResult,
$model->getProcessedTemplate($variables));
243 $filterTemplate = $this->getMockBuilder(\
Magento\Email\Model\Template\Filter::class)
245 'setUseSessionInUrl',
246 'setPlainTemplateMode',
247 'setIsChildTemplate',
255 ->disableOriginalConstructor()
257 $filterTemplate->expects($this->once())
258 ->method(
'setUseSessionInUrl')
259 ->will($this->returnSelf());
260 $filterTemplate->expects($this->once())
261 ->method(
'setPlainTemplateMode')
262 ->will($this->returnSelf());
263 $filterTemplate->expects($this->once())
264 ->method(
'setIsChildTemplate')
265 ->will($this->returnSelf());
266 $filterTemplate->expects($this->once())
267 ->method(
'setDesignParams')
268 ->will($this->returnSelf());
269 $filterTemplate->expects($this->any())
270 ->method(
'setStoreId')
271 ->will($this->returnSelf());
272 $filterTemplate->expects($this->any())
273 ->method(
'getStoreId')
274 ->will($this->returnValue(1));
285 'theme' =>
'themeId',
286 'locale' =>
'localeId',
288 $model->expects($this->any())
289 ->method(
'getDesignParams')
290 ->will($this->returnValue($designParams));
291 $model->setTemplateFilter($filterTemplate);
294 $filterTemplate->expects($this->once())
296 ->will($this->throwException(
new \Exception));
297 $model->getProcessedTemplate([]);
310 'expectedVariables' => [
312 'logo_alt' =>
'frontendName',
314 'logo_width' =>
null,
315 'logo_height' =>
null,
316 'store_phone' =>
null,
317 'store_hours' =>
null,
318 'store_email' =>
null,
320 'expectedResult' =>
'expected result',
322 'logo variables set' => [
324 'logo_url' =>
'http://example.com/logo',
325 'logo_alt' =>
'Logo Alt',
329 'expectedVariables' => [
330 'logo_url' =>
'http://example.com/logo',
331 'logo_alt' =>
'Logo Alt',
333 'logo_width' =>
null,
334 'logo_height' =>
null,
335 'store_phone' =>
null,
336 'store_hours' =>
null,
337 'store_email' =>
null,
338 'template_styles' =>
null,
340 'expectedResult' =>
'expected result',
348 $value =
'urlWithParamsValue';
351 'theme' =>
'themeId',
352 'locale' =>
'localeId',
354 $model->expects($this->once())
355 ->method(
'getDesignParams')
356 ->will($this->returnValue($designParams));
357 $this->assetRepo->method(
'getUrlWithParams')
358 ->with(\
Magento\Email\Model\AbstractTemplate::DEFAULT_LOGO_FILE_ID, $designParams)
359 ->will($this->returnValue(
$value));
360 $this->assertEquals(
$value,
$model->getDefaultEmailLogo());
375 $config = [
'area' =>
'some_area',
'store' => 1];
378 $this->assertEquals(
$config,
$model->getDesignConfig()->getData());
386 return [[[]], [[
'area' =>
'some_area']], [[
'store' =>
'any_store']]];
392 $originalConfig = [
'area' =>
'some_area',
'store' => 1];
393 $model->setDesignConfig($originalConfig);
396 [
'in' => [
'area' =>
'frontend',
'store' =>
null],
'out' => $originalConfig],
397 [
'in' => [
'area' =>
'frontend',
'store' =>
false],
'out' => $originalConfig],
398 [
'in' => [
'area' =>
'frontend',
'store' => 0],
'out' => [
'area' =>
'frontend',
'store' => 0]],
399 [
'in' => [
'area' =>
'frontend',
'store' => 1],
'out' => [
'area' =>
'frontend',
'store' => 1]],
400 [
'in' => [
'area' =>
'frontend',
'store' => 2],
'out' => [
'area' =>
'frontend',
'store' => 2]],
402 foreach ($expectedConfigs as $set) {
403 $model->emulateDesign($set[
'in'][
'store'], $set[
'in'][
'area']);
405 $this->assertEquals($set[
'out'],
$model->getDesignConfig()->getData());
409 $this->assertEquals($originalConfig,
$model->getDesignConfig()->getData());
415 $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
417 $designMock = $this->createMock(\
Magento\Framework\View\DesignInterface::class);
418 $designMock->expects($this->any())->method(
'getArea')->willReturn(
'test_area');
420 $storeMock = $this->createMock(\
Magento\Store\Model\Store::class);
421 $storeMock->expects($this->any())->method(
'getId')->willReturn(2);
422 $storeManagerMock = $this->createMock(\
Magento\Store\Model\StoreManagerInterface::class);
423 $storeManagerMock->expects($this->any())->method(
'getStore')->willReturn($storeMock);
425 $model = $this->getMockForAbstractClass(
426 \
Magento\Email\Model\AbstractTemplate::class,
427 $helper->getConstructArguments(
428 \
Magento\Email\Model\AbstractTemplate::class,
430 'design' => $designMock,
431 'storeManager' => $storeManagerMock
436 $expectedConfig = [
'area' =>
'test_area',
'store' => 2];
437 $this->assertEquals($expectedConfig,
$model->getDesignConfig()->getData());
448 $this->emailConfig->expects($this->once())
449 ->method(
'getTemplateArea')
463 $this->emailConfig->expects($this->never())
464 ->method(
'getTemplateArea');
invalidInputParametersDataProvider()
testGetProcessedTemplateException()
getProcessedTemplateProvider()
testSetDesignConfigWithValidInputParametersReturnsSuccess()
testSetDesignConfigWithInvalidInputParametersThrowsException($config)
testGetProcessedTemplate($variables, $templateType, $storeId, $expectedVariables, $expectedResult)
testEmulateDesignAndRevertDesign()
testGetDefaultEmailLogo()
getModelMock(array $mockedMethods=[], array $data=[])
testSetForcedAreaWhenAreaIsNotSet()
testSetForcedAreaWhenAreaIsSet()