@@ -45,13 +45,21 @@ class RuleUpdateTest extends AbstractTest
45
45
* @var Mageone_Qps_Model_SecService
46
46
*/
47
47
private $ secService ;
48
+ /**
49
+ * @var \Mageone_Qps_Model_EmailService|MockObject
50
+ */
51
+ private $ emailServiceMock ;
48
52
49
53
protected function setUp (): void
50
54
{
51
55
parent ::setUp ();
52
- $ this ->clientMock = $ this ->createMock (Mage_HTTP_IClient::class);
53
- $ this ->cron = Mage::getModel ('qps/cron ' , ['client ' => $ this ->clientMock ]);
54
- $ this ->secService = Mage::getModel ('qps/secService ' );
56
+ $ this ->clientMock = $ this ->createMock (\Mage_HTTP_IClient::class);
57
+ $ this ->emailServiceMock = $ this ->createMock (\Mageone_Qps_Model_EmailService::class);
58
+ $ this ->cron = Mage::getModel (
59
+ 'qps/cron ' ,
60
+ ['client ' => $ this ->clientMock , 'emailService ' => $ this ->emailServiceMock ]
61
+ );
62
+ $ this ->secService = Mage::getModel ('qps/secService ' );
55
63
56
64
$ this ->helperMock ->method ('getUsername ' )->willReturn (self ::EXAMPLE_USER );
57
65
$ this ->helperMock ->method ('getResourceUrl ' )->willReturn (self ::RESOURCE_URL );
@@ -113,6 +121,37 @@ public function testClientReturns200(): void
113
121
$ this ->cron ->getRules ();
114
122
}
115
123
124
+ public function testClientReturns100 (): void
125
+ {
126
+ $ secService = $ this ->secService ;
127
+ $ validatePostData = (static function ($ postData ) use ($ secService ) {
128
+ if ($ postData ['user ' ] !== self ::EXAMPLE_USER ) {
129
+ return false ;
130
+ }
131
+ $ decrypt = $ secService ->decryptMessage ($ postData ['message ' ]);
132
+ try {
133
+ $ message = json_decode ($ decrypt , true , 512 , JSON_THROW_ON_ERROR );
134
+
135
+ return $ message ['magento_version ' ] === Mage::getVersion ()
136
+ && $ message ['patches_list ' ] === ['test-patch ' => 'TEST patch ' ];
137
+ } catch (Exception $ e ) {
138
+ return false ;
139
+ }
140
+ });
141
+
142
+ $ this ->clientMock
143
+ ->expects ($ this ->once ())
144
+ ->method ('post ' )
145
+ ->with (self ::RESOURCE_URL , $ this ->callback ($ validatePostData ));
146
+
147
+ $ this ->clientMock
148
+ ->expects ($ this ->once ())
149
+ ->method ('getStatus ' )
150
+ ->willReturn (100 );
151
+
152
+ $ this ->cron ->getRules ();
153
+ }
154
+
116
155
public function testClientReturnsNo200 (): void
117
156
{
118
157
$ this ->clientMock
@@ -184,8 +223,10 @@ public function testRulesAreAutoEnabled($rules): void
184
223
*
185
224
* @param string[]
186
225
*/
187
- public function testWriteNewRules ($ rules ): void
226
+ public function testWriteNewRulesAndCallEmailService ($ rules ): void
188
227
{
228
+ $ this ->emailServiceMock ->expects ($ this ->once ())->method ('sendNotificationEmail ' );
229
+
189
230
$ this ->clientMock
190
231
->method ('getStatus ' )
191
232
->willReturn (200 );
0 commit comments