Skip to content

Commit 2c1ddd8

Browse files
Merge branch 'ACQE-4503' into integration-tests-mainline
2 parents 74c5bc7 + c1b42cc commit 2c1ddd8

File tree

3 files changed

+204
-1
lines changed

3 files changed

+204
-1
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\Email\Model\Template;
11+
12+
use Magento\Email\Model\ResourceModel\Template\Collection as TemplateCollection;
13+
use Magento\Framework\App\Config\MutableScopeConfigInterface;
14+
use Magento\Framework\App\Config\ScopeConfigInterface;
15+
use Magento\Framework\Exception\NotFoundException;
16+
use Magento\Framework\ObjectManagerInterface;
17+
use Magento\Store\Model\ScopeInterface;
18+
use Magento\Framework\Phrase;
19+
use Magento\TestFramework\Helper\Bootstrap;
20+
use Magento\TestFramework\Mail\Template\TransportBuilderMock;
21+
use Magento\TestFramework\Bootstrap as TestFrameworkBootstrap;
22+
23+
/**
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25+
*/
26+
class NewAccountEmailTemplateTest extends \PHPUnit\Framework\TestCase
27+
{
28+
29+
/**
30+
* @var ObjectManagerInterface
31+
*/
32+
private $objectManager;
33+
34+
/**
35+
* @var ScopeConfigInterface
36+
*/
37+
private $config;
38+
39+
/**
40+
* @var array
41+
*/
42+
protected $storeData = [];
43+
44+
/**
45+
* Set up
46+
*/
47+
protected function setUp(): void
48+
{
49+
parent::setUp();
50+
51+
$this->objectManager = Bootstrap::getObjectManager();
52+
$this->config = $this->objectManager->get(ScopeConfigInterface::class);
53+
$this->storeData['name'] = $this->config->getValue(
54+
'general/store_information/name',
55+
ScopeInterface::SCOPE_STORES
56+
);
57+
$this->storeData['phone'] = $this->config->getValue(
58+
'general/store_information/phone',
59+
ScopeInterface::SCOPE_STORES
60+
);
61+
$this->storeData['city'] = $this->config->getValue(
62+
'general/store_information/city',
63+
ScopeInterface::SCOPE_STORES
64+
);
65+
$this->storeData['country'] = $this->config->getValue(
66+
'general/store_information/country_id',
67+
ScopeInterface::SCOPE_STORES
68+
);
69+
}
70+
71+
/**
72+
* @magentoConfigFixture current_store general/store_information/name TestStore
73+
* @magentoConfigFixture default_store general/store_information/phone 5124666492
74+
* @magentoConfigFixture default_store general/store_information/hours 10 to 2
75+
* @magentoConfigFixture default_store general/store_information/street_line1 1 Test Dr
76+
* @magentoConfigFixture default_store general/store_information/street_line2 2nd Addr Line
77+
* @magentoConfigFixture default_store general/store_information/city Austin
78+
* @magentoConfigFixture default_store general/store_information/zip 78739
79+
* @magentoConfigFixture default_store general/store_information/country_id US
80+
* @magentoConfigFixture default_store general/store_information/region_id 57
81+
* @magentoDataFixture Magento/Email/Model/_files/email_template.php
82+
*/
83+
public function testNewAccountEmailTemplate(): void
84+
{
85+
86+
/** @var MutableScopeConfigInterface $config */
87+
$config = Bootstrap::getObjectManager()
88+
->get(MutableScopeConfigInterface::class);
89+
$config->setValue(
90+
'admin/emails/email_template',
91+
$this->getCustomEmailTemplateId(
92+
'template_fixture'
93+
)
94+
);
95+
96+
/** @var \Magento\User\Model\User $userModel */
97+
$userModel = Bootstrap::getObjectManager()->get(\Magento\User\Model\User::class);
98+
$userModel->setFirstname(
99+
'John'
100+
)->setLastname(
101+
'Doe'
102+
)->setUsername(
103+
'user1'
104+
)->setPassword(
105+
TestFrameworkBootstrap::ADMIN_PASSWORD
106+
)->setEmail(
107+
'user1@magento.com'
108+
);
109+
$userModel->save();
110+
111+
$userModel->sendNotificationEmailsIfRequired();
112+
113+
/** @var TransportBuilderMock $transportBuilderMock */
114+
$transportBuilderMock = Bootstrap::getObjectManager()
115+
->get(TransportBuilderMock::class);
116+
$sentMessage = $transportBuilderMock->getSentMessage();
117+
$sentMessage->getBodyText();
118+
119+
$storeText = implode(',', $this->storeData);
120+
121+
$this->assertStringContainsString("John,", $sentMessage->getBodyText());
122+
$this->assertStringContainsString("TestStore", $storeText);
123+
$this->assertStringContainsString("5124666492", $storeText);
124+
$this->assertStringContainsString("Austin", $storeText);
125+
$this->assertStringContainsString("US", $storeText);
126+
}
127+
128+
/**
129+
* Return email template id by origin template code
130+
*
131+
* @param string $origTemplateCode
132+
* @return int|null
133+
* @throws NotFoundException
134+
*/
135+
private function getCustomEmailTemplateId(string $origTemplateCode): ?int
136+
{
137+
$templateId = null;
138+
$templateCollection = Bootstrap::getObjectManager()
139+
->create(TemplateCollection::class);
140+
foreach ($templateCollection as $template) {
141+
if ($template->getOrigTemplateCode() == $origTemplateCode) {
142+
$templateId = (int) $template->getId();
143+
}
144+
}
145+
if ($templateId === null) {
146+
throw new NotFoundException(new Phrase(
147+
'Customized %templateCode% email template not found',
148+
['templateCode' => $origTemplateCode]
149+
));
150+
}
151+
152+
return $templateId;
153+
}
154+
}

