1818use Commercetools \Core \Request \ProductDiscounts \Command \ProductDiscountChangeSortOrderAction ;
1919use Commercetools \Core \Request \ProductDiscounts \Command \ProductDiscountChangeValueAction ;
2020use Commercetools \Core \Request \ProductDiscounts \Command \ProductDiscountSetDescriptionAction ;
21+ use Commercetools \Core \Request \ProductDiscounts \Command \ProductDiscountSetValidFromAction ;
22+ use Commercetools \Core \Request \ProductDiscounts \Command \ProductDiscountSetValidUntilAction ;
2123use Commercetools \Core \Request \ProductDiscounts \ProductDiscountCreateRequest ;
2224use Commercetools \Core \Request \ProductDiscounts \ProductDiscountDeleteRequest ;
2325use Commercetools \Core \Request \ProductDiscounts \ProductDiscountUpdateRequest ;
@@ -49,7 +51,7 @@ protected function createProductDiscount(ProductDiscountDraft $draft)
4951 $ request = ProductDiscountCreateRequest::ofDraft ($ draft );
5052 $ response = $ request ->executeWithClient ($ this ->getClient ());
5153 $ productDiscount = $ request ->mapResponse ($ response );
52- $ this ->cleanupRequests [] = ProductDiscountDeleteRequest::ofIdAndVersion (
54+ $ this ->cleanupRequests [] = $ this -> deleteRequest = ProductDiscountDeleteRequest::ofIdAndVersion (
5355 $ productDiscount ->getId (),
5456 $ productDiscount ->getVersion ()
5557 );
@@ -78,12 +80,7 @@ public function testChangeIsActive()
7880 $ this ->assertInstanceOf (ProductDiscount::class, $ result );
7981 $ this ->assertSame ($ isActive , $ result ->getIsActive ());
8082 $ this ->assertNotSame ($ productDiscount ->getVersion (), $ result ->getVersion ());
81-
82- $ deleteRequest = array_pop ($ this ->cleanupRequests );
83- $ deleteRequest ->setVersion ($ result ->getVersion ());
84- $ result = $ this ->getClient ()->execute ($ deleteRequest )->toObject ();
85-
86- $ this ->assertInstanceOf (ProductDiscount::class, $ result );
83+ $ this ->deleteRequest ->setVersion ($ result ->getVersion ());
8784 }
8885
8986 public function testChangePredicate ()
@@ -108,11 +105,7 @@ public function testChangePredicate()
108105 $ this ->assertSame ($ predicate , $ result ->getPredicate ());
109106 $ this ->assertNotSame ($ productDiscount ->getVersion (), $ result ->getVersion ());
110107
111- $ deleteRequest = array_pop ($ this ->cleanupRequests );
112- $ deleteRequest ->setVersion ($ result ->getVersion ());
113- $ result = $ this ->getClient ()->execute ($ deleteRequest )->toObject ();
114-
115- $ this ->assertInstanceOf (ProductDiscount::class, $ result );
108+ $ this ->deleteRequest ->setVersion ($ result ->getVersion ());
116109 }
117110
118111
@@ -137,11 +130,7 @@ public function testChangeName()
137130 $ this ->assertSame ($ name ->en , $ result ->getName ()->en );
138131 $ this ->assertNotSame ($ productDiscount ->getVersion (), $ result ->getVersion ());
139132
140- $ deleteRequest = array_pop ($ this ->cleanupRequests );
141- $ deleteRequest ->setVersion ($ result ->getVersion ());
142- $ result = $ this ->getClient ()->execute ($ deleteRequest )->toObject ();
143-
144- $ this ->assertInstanceOf (ProductDiscount::class, $ result );
133+ $ this ->deleteRequest ->setVersion ($ result ->getVersion ());
145134 }
146135
147136 public function testSetDescription ()
@@ -164,11 +153,7 @@ public function testSetDescription()
164153 $ this ->assertSame ($ description ->en , $ result ->getDescription ()->en );
165154 $ this ->assertNotSame ($ productDiscount ->getVersion (), $ result ->getVersion ());
166155
167- $ deleteRequest = array_pop ($ this ->cleanupRequests );
168- $ deleteRequest ->setVersion ($ result ->getVersion ());
169- $ result = $ this ->getClient ()->execute ($ deleteRequest )->toObject ();
170-
171- $ this ->assertInstanceOf (ProductDiscount::class, $ result );
156+ $ this ->deleteRequest ->setVersion ($ result ->getVersion ());
172157 }
173158
174159 public function testChangeSortOrder ()
@@ -191,11 +176,7 @@ public function testChangeSortOrder()
191176 $ this ->assertSame ($ sortOrder , $ result ->getSortOrder ());
192177 $ this ->assertNotSame ($ productDiscount ->getVersion (), $ result ->getVersion ());
193178
194- $ deleteRequest = array_pop ($ this ->cleanupRequests );
195- $ deleteRequest ->setVersion ($ result ->getVersion ());
196- $ result = $ this ->getClient ()->execute ($ deleteRequest )->toObject ();
197-
198- $ this ->assertInstanceOf (ProductDiscount::class, $ result );
179+ $ this ->deleteRequest ->setVersion ($ result ->getVersion ());
199180 }
200181
201182 public function testChangeValue ()
@@ -226,10 +207,52 @@ public function testChangeValue()
226207 );
227208 $ this ->assertNotSame ($ productDiscount ->getVersion (), $ result ->getVersion ());
228209
229- $ deleteRequest = array_pop ($ this ->cleanupRequests );
230- $ deleteRequest ->setVersion ($ result ->getVersion ());
231- $ result = $ this ->getClient ()->execute ($ deleteRequest )->toObject ();
210+ $ this ->deleteRequest ->setVersion ($ result ->getVersion ());
211+ }
212+
213+ public function testSetValidFrom ()
214+ {
215+ $ draft = $ this ->getDraft ('set-valid-from ' );
216+ $ productDiscount = $ this ->createProductDiscount ($ draft );
217+
218+
219+ $ validFrom = new \DateTime ();
220+ $ request = ProductDiscountUpdateRequest::ofIdAndVersion (
221+ $ productDiscount ->getId (),
222+ $ productDiscount ->getVersion ()
223+ )
224+ ->addAction (ProductDiscountSetValidFromAction::of ()->setValidFrom ($ validFrom ))
225+ ;
226+ $ response = $ request ->executeWithClient ($ this ->getClient ());
227+ $ result = $ request ->mapResponse ($ response );
228+ $ this ->deleteRequest ->setVersion ($ result ->getVersion ());
229+
230+ $ this ->assertInstanceOf (ProductDiscount::class, $ result );
231+ $ validFrom ->setTimezone (new \DateTimeZone ('UTC ' ));
232+ $ this ->assertSame ($ validFrom ->format ('c ' ), $ result ->getValidFrom ()->format ('c ' ));
233+ $ this ->assertNotSame ($ productDiscount ->getVersion (), $ result ->getVersion ());
234+ }
235+
236+ public function testSetValidUntil ()
237+ {
238+ $ draft = $ this ->getDraft ('set-valid-from ' );
239+ $ productDiscount = $ this ->createProductDiscount ($ draft );
240+
241+
242+ $ validUntil = new \DateTime ();
243+ $ request = ProductDiscountUpdateRequest::ofIdAndVersion (
244+ $ productDiscount ->getId (),
245+ $ productDiscount ->getVersion ()
246+ )
247+ ->addAction (ProductDiscountSetValidUntilAction::of ()->setValidUntil ($ validUntil ))
248+ ;
249+ $ response = $ request ->executeWithClient ($ this ->getClient ());
250+ $ result = $ request ->mapResponse ($ response );
251+ $ this ->deleteRequest ->setVersion ($ result ->getVersion ());
232252
233253 $ this ->assertInstanceOf (ProductDiscount::class, $ result );
254+ $ validUntil ->setTimezone (new \DateTimeZone ('UTC ' ));
255+ $ this ->assertSame ($ validUntil ->format ('c ' ), $ result ->getValidUntil ()->format ('c ' ));
256+ $ this ->assertNotSame ($ productDiscount ->getVersion (), $ result ->getVersion ());
234257 }
235258}
0 commit comments