33namespace Drupal \Tests \commerce_log \Kernel ;
44
55use Drupal \commerce_order \Entity \Order ;
6+ use Drupal \commerce_order \Entity \OrderType ;
67use Drupal \commerce_price \Price ;
78use Drupal \commerce_product \Entity \Product ;
89use Drupal \commerce_product \Entity \ProductVariation ;
@@ -71,6 +72,11 @@ protected function setUp() {
7172 $ this ->logStorage = $ this ->container ->get ('entity_type.manager ' )->getStorage ('commerce_log ' );
7273 $ this ->logViewBuilder = $ this ->container ->get ('entity_type.manager ' )->getViewBuilder ('commerce_log ' );
7374
75+ // Change the workflow of the default order type.
76+ $ order_type = OrderType::load ('default ' );
77+ $ order_type ->setWorkflowId ('order_fulfillment_validation ' );
78+ $ order_type ->save ();
79+
7480 // Turn off title generation to allow explicit values to be used.
7581 $ variation_type = ProductVariationType::load ('default ' );
7682 $ variation_type ->setGenerateTitle (FALSE );
@@ -123,9 +129,28 @@ protected function setUp() {
123129 }
124130
125131 /**
126- * Tests that a log is generated when an order is placed .
132+ * Tests that a log is generated for the cancel transition .
127133 */
128- public function testPlacedLog () {
134+ public function testCancelLog () {
135+ // Draft -> Canceled.
136+ $ transition = $ this ->order ->getState ()->getTransitions ();
137+ $ this ->order ->getState ()->applyTransition ($ transition ['cancel ' ]);
138+ $ this ->order ->save ();
139+
140+ $ logs = $ this ->logStorage ->loadByEntity ($ this ->order );
141+ $ this ->assertEquals (1 , count ($ logs ));
142+ $ log = reset ($ logs );
143+ $ build = $ this ->logViewBuilder ->view ($ log );
144+ $ this ->render ($ build );
145+
146+ $ this ->assertText ('The order was canceled. ' );
147+ }
148+
149+ /**
150+ * Tests that a log is generated for place, validate, and fulfill transitions.
151+ */
152+ public function testPlaceValidateFulfillLogs () {
153+ // Draft -> Placed.
129154 $ transition = $ this ->order ->getState ()->getTransitions ();
130155 $ this ->order ->getState ()->applyTransition ($ transition ['place ' ]);
131156 $ this ->order ->save ();
@@ -137,6 +162,32 @@ public function testPlacedLog() {
137162 $ this ->render ($ build );
138163
139164 $ this ->assertText ('The order was placed. ' );
165+
166+ // Placed -> Validated.
167+ $ transition = $ this ->order ->getState ()->getTransitions ();
168+ $ this ->order ->getState ()->applyTransition ($ transition ['validate ' ]);
169+ $ this ->order ->save ();
170+
171+ $ logs = $ this ->logStorage ->loadByEntity ($ this ->order );
172+ $ this ->assertEquals (2 , count ($ logs ));
173+ $ log = $ logs [2 ];
174+ $ build = $ this ->logViewBuilder ->view ($ log );
175+ $ this ->render ($ build );
176+
177+ $ this ->assertText ('The order was validated. ' );
178+
179+ // Validated -> Fulfilled.
180+ $ transition = $ this ->order ->getState ()->getTransitions ();
181+ $ this ->order ->getState ()->applyTransition ($ transition ['fulfill ' ]);
182+ $ this ->order ->save ();
183+
184+ $ logs = $ this ->logStorage ->loadByEntity ($ this ->order );
185+ $ this ->assertEquals (3 , count ($ logs ));
186+ $ log = $ logs [3 ];
187+ $ build = $ this ->logViewBuilder ->view ($ log );
188+ $ this ->render ($ build );
189+
190+ $ this ->assertText ('The order was fulfilled. ' );
140191 }
141192
142193}
0 commit comments