@@ -127,18 +127,20 @@ protected function setUp(): void
127127 * @param string $orderStatus
128128 * @param bool $userHasResource
129129 * @param bool $expectedNotify
130+ * @param string $expectedOrderStatus
130131 *
131132 * @dataProvider executeWillNotifyCustomerDataProvider
132133 */
133134 public function testExecuteWillNotifyCustomer (
134135 array $ historyData ,
135136 string $ orderStatus ,
136137 bool $ userHasResource ,
137- bool $ expectedNotify
138+ bool $ expectedNotify ,
139+ string $ expectedOrderStatus
138140 ) {
139141 $ orderId = 30 ;
140142 $ this ->requestMock ->expects ($ this ->once ())->method ('getParam ' )->with ('order_id ' )->willReturn ($ orderId );
141- $ this ->orderMock ->expects ($ this ->atLeastOnce ())->method ('getDataByKey ' )
143+ $ this ->orderMock ->expects ($ this ->any ())->method ('getDataByKey ' )
142144 ->with ('status ' )->willReturn ($ orderStatus );
143145 $ this ->orderRepositoryMock ->expects ($ this ->once ())
144146 ->method ('get ' )
@@ -152,6 +154,12 @@ public function testExecuteWillNotifyCustomer(
152154 $ this ->objectManagerMock ->expects ($ this ->once ())->method ('create ' )->willReturn (
153155 $ this ->createMock (OrderCommentSender::class)
154156 );
157+
158+ // Verify the getOrderStatus method call
159+ $ this ->orderMock ->expects ($ this ->once ())->method ('setStatus ' )->with ($ expectedOrderStatus );
160+ $ this ->orderMock ->expects ($ this ->once ())->method ('save ' );
161+ $ this ->statusHistoryCommentMock ->expects ($ this ->once ())->method ('save ' );
162+
155163 $ this ->addCommentController ->execute ();
156164 }
157165
@@ -167,57 +175,63 @@ public function executeWillNotifyCustomerDataProvider()
167175 'is_customer_notified ' => true ,
168176 'status ' => 'processing '
169177 ],
170- 'orderStatus ' =>'processing ' ,
178+ 'orderStatus ' => 'processing ' ,
171179 'userHasResource ' => true ,
172- 'expectedNotify ' => true
180+ 'expectedNotify ' => true ,
181+ 'expectedOrderStatus ' => 'processing '
173182 ],
174183 'User Has Access - Notify False ' => [
175184 'postData ' => [
176185 'comment ' => 'Great Product! ' ,
177186 'is_customer_notified ' => false ,
178187 'status ' => 'processing '
179188 ],
180- 'orderStatus ' =>'processing ' ,
189+ 'orderStatus ' => 'processing ' ,
181190 'userHasResource ' => true ,
182- 'expectedNotify ' => false
191+ 'expectedNotify ' => false ,
192+ 'expectedOrderStatus ' => 'processing '
183193 ],
184194 'User Has Access - Notify Unset ' => [
185195 'postData ' => [
186196 'comment ' => 'Great Product! ' ,
187197 'status ' => 'processing '
188198 ],
189- 'orderStatus ' =>'fraud ' ,
199+ 'orderStatus ' => 'fraud ' ,
190200 'userHasResource ' => true ,
191- 'expectedNotify ' => false
201+ 'expectedNotify ' => false ,
202+ 'expectedOrderStatus ' => 'processing '
192203 ],
193204 'User No Access - Notify True ' => [
194205 'postData ' => [
195206 'comment ' => 'Great Product! ' ,
196207 'is_customer_notified ' => true ,
197208 'status ' => 'fraud '
198209 ],
199- 'orderStatus ' =>'processing ' ,
210+ 'orderStatus ' => 'processing ' ,
200211 'userHasResource ' => false ,
201- 'expectedNotify ' => false
212+ 'expectedNotify ' => false ,
213+ 'expectedOrderStatus ' => 'fraud '
202214 ],
203215 'User No Access - Notify False ' => [
204216 'postData ' => [
205217 'comment ' => 'Great Product! ' ,
206218 'is_customer_notified ' => false ,
207219 'status ' => 'processing '
208220 ],
209- 'orderStatus ' =>'complete ' ,
221+ 'orderStatus ' => 'complete ' ,
210222 'userHasResource ' => false ,
211- 'expectedNotify ' => false
223+ 'expectedNotify ' => false ,
224+ 'expectedOrderStatus ' => 'processing '
212225 ],
213226 'User No Access - Notify Unset ' => [
214227 'postData ' => [
215228 'comment ' => 'Great Product! ' ,
216229 'status ' => 'processing '
217230 ],
218- 'orderStatus ' =>'complete ' ,
231+ 'orderStatus ' => 'complete ' ,
219232 'userHasResource ' => false ,
220- 'expectedNotify ' => false
233+ 'expectedNotify ' => false ,
234+ 'expectedOrderStatus ' => 'processing '
221235 ],
222236 ];
223237 }
0 commit comments