99
1010use Magento \Customer \Api \AccountManagementInterface ;
1111use Magento \Customer \Model \Session ;
12- use Magento \Framework \App \Area ;
1312use Magento \Framework \Locale \Resolver ;
13+ use Magento \Framework \Mail \EmailMessage ;
1414use Magento \Framework \Module \Dir \Reader ;
1515use Magento \Framework \Phrase ;
1616use Magento \Framework \Phrase \Renderer \Translate as PhraseRendererTranslate ;
1717use Magento \Framework \Phrase \RendererInterface ;
1818use Magento \Framework \Translate ;
19+ use Magento \Framework \View \Design \ThemeInterface ;
20+ use Magento \Framework \View \DesignInterface ;
1921use Magento \Store \Model \StoreRepository ;
2022use Magento \TestFramework \Helper \Bootstrap ;
2123use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
@@ -50,6 +52,11 @@ class AlertProcessorTest extends TestCase
5052 */
5153 private $ transportBuilder ;
5254
55+ /**
56+ * @var DesignInterface
57+ */
58+ private $ design ;
59+
5360 /**
5461 * @inheritDoc
5562 */
@@ -64,6 +71,7 @@ protected function setUp(): void
6471 $ customer = $ service ->authenticate ('customer@example.com ' , 'password ' );
6572 $ customerSession = $ this ->objectManager ->get (Session::class);
6673 $ customerSession ->setCustomerDataAsLoggedIn ($ customer );
74+ $ this ->design = $ this ->objectManager ->get (DesignInterface::class);
6775 }
6876
6977 /**
@@ -139,4 +147,44 @@ private function processAlerts(): void
139147 $ this ->publisher ->execute ($ alertType , [$ customerId ], $ websiteId );
140148 $ this ->alertProcessor ->process ($ alertType , [$ customerId ], $ websiteId );
141149 }
150+
151+ /**
152+ * Validate the current theme
153+ *
154+ * @magentoConfigFixture current_store catalog/productalert/allow_price 1
155+ * @magentoDataFixture Magento/ProductAlert/_files/product_alert.php
156+ */
157+ public function testValidateCurrentTheme ()
158+ {
159+ $ this ->design ->setDesignTheme (
160+ $ this ->objectManager ->get (ThemeInterface::class)
161+ );
162+
163+ $ this ->processAlerts ();
164+
165+ $ message = $ this ->transportBuilder ->getSentMessage ();
166+ $ messageContent = $ this ->getMessageRawContent ($ message );
167+ $ emailDom = new \DOMDocument ();
168+ $ emailDom ->loadHTML ($ messageContent );
169+
170+ $ emailXpath = new \DOMXPath ($ emailDom );
171+ $ greeting = $ emailXpath ->query ('//img[@class="photo image"] ' );
172+ $ this ->assertStringContainsString (
173+ 'thumbnail.jpg ' ,
174+ $ greeting ->item (0 )->getAttribute ('src ' )
175+ );
176+ $ this ->assertEquals ('Magento/luma ' , $ this ->design ->getDesignTheme ()->getCode ());
177+ }
178+
179+ /**
180+ * Returns raw content of provided message
181+ *
182+ * @param EmailMessage $message
183+ * @return string
184+ */
185+ private function getMessageRawContent (EmailMessage $ message ): string
186+ {
187+ $ emailParts = $ message ->getBody ()->getParts ();
188+ return current ($ emailParts )->getRawContent ();
189+ }
142190}
0 commit comments