33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
67
78namespace Magento \ProductAlert \Model ;
89
910use Magento \Catalog \Api \ProductRepositoryInterface ;
11+ use Magento \Catalog \Model \Product ;
1012use Magento \Customer \Api \AccountManagementInterface ;
1113use Magento \Customer \Api \CustomerRepositoryInterface ;
14+ use Magento \Customer \Helper \View ;
1215use Magento \Framework \Exception \LocalizedException ;
1316use Magento \Framework \Exception \MailException ;
1417use Magento \Framework \Exception \NoSuchEntityException ;
18+ use Magento \Store \Model \StoreManagerInterface ;
1519use Magento \Store \Model \Website ;
20+ use Magento \TestFramework \Helper \Bootstrap ;
1621use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
22+ use Magento \TestFramework \ObjectManager ;
23+ use PHPUnit \Framework \TestCase ;
1724
1825/**
1926 * Test for Magento\ProductAlert\Model\Email class.
2027 *
2128 * @magentoAppIsolation enabled
29+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2230 */
23- class EmailTest extends \ PHPUnit \ Framework \ TestCase
31+ class EmailTest extends TestCase
2432{
2533 /**
2634 * @var Email
2735 */
2836 protected $ _emailModel ;
2937
3038 /**
31- * @var \Magento\TestFramework\ ObjectManager
39+ * @var ObjectManager
3240 */
3341 protected $ _objectManager ;
3442
@@ -38,7 +46,7 @@ class EmailTest extends \PHPUnit\Framework\TestCase
3846 protected $ customerAccountManagement ;
3947
4048 /**
41- * @var \Magento\Customer\Helper\ View
49+ * @var View
4250 */
4351 protected $ _customerViewHelper ;
4452
@@ -62,11 +70,11 @@ class EmailTest extends \PHPUnit\Framework\TestCase
6270 */
6371 protected function setUp (): void
6472 {
65- $ this ->_objectManager = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ();
73+ $ this ->_objectManager = Bootstrap::getObjectManager ();
6674 $ this ->customerAccountManagement = $ this ->_objectManager ->create (
6775 AccountManagementInterface::class
6876 );
69- $ this ->_customerViewHelper = $ this ->_objectManager ->create (\ Magento \ Customer \ Helper \ View::class);
77+ $ this ->_customerViewHelper = $ this ->_objectManager ->create (View::class);
7078 $ this ->transportBuilder = $ this ->_objectManager ->get (TransportBuilderMock::class);
7179 $ this ->customerRepository = $ this ->_objectManager ->create (CustomerRepositoryInterface::class);
7280 $ this ->productRepository = $ this ->_objectManager ->create (ProductRepositoryInterface::class);
@@ -100,7 +108,7 @@ public function testSend($isCustomerIdUsed)
100108 $ this ->_emailModel ->setCustomerData ($ customer );
101109 }
102110
103- /** @var \Magento\Catalog\Model\ Product $product */
111+ /** @var Product $product */
104112 $ product = $ this ->productRepository ->getById (1 );
105113
106114 $ this ->_emailModel ->addPriceProduct ($ product );
@@ -165,4 +173,36 @@ public function testEmailForDifferentCustomers(): void
165173 );
166174 }
167175 }
176+
177+ /**
178+ * @magentoAppArea frontend
179+ * @magentoDataFixture Magento/Customer/_files/customer.php
180+ * @magentoDataFixture Magento/Catalog/_files/product_simple.php
181+ * @magentoDataFixture Magento/Store/_files/second_store_with_second_identity.php
182+ */
183+ public function testScopedMessageIdentity ()
184+ {
185+ /** @var Website $website */
186+ $ website = $ this ->_objectManager ->create (Website::class);
187+ $ website ->load (1 );
188+ $ this ->_emailModel ->setWebsite ($ website );
189+
190+ /** @var StoreManagerInterface $storeManager */
191+ $ storeManager = $ this ->_objectManager ->create (StoreManagerInterface::class);
192+ $ store = $ storeManager ->getStore ('fixture_second_store ' );
193+ $ this ->_emailModel ->setStoreId ($ store ->getId ());
194+
195+ $ customer = $ this ->customerRepository ->getById (1 );
196+ $ this ->_emailModel ->setCustomerData ($ customer );
197+
198+ /** @var Product $product */
199+ $ product = $ this ->productRepository ->getById (1 );
200+
201+ $ this ->_emailModel ->addPriceProduct ($ product );
202+ $ this ->_emailModel ->send ();
203+
204+ $ from = $ this ->transportBuilder ->getSentMessage ()->getFrom ()[0 ];
205+ $ this ->assertEquals ('Fixture Store Owner ' , $ from ->getName ());
206+ $ this ->assertEquals ('fixture.store.owner@example.com ' , $ from ->getEmail ());
207+ }
168208}
0 commit comments