dev/tests/integration/testsuite/Magento/Email/Model/_files/email_template.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
[
1313
'template_text' => file_get_contents(__DIR__ . '/template_fixture.html'),
1414
'template_code' => \Magento\Theme\Model\Config\ValidatorTest::TEMPLATE_CODE,
15-
'template_type' => \Magento\Email\Model\Template::TYPE_TEXT
15+
'template_type' => \Magento\Email\Model\Template::TYPE_TEXT,
16+
'orig_template_code' => 'template_fixture'
1617
]
1718
);
1819
$template->save();
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
2+
3+
<p class="greeting">{{trans "%first_name," first_name=$user.firstname}}</p>
4+
<p>{{trans "Welcome to %store_name." store_name=$store.getFrontendName()}}</p>
5+
<p>
6+
{{trans
7+
'To sign in to our site, use these credentials during checkout or on the <a href="%customer_url">My Account</a> page:'
8+
9+
customer_url=$this.getUrl($store,'customer/account/',[_nosid:1])
10+
|raw}}
11+
</p>
12+
<ul>
13+
<li><strong>{{trans "Email:"}}</strong> {{var customer.email}}</li>
14+
<li><strong>{{trans "Password:"}}</strong> <em>{{trans "Password you set when creating account"}}</em></li>
15+
</ul>
16+
<p>
17+
{{trans
18+
'Forgot your account password? Click <a href="%reset_url">here</a> to reset it.'
19+
20+
reset_url="$this.getUrl($store,'customer/account/createPassword/',[_query:[id:$customer.id,token:$customer.rp_token],_nosid:1])"
21+
|raw}}
22+
</p>
23+
<p>{{trans "When you sign in to your account, you will be able to:"}}</p>
24+
<ul>
25+
<li>{{trans "Proceed through checkout faster"}}</li>
26+
<li>{{trans "Check the status of orders"}}</li>
27+
<li>{{trans "View past orders"}}</li>
28+
<li>{{trans "Store alternative addresses (for shipping to multiple family members and friends)"}}</li>
29+
</ul>
30+
31+
<ul>
32+
<li><strong>{{trans "Base Unsecure URL:"}}</strong> {{config path="web/unsecure/base_url"}}</li>
33+
<li><strong>{{trans "Base Secure URL:"}}</strong> {{config path="web/secure/base_url"}}</li>
34+
<li><strong>{{trans "General Contact Name:"}}</strong>{{config path="trans_email/ident_general/name"}} </li>
35+
<li><strong>{{trans "General Contact Email:"}}</strong>{{config path="trans_email/ident_general/email"}} </li>
36+
<li><strong>{{trans "Sales Representative Contact Name:"}}</strong>{{config path="trans_email/ident_sales/name"}} </li>
37+
<li><strong>{{trans "Sales Representative Contact Email:"}}</strong>{{config path="trans_email/ident_sales/email"}} </li>
38+
<li><strong>{{trans "Store Name:"}}</strong>{{config path="general/store_information/name"}} </li>
39+
<li><strong>{{trans "Store Phone Number:"}}</strong> {{config path="general/store_information/phone"}}</li>
40+
<li><strong>{{trans "Store Hours:"}}</strong> {{config path="general/store_information/hours"}}</li>
41+
<li><strong>{{trans "Country:"}}</strong> {{config path="general/store_information/country_id"}}</li>
42+
<li><strong>{{trans "Region/State:"}}</strong>{{config path="general/store_information/region_id"}} </li>
43+
<li><strong>{{trans "Zip/Postal Code:"}}</strong>{{config path="general/store_information/postcode"}} </li>
44+
<li><strong>{{trans "City:"}}</strong> {{config path="general/store_information/city"}}</li>
45+
<li><strong>{{trans "Street Address 1:"}}</strong> {{config path="general/store_information/street_line1"}}</li>
46+
<li><strong>{{trans "Street Address 2:"}}</strong>{{config path="general/store_information/street_line2"}}</li>
47+
</ul>
48+

0 commit comments

Comments
 (0)