@@ -185,132 +185,6 @@ public function testGetCouponLoyalty($email, $code)
185185 }
186186 }
187187
188- public function testCreateLoyaltyCouponWithoutAppliedCoupon ()
189- {
190- $ products = DataLoyaltyRetailCrm::createProducts ();
191- $ user = DataLoyaltyRetailcrm::createUsers ()[0 ];
192-
193- $ cart = new WC_Cart ();
194- $ cart ->add_to_cart ($ products [0 ]->get_id ());
195- $ cart ->add_to_cart ($ products [1 ]->get_id ());
196-
197- $ woocommerce = wc ();
198- $ woocommerce ->cart = $ cart ;
199- $ woocommerce ->customer = $ user ;
200-
201- $ validatorMock = $ this ->getMockBuilder ('\WC_Retailcrm_Loyalty_Validator ' )
202- ->disableOriginalConstructor ()
203- ->getMock ()
204- ;
205- $ this ->setMockResponse ($ validatorMock , 'checkAccount ' , true );
206- $ validatorMock ->loyaltyAccount ['level ' ]['type ' ] = 'loyalty_level ' ;
207-
208- $ responseCalculation = DataLoyaltyRetailCrm::getDataCalculation ()[1 ];
209- $ responseMock = new WC_Retailcrm_Response (200 , json_encode ($ responseCalculation ['response ' ]));
210- $ this ->setMockResponse ($ this ->apiMock , 'calculateDiscountLoyalty ' , $ responseMock );
211-
212- $ this ->loyalty = new WC_Retailcrm_Loyalty ($ this ->apiMock , []);
213- $ reflection = new \ReflectionClass ($ this ->loyalty );
214- $ reflection_property = $ reflection ->getProperty ('validator ' );
215- $ reflection_property ->setAccessible (true );
216- $ reflection_property ->setValue ($ this ->loyalty , $ validatorMock );
217-
218- $ GLOBALS ['woocommerce ' ] = $ woocommerce ;
219- $ result = $ this ->loyalty ->createLoyaltyCoupon ();
220-
221- $ this ->assertNotEmpty ($ result );
222- $ this ->assertNotEmpty ($ this ->loyalty ->getCouponLoyalty ($ woocommerce ->customer ->get_email ()));
223- }
224-
225- public function testCreateLoyaltyCouponWithPercentDiscount ()
226- {
227- $ products = DataLoyaltyRetailCrm::createProducts ();
228- $ user = DataLoyaltyRetailcrm::createUsers ()[0 ];
229-
230- $ cart = new WC_Cart ();
231- $ cart ->add_to_cart ($ products [0 ]->get_id ());
232- $ cart ->add_to_cart ($ products [1 ]->get_id ());
233-
234- $ woocommerce = wc ();
235- $ woocommerce ->cart = $ cart ;
236- $ woocommerce ->customer = $ user ;
237-
238- $ validatorMock = $ this ->getMockBuilder ('\WC_Retailcrm_Loyalty_Validator ' )
239- ->disableOriginalConstructor ()
240- ->getMock ()
241- ;
242- $ this ->setMockResponse ($ validatorMock , 'checkAccount ' , true );
243- $ validatorMock ->loyaltyAccount ['level ' ]['type ' ] = 'discount ' ;
244-
245- $ responseCalculation = DataLoyaltyRetailCrm::getDataCalculation ()[1 ];
246- $ responseMock = new WC_Retailcrm_Response (200 , json_encode ($ responseCalculation ['response ' ]));
247- $ this ->setMockResponse ($ this ->apiMock , 'calculateDiscountLoyalty ' , $ responseMock );
248-
249- $ this ->loyalty = new WC_Retailcrm_Loyalty ($ this ->apiMock , []);
250- $ reflection = new \ReflectionClass ($ this ->loyalty );
251- $ reflection_property = $ reflection ->getProperty ('validator ' );
252- $ reflection_property ->setAccessible (true );
253- $ reflection_property ->setValue ($ this ->loyalty , $ validatorMock );
254-
255- $ GLOBALS ['woocommerce ' ] = $ woocommerce ;
256- $ result = $ this ->loyalty ->createLoyaltyCoupon ();
257-
258- $ this ->assertEmpty ($ result );
259- $ this ->assertNotEmpty ($ this ->loyalty ->getCouponLoyalty ($ woocommerce ->customer ->get_email ()));
260- $ this ->assertNotEmpty ($ woocommerce ->cart ->get_coupons ());
261- }
262-
263- public function testCreateLoyaltyCouponWithRefreshCoupon ()
264- {
265- $ products = DataLoyaltyRetailCrm::createProducts ();
266- $ user = DataLoyaltyRetailcrm::createUsers ()[0 ];
267-
268- $ cart = new WC_Cart ();
269- $ cart ->add_to_cart ($ products [0 ]->get_id ());
270- $ cart ->add_to_cart ($ products [1 ]->get_id ());
271-
272- $ coupon = new WC_Coupon ();
273- $ coupon ->set_usage_limit (0 );
274- $ coupon ->set_amount ('50 ' );
275- $ coupon ->set_email_restrictions ($ user ->get_email ());
276- $ coupon ->set_code ('loyalty ' . mt_rand ());
277- $ coupon ->save ();
278- $ cart ->apply_coupon ($ coupon ->get_code ());
279-
280- $ couponCode = $ coupon ->get_code ();
281- $ woocommerce = wc ();
282- $ woocommerce ->cart = $ cart ;
283- $ woocommerce ->customer = $ user ;
284-
285- $ validatorMock = $ this ->getMockBuilder ('\WC_Retailcrm_Loyalty_Validator ' )
286- ->disableOriginalConstructor ()
287- ->getMock ()
288- ;
289- $ this ->setMockResponse ($ validatorMock , 'checkAccount ' , true );
290- $ validatorMock ->loyaltyAccount ['level ' ]['type ' ] = 'discount ' ;
291-
292- $ responseCalculation = DataLoyaltyRetailCrm::getDataCalculation ()[1 ];
293- $ responseMock = new WC_Retailcrm_Response (200 , json_encode ($ responseCalculation ['response ' ]));
294- $ this ->setMockResponse ($ this ->apiMock , 'calculateDiscountLoyalty ' , $ responseMock );
295-
296- $ this ->loyalty = new WC_Retailcrm_Loyalty ($ this ->apiMock , []);
297- $ reflection = new \ReflectionClass ($ this ->loyalty );
298- $ reflection_property = $ reflection ->getProperty ('validator ' );
299- $ reflection_property ->setAccessible (true );
300- $ reflection_property ->setValue ($ this ->loyalty , $ validatorMock );
301-
302- $ GLOBALS ['woocommerce ' ] = $ woocommerce ;
303- $ result = $ this ->loyalty ->createLoyaltyCoupon (true );
304-
305- $ this ->assertEmpty ($ result );
306- $ this ->assertNotEmpty ($ this ->loyalty ->getCouponLoyalty ($ woocommerce ->customer ->get_email ()));
307-
308- $ coupons = $ woocommerce ->cart ->get_coupons ();
309-
310- $ this ->assertNotEmpty ($ coupons );
311- $ this ->assertFalse (isset ($ coupons [$ couponCode ]));
312- }
313-
314188 public function testDeleteLoyaltyCouponInOrder ()
315189 {
316190 $ products = DataLoyaltyRetailCrm::createProducts ();
0 commit comments