@@ -674,6 +674,79 @@ public function test_remove_conditions_by_type()
674674 $ this ->assertEquals (1 , $ this ->cart ->getConditions ()->count (), "We should have 1 condition remaining as promo conditions type has been removed. " );
675675 }
676676
677+ public function test_add_cart_condition_without_condition_attributes ()
678+ {
679+ $ cartCondition1 = new CartCondition (array (
680+ 'name ' => 'SALE 5% ' ,
681+ 'type ' => 'sale ' ,
682+ 'target ' => 'subtotal ' ,
683+ 'value ' => '-5% '
684+ ));
685+
686+ $ item = array (
687+ 'id ' => 456 ,
688+ 'name ' => 'Sample Item 1 ' ,
689+ 'price ' => 100 ,
690+ 'quantity ' => 1 ,
691+ 'attributes ' => array (),
692+ );
693+
694+ $ this ->cart ->add ($ item );
695+
696+ $ this ->cart ->condition ([$ cartCondition1 ]);
697+
698+ // prove first we have now the condition on the cart
699+ $ contition = $ this ->cart ->getCondition ("SALE 5% " );
700+ $ this ->assertEquals ('SALE 5% ' ,$ contition ->getName ());
701+
702+ // when get attribute is called and there is no attributes added,
703+ // it should return an empty array
704+ $ conditionAttribute = $ contition ->getAttributes ();
705+ $ this ->assertInternalType ('array ' , $ conditionAttribute );
706+ }
707+
708+ public function test_add_cart_condition_with_condition_attributes ()
709+ {
710+ $ cartCondition1 = new CartCondition (array (
711+ 'name ' => 'SALE 5% ' ,
712+ 'type ' => 'sale ' ,
713+ 'target ' => 'subtotal ' ,
714+ 'value ' => '-5% ' ,
715+ 'attributes ' => array (
716+ 'description ' => 'october fest promo sale ' ,
717+ 'sale_start_date ' => '2015-01-20 ' ,
718+ 'sale_end_date ' => '2015-01-30 ' ,
719+ )
720+ ));
721+
722+ $ item = array (
723+ 'id ' => 456 ,
724+ 'name ' => 'Sample Item 1 ' ,
725+ 'price ' => 100 ,
726+ 'quantity ' => 1 ,
727+ 'attributes ' => array (),
728+ );
729+
730+ $ this ->cart ->add ($ item );
731+
732+ $ this ->cart ->condition ([$ cartCondition1 ]);
733+
734+ // prove first we have now the condition on the cart
735+ $ contition = $ this ->cart ->getCondition ("SALE 5% " );
736+ $ this ->assertEquals ('SALE 5% ' ,$ contition ->getName ());
737+
738+ // when get attribute is called and there is no attributes added,
739+ // it should return an empty array
740+ $ conditionAttributes = $ contition ->getAttributes ();
741+ $ this ->assertInternalType ('array ' , $ conditionAttributes );
742+ $ this ->assertArrayHasKey ('description ' ,$ conditionAttributes );
743+ $ this ->assertArrayHasKey ('sale_start_date ' ,$ conditionAttributes );
744+ $ this ->assertArrayHasKey ('sale_end_date ' ,$ conditionAttributes );
745+ $ this ->assertEquals ('october fest promo sale ' ,$ conditionAttributes ['description ' ]);
746+ $ this ->assertEquals ('2015-01-20 ' ,$ conditionAttributes ['sale_start_date ' ]);
747+ $ this ->assertEquals ('2015-01-30 ' ,$ conditionAttributes ['sale_end_date ' ]);
748+ }
749+
677750 protected function fillCart ()
678751 {
679752 $ items = array (
0 commit comments