Skip to content

Commit

Permalink
Merge pull request #87 from Peardian/newtests
Browse files Browse the repository at this point in the history
New tests and Bug fixes
  • Loading branch information
Peardian authored Jul 5, 2016
2 parents ec1ceaa + e0a92c0 commit 6ac892f
Show file tree
Hide file tree
Showing 29 changed files with 684 additions and 52 deletions.
5 changes: 1 addition & 4 deletions includes/classes/AmazonCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,7 @@ protected function sleep(){
* @return boolean <b>FALSE</b> if no XML data
*/
protected function checkToken($xml){
if (!$xml){
return false;
}
if ($xml->NextToken && (string)$xml->HasNext != 'false' && (string)$xml->MoreResultsAvailable != 'false'){
if ($xml && $xml->NextToken && (string)$xml->HasNext != 'false' && (string)$xml->MoreResultsAvailable != 'false'){
$this->tokenFlag = true;
$this->options['NextToken'] = (string)$xml->NextToken;
} else {
Expand Down
12 changes: 8 additions & 4 deletions includes/classes/AmazonFulfillmentOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,20 @@ protected function parseXML($xml) {
$this->order['Details']['CODSettings']['IsCODRequired'] = (string)$d->CODSettings->IsCODRequired;
}
if (isset($d->CODSettings->CODCharge)){
$this->order['Details']['CODSettings']['CODCharge'] = (string)$d->CODSettings->CODCharge;
$this->order['Details']['CODSettings']['CODCharge']['CurrencyCode'] = (string)$d->CODSettings->CODCharge->CurrencyCode;
$this->order['Details']['CODSettings']['CODCharge']['Value'] = (string)$d->CODSettings->CODCharge->Value;
}
if (isset($d->CODSettings->CODChargeTax)){
$this->order['Details']['CODSettings']['CODChargeTax'] = (string)$d->CODSettings->CODChargeTax;
$this->order['Details']['CODSettings']['CODChargeTax']['CurrencyCode'] = (string)$d->CODSettings->CODChargeTax->CurrencyCode;
$this->order['Details']['CODSettings']['CODChargeTax']['Value'] = (string)$d->CODSettings->CODChargeTax->Value;
}
if (isset($d->CODSettings->ShippingCharge)){
$this->order['Details']['CODSettings']['ShippingCharge'] = (string)$d->CODSettings->ShippingCharge;
$this->order['Details']['CODSettings']['ShippingCharge']['CurrencyCode'] = (string)$d->CODSettings->ShippingCharge->CurrencyCode;
$this->order['Details']['CODSettings']['ShippingCharge']['Value'] = (string)$d->CODSettings->ShippingCharge->Value;
}
if (isset($d->CODSettings->ShippingChargeTax)){
$this->order['Details']['CODSettings']['ShippingChargeTax'] = (string)$d->CODSettings->ShippingChargeTax;
$this->order['Details']['CODSettings']['ShippingChargeTax']['CurrencyCode'] = (string)$d->CODSettings->ShippingChargeTax->CurrencyCode;
$this->order['Details']['CODSettings']['ShippingChargeTax']['Value'] = (string)$d->CODSettings->ShippingChargeTax->Value;
}

//Section 2: Order Items
Expand Down
42 changes: 10 additions & 32 deletions includes/classes/AmazonFulfillmentOrderCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public function setCodSettings($cu, $r = null, $c = null, $ct = null, $s = null,
return false;
}
if (isset($r)) {
if (filter_var($s, FILTER_VALIDATE_BOOLEAN)) {
if (filter_var($r, FILTER_VALIDATE_BOOLEAN)) {
$r = 'true';
} else {
$r = 'false';
Expand Down Expand Up @@ -364,9 +364,13 @@ public function resetCodSettings(){
* The parameters are passed through <i>strtotime</i>, so values such as "-1 hour" are fine.
* @param string $s <p>A time string for the earliest time.</p>
* @param string $e <p>A time string for the latest time.</p>
* @return boolean <b>FALSE</b> if improper input
* @see genTime
*/
public function setDeliveryWindow($s, $e){
if (empty($s) || empty($e)) {
return false;
}
$times = $this->genTime($s);
$this->options['DeliveryWindow.StartDateTime'] = $times;
$timee = $this->genTime($e);
Expand Down Expand Up @@ -480,7 +484,7 @@ protected function resetItems(){
*/
public function createOrder(){
if (!array_key_exists('SellerFulfillmentOrderId',$this->options)){
$this->log("Seller Fulfillment OrderID must be set in order to create an order",'Warning');
$this->log("Seller Fulfillment Order ID must be set in order to create an order",'Warning');
return false;
}
if (!array_key_exists('DisplayableOrderId',$this->options)){
Expand Down Expand Up @@ -531,39 +535,13 @@ public function createOrder(){
* Updates a Fulfillment Order with Amazon.
*
* Submits an <i>UpdateFulfillmentOrder</i> request to Amazon. In order to do this,
* a number of parameters are required. Amazon will send back an HTTP response,
* so there is no data to retrieve afterwards. The following parameters are required:
* fulfillment order ID, displayed order ID, displayed timestamp, comment,
* shipping speed, address, and items.
* a fulfillment order ID is required. Amazon will send back an HTTP response,
* so there is no data to retrieve afterwards.
* @return boolean <b>TRUE</b> if the order creation was successful, <b>FALSE</b> if something goes wrong
*/
public function updateOrder(){
if (!array_key_exists('SellerFulfillmentOrderId',$this->options)){
$this->log("Seller Fulfillment OrderID must be set in order to create an order",'Warning');
return false;
}
if (!array_key_exists('DisplayableOrderId',$this->options)){
$this->log("Displayable Order ID must be set in order to create an order",'Warning');
return false;
}
if (!array_key_exists('DisplayableOrderDateTime',$this->options)){
$this->log("Date must be set in order to create an order",'Warning');
return false;
}
if (!array_key_exists('DisplayableOrderComment',$this->options)){
$this->log("Comment must be set in order to create an order",'Warning');
return false;
}
if (!array_key_exists('ShippingSpeedCategory',$this->options)){
$this->log("Shipping Speed must be set in order to create an order",'Warning');
return false;
}
if (!array_key_exists('DestinationAddress.Name',$this->options)){
$this->log("Address must be set in order to create an order",'Warning');
return false;
}
if (!array_key_exists('Items.member.1.SellerSKU',$this->options)){
$this->log("Items must be set in order to create an order",'Warning');
$this->log("Seller Fulfillment Order ID must be set in order to update an order",'Warning');
return false;
}

Expand All @@ -581,7 +559,7 @@ public function updateOrder(){
if (!$this->checkResponse($response)){
return false;
} else {
$this->log("Successfully created Fulfillment Order ".$this->options['SellerFulfillmentOrderId']." / ".$this->options['DisplayableOrderId']);
$this->log("Successfully updated Fulfillment Order ".$this->options['SellerFulfillmentOrderId']);
return true;
}
}
Expand Down
14 changes: 9 additions & 5 deletions includes/classes/AmazonFulfillmentOrderList.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ protected function parseXML($xml){
}
if (isset($x->FulfillmentMethod)){
//deprecated
$this->orderList[$i]['FulfillmentPolicy'] = (string)$x->FulfillmentMethod;
$this->orderList[$i]['FulfillmentMethod'] = (string)$x->FulfillmentMethod;
}
$this->orderList[$i]['ReceivedDateTime'] = (string)$x->ReceivedDateTime;
$this->orderList[$i]['FulfillmentOrderStatus'] = (string)$x->FulfillmentOrderStatus;
Expand All @@ -239,16 +239,20 @@ protected function parseXML($xml){
$this->orderList[$i]['CODSettings']['IsCODRequired'] = (string)$x->CODSettings->IsCODRequired;
}
if (isset($x->CODSettings->CODCharge)){
$this->orderList[$i]['CODSettings']['CODCharge'] = (string)$x->CODSettings->CODCharge;
$this->orderList[$i]['CODSettings']['CODCharge']['CurrencyCode'] = (string)$x->CODSettings->CODCharge->CurrencyCode;
$this->orderList[$i]['CODSettings']['CODCharge']['Value'] = (string)$x->CODSettings->CODCharge->Value;
}
if (isset($x->CODSettings->CODChargeTax)){
$this->orderList[$i]['CODSettings']['CODChargeTax'] = (string)$x->CODSettings->CODChargeTax;
$this->orderList[$i]['CODSettings']['CODChargeTax']['CurrencyCode'] = (string)$x->CODSettings->CODChargeTax->CurrencyCode;
$this->orderList[$i]['CODSettings']['CODChargeTax']['Value'] = (string)$x->CODSettings->CODChargeTax->Value;
}
if (isset($x->CODSettings->ShippingCharge)){
$this->orderList[$i]['CODSettings']['ShippingCharge'] = (string)$x->CODSettings->ShippingCharge;
$this->orderList[$i]['CODSettings']['ShippingCharge']['CurrencyCode'] = (string)$x->CODSettings->ShippingCharge->CurrencyCode;
$this->orderList[$i]['CODSettings']['ShippingCharge']['Value'] = (string)$x->CODSettings->ShippingCharge->Value;
}
if (isset($x->CODSettings->ShippingChargeTax)){
$this->orderList[$i]['CODSettings']['ShippingChargeTax'] = (string)$x->CODSettings->ShippingChargeTax;
$this->orderList[$i]['CODSettings']['ShippingChargeTax']['CurrencyCode'] = (string)$x->CODSettings->ShippingChargeTax->CurrencyCode;
$this->orderList[$i]['CODSettings']['ShippingChargeTax']['Value'] = (string)$x->CODSettings->ShippingChargeTax->Value;
}
$this->index++;
}
Expand Down
4 changes: 2 additions & 2 deletions includes/classes/AmazonInventoryList.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function setUseToken($b = true){
* were updated after the given time.
* If this parameters is set, seller SKUs cannot be set.
* The parameter is passed through <i>strtotime</i>, so values such as "-1 hour" are fine.
* @param string $s <p>Time string.</p>
* @param string $t <p>Time string.</p>
* @return boolean <b>FALSE</b> if improper input
*/
public function setStartTime($t = null){
Expand All @@ -101,7 +101,7 @@ public function setStartTime($t = null){
* This method sets the list of seller SKUs to be sent in the next request.
* Setting this parameter tells Amazon to only return inventory supplies that match
* the IDs in the list. If this parameter is set, Start Time cannot be set.
* @param array|string $s <p>A list of Seller SKUs, or a single ID string.</p>
* @param array|string $a <p>A list of Seller SKUs, or a single ID string.</p>
* @return boolean <b>FALSE</b> if improper input
*/
public function setSellerSkus($a){
Expand Down
4 changes: 2 additions & 2 deletions includes/classes/AmazonOrderList.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,11 @@ public function setMaxResultsPerPage($num){
public function setTfmShipmentStatusFilter($list){
if (is_string($list)){
//if single string, set as filter
$this->resetOrderStatusFilter();
$this->resetTfmShipmentStatusFilter();
$this->options['TFMShipmentStatus.Status.1'] = $list;
} else if (is_array($list)){
//if array of strings, set all filters
$this->resetOrderStatusFilter();
$this->resetTfmShipmentStatusFilter();
$i = 1;
foreach($list as $x){
$this->options['TFMShipmentStatus.Status.'.$i] = $x;
Expand Down
2 changes: 1 addition & 1 deletion includes/classes/AmazonShipmentItemList.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function parseXML($xml){
$a['QuantityInCase'] = (string)$x->QuantityInCase;
}
if (isset($x->PrepDetailsList)) {
foreach ($x->PrepDetailsList as $z) {
foreach ($x->PrepDetailsList->children() as $z) {
$temp = array();
$temp['PrepInstruction'] = (string)$z->PrepInstruction;
$temp['PrepOwner'] = (string)$z->PrepOwner;
Expand Down
11 changes: 11 additions & 0 deletions test-cases/includes/classes/AmazonFeedListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,16 @@ public function testFetchFeedSubmissions(){
$this->assertEquals('_MOCK_FEED_',$r[0]['FeedType']);
$this->assertEquals('2012-12-12T12:12:12+00:00',$r[0]['SubmittedDate']);
$this->assertEquals('_SUBMITTED_',$r[0]['FeedProcessingStatus']);
$this->assertEquals('2012-12-15T12:12:12+00:00',$r[0]['StartedProcessingDate']);
$this->assertEquals('2012-12-16T12:12:12+00:00',$r[0]['CompletedProcessingDate']);

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

return $this->object;
}

/**
* @param AmazonFeedList $o
* @depends testFetchFeedSubmissions
*/
public function testGetFeedInfo($o){
Expand All @@ -188,6 +191,8 @@ public function testGetFeedInfo($o){
$this->assertArrayHasKey('FeedType',$info);
$this->assertArrayHasKey('SubmittedDate',$info);
$this->assertArrayHasKey('FeedProcessingStatus',$info);
$this->assertArrayHasKey('StartedProcessingDate',$info);
$this->assertArrayHasKey('CompletedProcessingDate',$info);

$id = $o->getFeedId();
$type = $o->getFeedType();
Expand All @@ -199,17 +204,23 @@ public function testGetFeedInfo($o){
$this->assertEquals($info['FeedType'],$type);
$this->assertEquals($info['SubmittedDate'],$date);
$this->assertEquals($info['FeedProcessingStatus'],$status);
$this->assertEquals($info['StartedProcessingDate'], $o->getDateStarted());
$this->assertEquals($info['CompletedProcessingDate'],$o->getDateCompleted());

$this->assertFalse($o->getFeedInfo(null));
$this->assertFalse($o->getFeedId(null));
$this->assertFalse($o->getFeedType(null));
$this->assertFalse($o->getDateSubmitted(null));
$this->assertFalse($o->getFeedStatus(null));
$this->assertFalse($o->getDateStarted(null));
$this->assertFalse($o->getDateCompleted(null));
$this->assertFalse($o->getFeedInfo('string'));
$this->assertFalse($o->getFeedId('string'));
$this->assertFalse($o->getFeedType('string'));
$this->assertFalse($o->getDateSubmitted('string'));
$this->assertFalse($o->getFeedStatus('string'));
$this->assertFalse($o->getDateStarted('string'));
$this->assertFalse($o->getDateCompleted('string'));

$this->assertFalse($this->object->getFeedList()); //not fetched yet for this object
}
Expand Down
Loading

0 comments on commit 6ac892f

Please sign in to comment.