9
9
10
10
use Magento \Customer \Api \AccountManagementInterface ;
11
11
use Magento \Customer \Model \Session ;
12
- use Magento \Framework \App \Area ;
13
12
use Magento \Framework \Locale \Resolver ;
13
+ use Magento \Framework \Mail \EmailMessage ;
14
14
use Magento \Framework \Module \Dir \Reader ;
15
15
use Magento \Framework \Phrase ;
16
16
use Magento \Framework \Phrase \Renderer \Translate as PhraseRendererTranslate ;
17
17
use Magento \Framework \Phrase \RendererInterface ;
18
18
use Magento \Framework \Translate ;
19
+ use Magento \Framework \View \Design \ThemeInterface ;
20
+ use Magento \Framework \View \DesignInterface ;
19
21
use Magento \Store \Model \StoreRepository ;
20
22
use Magento \TestFramework \Helper \Bootstrap ;
21
23
use Magento \TestFramework \Mail \Template \TransportBuilderMock ;
@@ -50,6 +52,11 @@ class AlertProcessorTest extends TestCase
50
52
*/
51
53
private $ transportBuilder ;
52
54
55
+ /**
56
+ * @var DesignInterface
57
+ */
58
+ private $ design ;
59
+
53
60
/**
54
61
* @inheritDoc
55
62
*/
@@ -64,6 +71,7 @@ protected function setUp(): void
64
71
$ customer = $ service ->authenticate ('customer@example.com ' , 'password ' );
65
72
$ customerSession = $ this ->objectManager ->get (Session::class);
66
73
$ customerSession ->setCustomerDataAsLoggedIn ($ customer );
74
+ $ this ->design = $ this ->objectManager ->get (DesignInterface::class);
67
75
}
68
76
69
77
/**
@@ -139,4 +147,44 @@ private function processAlerts(): void
139
147
$ this ->publisher ->execute ($ alertType , [$ customerId ], $ websiteId );
140
148
$ this ->alertProcessor ->process ($ alertType , [$ customerId ], $ websiteId );
141
149
}
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
+ }
142
190
}
0 commit comments