33namespace Drupal \Tests \commerce \Unit ;
44
55use Drupal \commerce \ConditionGroup ;
6- use Drupal \commerce_order \Entity \OrderItemInterface ;
7- use Drupal \commerce_order \Plugin \Commerce \Condition \OrderItemQuantity ;
6+ use Drupal \commerce_order \Entity \OrderInterface ;
7+ use Drupal \commerce_order \Plugin \Commerce \Condition \OrderTotalPrice ;
8+ use Drupal \commerce_price \Price ;
89use Drupal \Tests \UnitTestCase ;
910
1011/**
@@ -28,10 +29,13 @@ public function testInvalidOperator() {
2829 */
2930 public function testGetters () {
3031 $ conditions = [];
31- $ conditions [] = new OrderItemQuantity ([
32+ $ conditions [] = new OrderTotalPrice ([
3233 'operator ' => '> ' ,
33- 'quantity ' => '10 ' ,
34- ], 'order_item_quantity ' , []);
34+ 'amount ' => [
35+ 'number ' => '10 ' ,
36+ 'currency_code ' => 'USD ' ,
37+ ],
38+ ], 'order_total_price ' , ['entity_type ' => 'commerce_order ' ]);
3539
3640 $ condition_group = new ConditionGroup ($ conditions , 'AND ' );
3741 $ this ->assertEquals ($ conditions , $ condition_group ->getConditions ());
@@ -43,33 +47,39 @@ public function testGetters() {
4347 */
4448 public function testEvaluate () {
4549 $ conditions = [];
46- $ conditions [] = new OrderItemQuantity ([
50+ $ conditions [] = new OrderTotalPrice ([
4751 'operator ' => '> ' ,
48- 'quantity ' => '10 ' ,
49- ], 'order_item_quantity ' , ['entity_type ' => 'commerce_order_item ' ]);
50- $ conditions [] = new OrderItemQuantity ([
52+ 'amount ' => [
53+ 'number ' => '10 ' ,
54+ 'currency_code ' => 'USD ' ,
55+ ],
56+ ], 'order_total_price ' , ['entity_type ' => 'commerce_order ' ]);
57+ $ conditions [] = new OrderTotalPrice ([
5158 'operator ' => '< ' ,
52- 'quantity ' => '100 ' ,
53- ], 'order_item_quantity ' , ['entity_type ' => 'commerce_order_item ' ]);
54- $ first_order_item = $ this ->prophesize (OrderItemInterface::class);
55- $ first_order_item ->getEntityTypeId ()->willReturn ('commerce_order_item ' );
56- $ first_order_item ->getQuantity ()->willReturn (101 );
57- $ first_order_item = $ first_order_item ->reveal ();
59+ 'amount ' => [
60+ 'number ' => '100 ' ,
61+ 'currency_code ' => 'USD ' ,
62+ ],
63+ ], 'order_total_price ' , ['entity_type ' => 'commerce_order ' ]);
64+ $ first_order = $ this ->prophesize (OrderInterface::class);
65+ $ first_order ->getEntityTypeId ()->willReturn ('commerce_order ' );
66+ $ first_order ->getTotalPrice ()->willReturn (new Price ('101 ' , 'USD ' ));
67+ $ first_order = $ first_order ->reveal ();
5868
59- $ second_order_item = $ this ->prophesize (OrderItemInterface ::class);
60- $ second_order_item ->getEntityTypeId ()->willReturn ('commerce_order_item ' );
61- $ second_order_item ->getQuantity ()->willReturn (90 );
69+ $ second_order_item = $ this ->prophesize (OrderInterface ::class);
70+ $ second_order_item ->getEntityTypeId ()->willReturn ('commerce_order ' );
71+ $ second_order_item ->getTotalPrice ()->willReturn (new Price ( ' 90 ' , ' USD ' ) );
6272 $ second_order_item = $ second_order_item ->reveal ();
6373
6474 $ empty_condition_group = new ConditionGroup ([], 'AND ' );
65- $ this ->assertTrue ($ empty_condition_group ->evaluate ($ first_order_item ));
75+ $ this ->assertTrue ($ empty_condition_group ->evaluate ($ first_order ));
6676
6777 $ and_condition_group = new ConditionGroup ($ conditions , 'AND ' );
68- $ this ->assertFalse ($ and_condition_group ->evaluate ($ first_order_item ));
78+ $ this ->assertFalse ($ and_condition_group ->evaluate ($ first_order ));
6979 $ this ->assertTrue ($ and_condition_group ->evaluate ($ second_order_item ));
7080
7181 $ or_condition_group = new ConditionGroup ($ conditions , 'OR ' );
72- $ this ->assertTrue ($ or_condition_group ->evaluate ($ first_order_item ));
82+ $ this ->assertTrue ($ or_condition_group ->evaluate ($ first_order ));
7383 $ this ->assertTrue ($ or_condition_group ->evaluate ($ second_order_item ));
7484 }
7585
0 commit comments