@@ -327,18 +327,18 @@ public function test_add_item_with_multiple_item_conditions_with_one_condition_w
327327 $ this ->assertEquals (85.00 , $ this ->cart ->getSubTotal (), 'Cart subtotal with 1 item should be 70 ' );
328328 }
329329
330- public function test_get_condition_by_condition_name ()
330+ public function test_get_cart_condition_by_condition_name ()
331331 {
332332 $ itemCondition1 = new CartCondition (array (
333333 'name ' => 'SALE 5% ' ,
334334 'type ' => 'sale ' ,
335- 'target ' => 'subtotal ' ,
335+ 'target ' => 'total ' ,
336336 'value ' => '-5% ' ,
337337 ));
338338 $ itemCondition2 = new CartCondition (array (
339339 'name ' => 'Item Gift Pack 25.00 ' ,
340340 'type ' => 'promo ' ,
341- 'target ' => 'subtotal ' ,
341+ 'target ' => 'total ' ,
342342 'value ' => '-25 ' ,
343343 ));
344344
@@ -358,11 +358,126 @@ public function test_get_condition_by_condition_name()
358358 $ condition = $ this ->cart ->getCondition ($ itemCondition1 ->getName ());
359359
360360 $ this ->assertEquals ($ condition ->getName (), 'SALE 5% ' );
361- $ this ->assertEquals ($ condition ->getTarget (), 'subtotal ' );
361+ $ this ->assertEquals ($ condition ->getTarget (), 'total ' );
362362 $ this ->assertEquals ($ condition ->getType (), 'sale ' );
363363 $ this ->assertEquals ($ condition ->getValue (), '-5% ' );
364364 }
365365
366+ public function test_remove_cart_condition_by_condition_name ()
367+ {
368+ $ itemCondition1 = new CartCondition (array (
369+ 'name ' => 'SALE 5% ' ,
370+ 'type ' => 'sale ' ,
371+ 'target ' => 'total ' ,
372+ 'value ' => '-5% ' ,
373+ ));
374+ $ itemCondition2 = new CartCondition (array (
375+ 'name ' => 'Item Gift Pack 25.00 ' ,
376+ 'type ' => 'promo ' ,
377+ 'target ' => 'total ' ,
378+ 'value ' => '-25 ' ,
379+ ));
380+
381+ $ item = array (
382+ 'id ' => 456 ,
383+ 'name ' => 'Sample Item 1 ' ,
384+ 'price ' => 100 ,
385+ 'quantity ' => 1 ,
386+ 'attributes ' => array (),
387+ );
388+
389+ $ this ->cart ->add ($ item );
390+
391+ $ this ->cart ->condition ([$ itemCondition1 , $ itemCondition2 ]);
392+
393+ // let's prove first we have now two conditions in the cart
394+ $ this ->assertEquals (2 , $ this ->cart ->getConditions ()->count (), 'Cart should have two conditions ' );
395+
396+ // now let's remove a specific condition by condition name
397+ $ this ->cart ->removeCartCondition ('SALE 5% ' );
398+
399+ // cart should have now only 1 condition
400+ $ this ->assertEquals (1 , $ this ->cart ->getConditions ()->count (), 'Cart should have one condition ' );
401+ $ this ->assertEquals ('Item Gift Pack 25.00 ' , $ this ->cart ->getConditions ()->first ()->getName ());
402+ }
403+
404+ public function test_remove_item_condition_by_condition_name ()
405+ {
406+ $ itemCondition1 = new CartCondition (array (
407+ 'name ' => 'SALE 5% ' ,
408+ 'type ' => 'sale ' ,
409+ 'target ' => 'subtotal ' ,
410+ 'value ' => '-5% ' ,
411+ ));
412+ $ itemCondition2 = new CartCondition (array (
413+ 'name ' => 'Item Gift Pack 25.00 ' ,
414+ 'type ' => 'promo ' ,
415+ 'target ' => 'subtotal ' ,
416+ 'value ' => '-25 ' ,
417+ ));
418+
419+ $ item = array (
420+ 'id ' => 456 ,
421+ 'name ' => 'Sample Item 1 ' ,
422+ 'price ' => 100 ,
423+ 'quantity ' => 1 ,
424+ 'attributes ' => array (),
425+ 'conditions ' => [$ itemCondition1 , $ itemCondition2 ]
426+ );
427+
428+ $ this ->cart ->add ($ item );
429+
430+ // let's very first the item has 2 conditions in it
431+ $ this ->assertCount (2 ,$ this ->cart ->get (456 )['conditions ' ], 'Item should have two conditions ' );
432+
433+ // now let's remove a condition on that item using the condition name
434+ $ this ->cart ->removeItemCondition (456 , 'SALE 5% ' );
435+
436+ // now we should have only 1 condition left on that item
437+ $ this ->assertCount (1 ,$ this ->cart ->get (456 )['conditions ' ], 'Item should have one condition left ' );
438+ }
439+
440+ public function test_clear_cart_conditions ()
441+ {
442+ // NOTE:
443+ // This only clears all conditions that has been added in a cart bases
444+ // this does not remove conditions on per item bases
445+
446+ $ itemCondition1 = new CartCondition (array (
447+ 'name ' => 'SALE 5% ' ,
448+ 'type ' => 'sale ' ,
449+ 'target ' => 'total ' ,
450+ 'value ' => '-5% ' ,
451+ ));
452+ $ itemCondition2 = new CartCondition (array (
453+ 'name ' => 'Item Gift Pack 25.00 ' ,
454+ 'type ' => 'promo ' ,
455+ 'target ' => 'total ' ,
456+ 'value ' => '-25 ' ,
457+ ));
458+
459+ $ item = array (
460+ 'id ' => 456 ,
461+ 'name ' => 'Sample Item 1 ' ,
462+ 'price ' => 100 ,
463+ 'quantity ' => 1 ,
464+ 'attributes ' => array (),
465+ );
466+
467+ $ this ->cart ->add ($ item );
468+
469+ $ this ->cart ->condition ([$ itemCondition1 , $ itemCondition2 ]);
470+
471+ // let's prove first we have now two conditions in the cart
472+ $ this ->assertEquals (2 , $ this ->cart ->getConditions ()->count (), 'Cart should have two conditions ' );
473+
474+ // now let's clear cart conditions
475+ $ this ->cart ->clearCartConditions ();
476+
477+ // cart should have now only 1 condition
478+ $ this ->assertEquals (0 , $ this ->cart ->getConditions ()->count (), 'Cart should have no conditions now ' );
479+ }
480+
366481 protected function fillCart ()
367482 {
368483 $ items = array (
0 commit comments