Skip to content

Commit 40bc316

Browse files
committed
Added tests for recently added features
1 parent abb5be4 commit 40bc316

22 files changed

+687
-1
lines changed

test-cases/includes/classes/AmazonFeedListTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,16 @@ public function testFetchFeedSubmissions(){
168168
$this->assertEquals('_MOCK_FEED_',$r[0]['FeedType']);
169169
$this->assertEquals('2012-12-12T12:12:12+00:00',$r[0]['SubmittedDate']);
170170
$this->assertEquals('_SUBMITTED_',$r[0]['FeedProcessingStatus']);
171+
$this->assertEquals('2012-12-15T12:12:12+00:00',$r[0]['StartedProcessingDate']);
172+
$this->assertEquals('2012-12-16T12:12:12+00:00',$r[0]['CompletedProcessingDate']);
171173

172174
$this->assertFalse($this->object->hasToken());
173175

174176
return $this->object;
175177
}
176178

177179
/**
180+
* @param AmazonFeedList $o
178181
* @depends testFetchFeedSubmissions
179182
*/
180183
public function testGetFeedInfo($o){
@@ -188,6 +191,8 @@ public function testGetFeedInfo($o){
188191
$this->assertArrayHasKey('FeedType',$info);
189192
$this->assertArrayHasKey('SubmittedDate',$info);
190193
$this->assertArrayHasKey('FeedProcessingStatus',$info);
194+
$this->assertArrayHasKey('StartedProcessingDate',$info);
195+
$this->assertArrayHasKey('CompletedProcessingDate',$info);
191196

192197
$id = $o->getFeedId();
193198
$type = $o->getFeedType();
@@ -199,17 +204,23 @@ public function testGetFeedInfo($o){
199204
$this->assertEquals($info['FeedType'],$type);
200205
$this->assertEquals($info['SubmittedDate'],$date);
201206
$this->assertEquals($info['FeedProcessingStatus'],$status);
207+
$this->assertEquals($info['StartedProcessingDate'], $o->getDateStarted());
208+
$this->assertEquals($info['CompletedProcessingDate'],$o->getDateCompleted());
202209

203210
$this->assertFalse($o->getFeedInfo(null));
204211
$this->assertFalse($o->getFeedId(null));
205212
$this->assertFalse($o->getFeedType(null));
206213
$this->assertFalse($o->getDateSubmitted(null));
207214
$this->assertFalse($o->getFeedStatus(null));
215+
$this->assertFalse($o->getDateStarted(null));
216+
$this->assertFalse($o->getDateCompleted(null));
208217
$this->assertFalse($o->getFeedInfo('string'));
209218
$this->assertFalse($o->getFeedId('string'));
210219
$this->assertFalse($o->getFeedType('string'));
211220
$this->assertFalse($o->getDateSubmitted('string'));
212221
$this->assertFalse($o->getFeedStatus('string'));
222+
$this->assertFalse($o->getDateStarted('string'));
223+
$this->assertFalse($o->getDateCompleted('string'));
213224

214225
$this->assertFalse($this->object->getFeedList()); //not fetched yet for this object
215226
}

test-cases/includes/classes/AmazonFulfillmentOrderCreatorTest.php

+180
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ protected function setUp() {
2626
protected function tearDown() {
2727

2828
}
29+
30+
public function testSetMarketplace() {
31+
$this->assertNull($this->object->setMarketplace('ATVPDKIKX0DER2'));
32+
$o = $this->object->getOptions();
33+
$this->assertArrayHasKey('MarketplaceId', $o);
34+
$this->assertEquals('ATVPDKIKX0DER2', $o['MarketplaceId']);
35+
$this->assertFalse($this->object->setMarketplace(77)); //won't work for numbers
36+
$this->assertFalse($this->object->setMarketplace(array())); //won't work for this
37+
$this->assertFalse($this->object->setMarketplace(null)); //won't work for other things
38+
}
2939

3040
public function testSetFulfillmentOrderId(){
3141
$this->assertFalse($this->object->setFulfillmentOrderId(null)); //can't be nothing
@@ -44,6 +54,20 @@ public function testSetDisplayableOrderId(){
4454
$this->assertArrayHasKey('DisplayableOrderId',$o);
4555
$this->assertEquals('ABC123',$o['DisplayableOrderId']);
4656
}
57+
58+
public function testSetFulfillmentAction() {
59+
$this->assertFalse($this->object->setFulfillmentAction(null)); //can't be nothing
60+
$this->assertFalse($this->object->setFulfillmentAction(5)); //can't be an int
61+
$this->assertFalse($this->object->setFulfillmentAction('wrong')); //not a valid value
62+
$this->assertNull($this->object->setFulfillmentAction('Ship'));
63+
$this->assertNull($this->object->setFulfillmentAction('Hold'));
64+
$o = $this->object->getOptions();
65+
$this->assertArrayHasKey('FulfillmentAction', $o);
66+
$this->assertEquals('Hold', $o['FulfillmentAction']);
67+
68+
$check = parseLog();
69+
$this->assertEquals('Tried to set fulfillment action to invalid value', $check[1]);
70+
}
4771

4872
public function testSetDate(){
4973
$this->assertFalse($this->object->setDate(null)); //can't be nothing
@@ -186,7 +210,96 @@ public function testSetEmails(){
186210
$o3 = $this->object->getOptions();
187211
$this->assertArrayNotHasKey('NotificationEmailList.member.1',$o3);
188212
}
213+
214+
public function testSetCodSettings() {
215+
$this->assertFalse($this->object->setCodSettings(null)); //can't be nothing
216+
217+
$this->assertNull($this->object->setCodSettings('USD', TRUE, '5', '6', '7', '8'));
218+
219+
$o = $this->object->getOptions();
220+
$this->assertArrayHasKey('CODSettings.IsCODRequired', $o);
221+
$this->assertEquals('true', $o['CODSettings.IsCODRequired']);
222+
$this->assertArrayHasKey('CODSettings.CODCharge.Value', $o);
223+
$this->assertEquals('5', $o['CODSettings.CODCharge.Value']);
224+
$this->assertArrayHasKey('CODSettings.CODCharge.CurrencyCode', $o);
225+
$this->assertEquals('USD', $o['CODSettings.CODCharge.CurrencyCode']);
226+
$this->assertArrayHasKey('CODSettings.CODChargeTax.Value', $o);
227+
$this->assertEquals('6', $o['CODSettings.CODChargeTax.Value']);
228+
$this->assertArrayHasKey('CODSettings.CODChargeTax.CurrencyCode', $o);
229+
$this->assertEquals('USD', $o['CODSettings.CODChargeTax.CurrencyCode']);
230+
$this->assertArrayHasKey('CODSettings.ShippingCharge.Value', $o);
231+
$this->assertEquals('7', $o['CODSettings.ShippingCharge.Value']);
232+
$this->assertArrayHasKey('CODSettings.ShippingCharge.CurrencyCode', $o);
233+
$this->assertEquals('USD', $o['CODSettings.ShippingCharge.CurrencyCode']);
234+
$this->assertArrayHasKey('CODSettings.ShippingChargeTax.Value', $o);
235+
$this->assertEquals('8', $o['CODSettings.ShippingChargeTax.Value']);
236+
$this->assertArrayHasKey('CODSettings.ShippingChargeTax.CurrencyCode', $o);
237+
$this->assertEquals('USD', $o['CODSettings.ShippingChargeTax.CurrencyCode']);
238+
239+
//using again does not cause reset
240+
$this->assertNull($this->object->setCodSettings('EUR', NULL, NULL, '5.60', '99', NULL));
241+
$o2 = $this->object->getOptions();
242+
$this->assertArrayHasKey('CODSettings.CODChargeTax.Value', $o2);
243+
$this->assertEquals('5.60', $o2['CODSettings.CODChargeTax.Value']);
244+
$this->assertArrayHasKey('CODSettings.CODChargeTax.CurrencyCode', $o2);
245+
$this->assertEquals('EUR', $o2['CODSettings.CODChargeTax.CurrencyCode']);
246+
$this->assertArrayHasKey('CODSettings.ShippingCharge.Value', $o2);
247+
$this->assertEquals('99', $o2['CODSettings.ShippingCharge.Value']);
248+
$this->assertArrayHasKey('CODSettings.ShippingCharge.CurrencyCode', $o2);
249+
$this->assertEquals('EUR', $o2['CODSettings.ShippingCharge.CurrencyCode']);
250+
//these are the same as before
251+
$this->assertArrayHasKey('CODSettings.CODCharge.Value', $o2);
252+
$this->assertEquals('5', $o2['CODSettings.CODCharge.Value']);
253+
$this->assertArrayHasKey('CODSettings.CODCharge.CurrencyCode', $o2);
254+
$this->assertEquals('USD', $o2['CODSettings.CODCharge.CurrencyCode']);
255+
$this->assertArrayHasKey('CODSettings.ShippingChargeTax.Value', $o2);
256+
$this->assertEquals('8', $o2['CODSettings.ShippingChargeTax.Value']);
257+
$this->assertArrayHasKey('CODSettings.ShippingChargeTax.CurrencyCode', $o2);
258+
$this->assertEquals('USD', $o2['CODSettings.ShippingChargeTax.CurrencyCode']);
259+
260+
$this->object->resetCodSettings();
261+
$o3 = $this->object->getOptions();
262+
$this->assertArrayNotHasKey('CODSettings.IsCODRequired', $o3);
263+
$this->assertArrayNotHasKey('CODSettings.CODCharge.Value', $o3);
264+
$this->assertArrayNotHasKey('CODSettings.CODCharge.CurrencyCode', $o3);
265+
$this->assertArrayNotHasKey('CODSettings.CODChargeTax.Value', $o3);
266+
$this->assertArrayNotHasKey('CODSettings.CODChargeTax.CurrencyCode', $o3);
267+
$this->assertArrayNotHasKey('CODSettings.ShippingCharge.Value', $o3);
268+
$this->assertArrayNotHasKey('CODSettings.ShippingCharge.CurrencyCode', $o3);
269+
$this->assertArrayNotHasKey('CODSettings.ShippingChargeTax.Value', $o3);
270+
$this->assertArrayNotHasKey('CODSettings.ShippingChargeTax.CurrencyCode', $o3);
271+
}
189272

273+
/**
274+
* @return array
275+
*/
276+
public function timeProvider() {
277+
return array(
278+
array(null, null, false), //nothing given, so no change
279+
array('', '', false), //strings, but empty
280+
array('-1 min', null, false), //one set
281+
array(null, '-1 min', false), //other set
282+
array('-1 min', '-1 min', true), //both set
283+
);
284+
}
285+
286+
/**
287+
* @dataProvider timeProvider
288+
*/
289+
public function testSetDeliveryWindow($a, $b, $c) {
290+
$this->object->setDeliveryWindow($a, $b);
291+
$o = $this->object->getOptions();
292+
if ($c) {
293+
$this->assertArrayHasKey('DeliveryWindow.StartDateTime', $o);
294+
$this->assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i', $o['DeliveryWindow.StartDateTime']);
295+
$this->assertArrayHasKey('DeliveryWindow.EndDateTime', $o);
296+
$this->assertStringMatchesFormat('%d-%d-%dT%d:%d:%d%i', $o['DeliveryWindow.EndDateTime']);
297+
} else {
298+
$this->assertArrayNotHasKey('DeliveryWindow.StartDateTime', $o);
299+
$this->assertArrayNotHasKey('DeliveryWindow.EndDateTime', $o);
300+
}
301+
}
302+
190303
public function testSetItems(){
191304
$this->assertFalse($this->object->setItems(null)); //can't be nothing
192305
$this->assertFalse($this->object->setItems('item')); //can't be a string
@@ -223,6 +336,10 @@ public function testSetItems(){
223336
$i[0]['OrderItemDisposition'] = 'OrderItemDisposition';
224337
$i[0]['PerUnitDeclaredValue']['CurrencyCode'] = 'USD';
225338
$i[0]['PerUnitDeclaredValue']['Value'] = '9.99';
339+
$i[0]['PerUnitPrice']['CurrencyCode'] = 'USD';
340+
$i[0]['PerUnitPrice']['Value'] = '20.01';
341+
$i[0]['PerUnitTax']['CurrencyCode'] = 'USD';
342+
$i[0]['PerUnitTax']['Value'] = '3.50';
226343
$i[1]['SellerSKU'] = 'SellerSKU2';
227344
$i[1]['SellerFulfillmentOrderItemId'] = 'SellerFulfillmentOrderItemId2';
228345
$i[1]['Quantity'] = 'Quantity2';
@@ -248,6 +365,14 @@ public function testSetItems(){
248365
$this->assertEquals('USD',$o['Items.member.1.PerUnitDeclaredValue.CurrencyCode']);
249366
$this->assertArrayHasKey('Items.member.1.PerUnitDeclaredValue.Value',$o);
250367
$this->assertEquals('9.99',$o['Items.member.1.PerUnitDeclaredValue.Value']);
368+
$this->assertArrayHasKey('Items.member.1.PerUnitPrice.CurrencyCode',$o);
369+
$this->assertEquals('USD',$o['Items.member.1.PerUnitPrice.CurrencyCode']);
370+
$this->assertArrayHasKey('Items.member.1.PerUnitPrice.Value',$o);
371+
$this->assertEquals('20.01',$o['Items.member.1.PerUnitPrice.Value']);
372+
$this->assertArrayHasKey('Items.member.1.PerUnitTax.CurrencyCode',$o);
373+
$this->assertEquals('USD',$o['Items.member.1.PerUnitTax.CurrencyCode']);
374+
$this->assertArrayHasKey('Items.member.1.PerUnitTax.Value',$o);
375+
$this->assertEquals('3.50',$o['Items.member.1.PerUnitTax.Value']);
251376
$this->assertArrayHasKey('Items.member.2.SellerSKU',$o);
252377
$this->assertEquals('SellerSKU2',$o['Items.member.2.SellerSKU']);
253378
$this->assertArrayHasKey('Items.member.2.SellerFulfillmentOrderItemId',$o);
@@ -334,6 +459,61 @@ public function testCreateOrder(){
334459
$this->assertEquals('Returning Mock Response: 200',$check[11]);
335460
$this->assertEquals('Successfully created Fulfillment Order 123ABC / ABC123',$check[12]);
336461
}
462+
463+
public function testUpdateOrder() {
464+
resetLog();
465+
$this->object->setMock(true, array(503, 200));
466+
467+
$this->assertFalse($this->object->updateOrder()); //no Seller Fulfillment Order ID set yet
468+
469+
$this->object->setFulfillmentOrderId('123ABC');
470+
$this->assertFalse($this->object->updateOrder()); //no Displayable Order ID set yet
471+
472+
$this->object->setDisplayableOrderId('ABC123');
473+
$this->assertFalse($this->object->updateOrder()); //no Date set yet
474+
475+
$this->object->setDate('-1 min');
476+
$this->assertFalse($this->object->updateOrder()); //no Displayable Order Comment set yet
477+
478+
$this->object->setComment('A comment.');
479+
$this->assertFalse($this->object->updateOrder()); //no Shipping Speed Category set yet
480+
481+
$this->object->setShippingSpeed('Standard');
482+
$this->assertFalse($this->object->updateOrder()); //no Destination Address set yet
483+
484+
$a = array();
485+
$a['Name'] = 'Name';
486+
$a['Line1'] = 'Line1';
487+
$a['City'] = 'City';
488+
$a['StateOrProvinceCode'] = 'StateOrProvinceCode';
489+
$a['CountryCode'] = 'CountryCode';
490+
$a['PostalCode'] = 'PostalCode';
491+
$this->object->setAddress($a);
492+
$this->assertFalse($this->object->updateOrder()); //no Items set yet
493+
494+
$i = array();
495+
$i[0]['SellerSKU'] = 'NewSellerSKU';
496+
$i[0]['SellerFulfillmentOrderItemId'] = 'NewSellerFulfillmentOrderItemId';
497+
$i[0]['Quantity'] = 'NewQuantity';
498+
$this->object->setItems($i);
499+
500+
$this->object->updateOrder(); //attempt 1: oops, bad response
501+
$this->object->updateOrder(); //attempt 2: success
502+
503+
$check = parseLog();
504+
$this->assertEquals('Mock files array set.', $check[1]);
505+
$this->assertEquals('Seller Fulfillment OrderID must be set in order to update an order', $check[2]);
506+
$this->assertEquals('Displayable Order ID must be set in order to update an order', $check[3]);
507+
$this->assertEquals('Date must be set in order to update an order', $check[4]);
508+
$this->assertEquals('Comment must be set in order to update an order', $check[5]);
509+
$this->assertEquals('Shipping Speed must be set in order to update an order', $check[6]);
510+
$this->assertEquals('Address must be set in order to update an order', $check[7]);
511+
$this->assertEquals('Items must be set in order to update an order', $check[8]);
512+
$this->assertEquals('Returning Mock Response: 503', $check[9]);
513+
$this->assertEquals('Bad Response! 503 Service Unavailable: Service Unavailable - Service Unavailable', $check[10]);
514+
$this->assertEquals('Returning Mock Response: 200', $check[11]);
515+
$this->assertEquals('Successfully updated Fulfillment Order 123ABC / ABC123', $check[12]);
516+
}
337517

338518
}
339519

test-cases/includes/classes/AmazonFulfillmentOrderTest.php

+16
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public function testGetOrder($o){
9191
$xd['DisplayableOrderDateTime'] = '2006-08-02T17:26:56Z';
9292
$xd['DisplayableOrderComment'] = 'Sample comment.';
9393
$xd['ShippingSpeedCategory'] = 'Standard';
94+
$xd['DeliveryWindow']['StartDateTime'] = '2008-03-11T08:07:53Z';
95+
$xd['DeliveryWindow']['EndDateTime'] = '2008-03-12T08:07:53Z';
9496
$xd['DestinationAddress']['Name'] = 'Greg Miller';
9597
$xd['DestinationAddress']['Line1'] = '123 Some St.';
9698
$xd['DestinationAddress']['Line2'] = 'Apt. 321';
@@ -102,11 +104,21 @@ public function testGetOrder($o){
102104
$xd['DestinationAddress']['PostalCode'] = '98101';
103105
$xd['DestinationAddress']['PhoneNumber'] = '206-555-1928';
104106
$xd['FulfillmentPolicy'] = 'FillOrKill';
107+
$xd['FulfillmentAction'] = 'Ship';
105108
$xd['FulfillmentMethod'] = 'Consumer';
106109
$xd['ReceivedDateTime'] = '2006-08-02T17:26:56Z';
107110
$xd['FulfillmentOrderStatus'] = 'PROCESSING';
108111
$xd['StatusUpdatedDateTime'] = '2006-09-28T23:48:48Z';
109112
$xd['NotificationEmailList'][0] = 'o8c2EXAMPLsfr7o@marketplace.amazon.com';
113+
$xd['CODSettings']['IsCODRequired'] = 'false';
114+
$xd['CODSettings']['CODCharge']['Value'] = '5.00';
115+
$xd['CODSettings']['CODCharge']['CurrencyCode'] = 'USD';
116+
$xd['CODSettings']['CODChargeTax']['Value'] = '1.00';
117+
$xd['CODSettings']['CODChargeTax']['CurrencyCode'] = 'USD';
118+
$xd['CODSettings']['ShippingCharge']['Value'] = '2.50';
119+
$xd['CODSettings']['ShippingCharge']['CurrencyCode'] = 'USD';
120+
$xd['CODSettings']['ShippingChargeTax']['Value'] = '0.50';
121+
$xd['CODSettings']['ShippingChargeTax']['CurrencyCode'] = 'USD';
110122

111123
$x['Details'] = $xd;
112124

@@ -134,6 +146,10 @@ public function testGetOrder($o){
134146
$xi[1]['EstimatedArrivalDateTime'] = '2008-03-09T08:07:53Z';
135147
$xi[0]['PerUnitDeclaredValue']['CurrencyCode'] = 'USD';
136148
$xi[0]['PerUnitDeclaredValue']['Value'] = '999.99';
149+
$xi[0]['PerUnitPrice']['CurrencyCode'] = 'USD';
150+
$xi[0]['PerUnitPrice']['Value'] = '30.99';
151+
$xi[0]['PerUnitTax']['CurrencyCode'] = 'USD';
152+
$xi[0]['PerUnitTax']['Value'] = '5.99';
137153

138154
$x['Items'] = $xi;
139155

test-cases/includes/classes/AmazonOrderItemListTest.php

+55
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ public function testFetchItemsBreak(){
8282
$this->assertEquals('You just got throttled.',$check[3]);
8383
$this->assertEquals('You grabbed the wrong Order\'s items! - 77 =/= 058-1233752-8214740',$check[5]);
8484
}
85+
86+
/**
87+
* @depends testFetchItems
88+
* @param AmazonOrderItemList $o
89+
*/
90+
public function testOrderId($o) {
91+
$this->assertEquals('058-1233752-8214740', $o->getOrderId());
92+
93+
$this->assertFalse($this->object->getOrderId()); //not fetched yet for this object
94+
}
8595

8696
/**
8797
* @depends testFetchItems
@@ -98,6 +108,11 @@ public function testGetItems($o){
98108
$x1['Title'] = 'Example item name';
99109
$x1['QuantityOrdered'] = '1';
100110
$x1['QuantityShipped'] = '1';
111+
$x1['BuyerCustomizedInfo'] = 'http://www.amazon.com';
112+
$x1['PointsGranted']['PointsNumber'] = '5';
113+
$x1['PointsGranted']['Amount'] = '2.50';
114+
$x1['PointsGranted']['CurrencyCode'] = 'USD';
115+
$x1['PriceDesignation'] = 'BusinessPrice';
101116
$x1['GiftMessageText'] = 'For you!';
102117
$x1['GiftWrapLevel'] = 'Classic';
103118
$x1['ItemPrice']['Amount'] = '25.99';
@@ -200,6 +215,46 @@ public function testGetQuantityShipped($o){
200215
$this->assertFalse($o->getQuantityShipped('wrong')); //not number
201216
$this->assertFalse($this->object->getQuantityShipped()); //not fetched yet for this object
202217
}
218+
219+
/**
220+
* @depends testFetchItems
221+
* @param AmazonOrderItemList $o
222+
*/
223+
public function testGetCustomizedInfo($o) {
224+
$this->assertEquals('http://www.amazon.com', $o->getCustomizedInfo(0));
225+
$this->assertEquals($o->getCustomizedInfo(0), $o->getCustomizedInfo());
226+
227+
$this->assertFalse($o->getCustomizedInfo('wrong')); //not number
228+
$this->assertFalse($this->object->getCustomizedInfo()); //not fetched yet for this object
229+
}
230+
231+
/**
232+
* @depends testFetchItems
233+
* @param AmazonOrderItemList $o
234+
*/
235+
public function testGetPointsGranted($o) {
236+
$x = array();
237+
$x['PointsNumber'] = '5';
238+
$x['Amount'] = '2.50';
239+
$x['CurrencyCode'] = 'USD';
240+
$this->assertEquals($x, $o->getPointsGranted(0));
241+
$this->assertEquals($o->getPointsGranted(0), $o->getPointsGranted());
242+
243+
$this->assertFalse($o->getPointsGranted('wrong')); //not number
244+
$this->assertFalse($this->object->getPointsGranted()); //not fetched yet for this object
245+
}
246+
247+
/**
248+
* @depends testFetchItems
249+
* @param AmazonOrderItemList $o
250+
*/
251+
public function testGetPriceDesignation($o) {
252+
$this->assertEquals('BusinessPrice', $o->getPriceDesignation(0));
253+
$this->assertEquals($o->getPriceDesignation(0), $o->getPriceDesignation());
254+
255+
$this->assertFalse($o->getPriceDesignation('wrong')); //not number
256+
$this->assertFalse($this->object->getPriceDesignation()); //not fetched yet for this object
257+
}
203258

204259
/**
205260
* @depends testFetchItems

0 commit comments

Comments
 (0)