Skip to content

Commit

Permalink
Merge pull request #17 from CPIGroup/master
Browse files Browse the repository at this point in the history
Feed fixes
  • Loading branch information
carl689 committed Mar 11, 2014
2 parents d7767ec + c65cf46 commit 09be5f8
Show file tree
Hide file tree
Showing 35 changed files with 64 additions and 97 deletions.
3 changes: 3 additions & 0 deletions includes/classes/AmazonCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ function fetchURL ($url, $param) {
return $return;
}

if (is_numeric(strpos($data, 'HTTP/1.1 100 Continue'))) {
$data=str_replace('HTTP/1.1 100 Continue', '', $data);
}
$data = preg_split("/\r\n\r\n/",$data, 2, PREG_SPLIT_NO_EMPTY);
if (!empty($data)) {
$return['head'] = ( isset($data[0]) ? $data[0] : null );
Expand Down
55 changes: 16 additions & 39 deletions includes/classes/AmazonFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Submits feeds to Amazon.
*
* This Amazon Feeds Core object can submit feeds to Amazon.
* In order to submit a feed, the feed's contents (a filename)
* In order to submit a feed, the feed's contents (as direct input or from a file)
* and feed type must be set. Once the feed has been submitted,
* the response from Amazon can be viewed with <i>getResponse</i>.
*/
Expand Down Expand Up @@ -59,28 +59,18 @@ public function __construct($s, $mock = false, $m = null, $config = null){
}

/**
* Sets the feed content. (Required*)
* Sets the Feed Content. (Required)
*
* This method creates a temporary file using the data you provide. It is
* recommended that you use <i>loadFeedFile</i> instead, as there is a good
* chance the data you provide here will be overwritten later.
* Thie method sets the feed's contents from direct input.
* This parameter is required in order to submit a feed to Amazon.
* @param string $s <p>The contents to put in the file.</p>
* @param string $override [optional] <p>The path to a file you want to write to.
* It can be relative or absolute.</p>
* @return boolean <b>FALSE</b> if improper input
*/
public function setFeedContent($s, $override = null){
public function setFeedContent($s){
if (is_string($s) && $s){
if ($override && file_exists($override) && is_writable($override)){
if (strpos($override, '/') === 0){
file_put_contents($override, $s);
} else {
file_put_contents('../../'.$override, $s);
}
$this->loadFeedFile($override);
} else {
file_put_contents('../../temp.xml', $s);
$this->loadFeedFile('temp.xml');
}
$this->feedContent=$s;
$this->feedMD5 = base64_encode(md5($this->feedContent,true));
} else {
return false;
}
Expand All @@ -89,20 +79,20 @@ public function setFeedContent($s, $override = null){
/**
* Sets the Feed Content. (Required)
*
* This method sets the file path to be sent in the next request. This
* This method loads the contents of a file to send as the feed. This
* parameter is required in order to submit a feed to Amazon.
* @param string $url <p>The path to a file you want to use.
* It can be relative or absolute.</p>
*/
public function loadFeedFile($path){
if (file_exists($path)){
if (strpos($path, '/') == 0){
$this->feedContent = $path;
$this->feedContent = file_get_contents($path);
} else {
$url = '/var/www/athena/plugins/newAmazon/'.$path; //todo: change to current install dir
$this->feedContent = $url;
$url = __DIR__.'/../../'.$path; //todo: change to current install dir
$this->feedContent = file_get_contents($url);
}
$this->feedMD5 = base64_encode(md5(file_get_contents($this->feedContent),true));
$this->feedMD5 = base64_encode(md5($this->feedContent,true));
}
}

Expand Down Expand Up @@ -263,19 +253,17 @@ public function submitFeed(){
$xml = $this->fetchMockFile()->$path;
} else {
$headers = $this->genHeader();
$post = $this->genPost();
$response = $this->sendRequest("$url?$query",array('Header'=>$headers,'Post'=>$post));
$response = $this->sendRequest("$url?$query",array('Header'=>$headers,'Post'=>$this->feedContent));

if (!$this->checkResponse($response)){
return false;
}

//getting Response 100?
if ($response['head'] == 'HTTP/1.1 100 Continue'){
if (isset($response['code']) && $response['code'] == '200'){
$body = strstr($response['body'],'<');
$xml = simplexml_load_string($body)->$path;
} else {
$this->log("Unexpected response: ".$response['code'],'Warning');
$this->log("Unexpected response: ".print_r($response,true),'Warning');
$xml = simplexml_load_string($response['body'])->$path;
}

Expand Down Expand Up @@ -318,17 +306,6 @@ protected function genHeader(){
return $return;
}

/**
* Generates array for Post.
*
* This method creates the Post array to use with cURL. It contains the Feed Content file path.
* @return array
*/
protected function genPost(){
$return['file'] = '@'.$this->feedContent;
return $return;
}

/**
* Checks whether or not the response is OK.
*
Expand Down
Empty file removed temp.xml
Empty file.
2 changes: 1 addition & 1 deletion test-cases/includes/classes/AmazonCoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonCoreTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonServiceStatus('testStore', 'Inbound', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonServiceStatus('testStore', 'Inbound', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test-cases/includes/classes/AmazonFeedListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonFeedListTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonFeedList('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonFeedList('testStore', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions test-cases/includes/classes/AmazonFeedResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonFeedResultTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonFeedResult('testStore', null, true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonFeedResult('testStore', null, true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down Expand Up @@ -66,9 +66,9 @@ public function testFetchFeedResult(){
public function testSaveFeed($o){
resetLog();
$this->assertFalse($this->object->saveFeed('mock/saveFeed.xml')); //nothing yet
$o->saveFeed('/var/www/athena/plugins/amazon/newAmazon/test-cases/mock/saveFeed.xml');
$o->saveFeed(__DIR__.'/../../mock/saveFeed.xml');
$check = parseLog();
$this->assertEquals('Successfully saved feed #77 at /var/www/athena/plugins/amazon/newAmazon/test-cases/mock/saveFeed.xml',$check[0]);
$this->assertEquals('Successfully saved feed #77 at '.__DIR__.'/../../mock/saveFeed.xml',$check[0]);
}

}
Expand Down
16 changes: 2 additions & 14 deletions test-cases/includes/classes/AmazonFeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonFeedTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonFeed('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonFeed('testStore', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand All @@ -27,18 +27,6 @@ protected function tearDown() {

}

/**
*
*/
public function testSetFeedContent() {
$ok = $this->object->setFeedContent('yes','/var/www/athena/plugins/amazon/newAmazon/test-cases/test-temp.xml');
$this->assertNull($ok);
$this->assertFileExists('/var/www/athena/plugins/amazon/newAmazon/test-cases/test-temp.xml');
$check = file_get_contents('/var/www/athena/plugins/amazon/newAmazon/test-cases/test-temp.xml');
$this->assertEquals('yes',$check);
$this->assertFalse($this->object->setFeedContent(null));
}

public function testSetFeedType(){
$ok = $this->object->setFeedType('string');
$this->assertNull($ok);
Expand Down Expand Up @@ -105,7 +93,7 @@ public function testSubmitFeed(){
$this->assertFalse($this->object->submitFeed()); //nothing set yet
$this->assertFalse($this->object->getResponse()); //no response yet either

$this->object->setFeedContent('yes','/var/www/athena/plugins/amazon/newAmazon/test-cases/test-temp.xml');
$this->object->setFeedContent('yes');
$this->assertFalse($this->object->submitFeed()); //no feed type set yet

$this->object->setFeedType('_MOCK_FEED_');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonFulfillmentOrderCreatorTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonFulfillmentOrderCreator('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonFulfillmentOrderCreator('testStore', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonFulfillmentOrderListTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonFulfillmentOrderList('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonFulfillmentOrderList('testStore', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test-cases/includes/classes/AmazonFulfillmentOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonFulfillmentOrderTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonFulfillmentOrder('testStore', null, true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonFulfillmentOrder('testStore', null, true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonFulfillmentPreviewTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonFulfillmentPreview('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonFulfillmentPreview('testStore', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test-cases/includes/classes/AmazonInventoryListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonInventoryListTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonInventoryList('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonInventoryList('testStore', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test-cases/includes/classes/AmazonOrderItemListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonOrderItemListTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonOrderItemList('testStore', null, true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonOrderItemList('testStore', null, true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test-cases/includes/classes/AmazonOrderListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonOrderListTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonOrderList('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonOrderList('testStore', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down Expand Up @@ -292,7 +292,7 @@ public function testFetchItems(){
$getOne = $this->object->fetchItems('string', 0); //$token will be set to false
$this->assertInternalType('object',$getOne);

$o = new AmazonOrderList('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$o = new AmazonOrderList('testStore', true, null, __DIR__.'/../../test-config.php');
$this->assertFalse($o->fetchItems()); //not fetched yet for this object
}
/**
Expand Down
4 changes: 2 additions & 2 deletions test-cases/includes/classes/AmazonOrderSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonOrderSetTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonOrderSet('testStore', null, true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonOrderSet('testStore', null, true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down Expand Up @@ -101,7 +101,7 @@ public function testFetchItems(){
$getOne = $this->object->fetchItems('string', 0); //$token will be set to false
$this->assertInternalType('object',$getOne);

$o = new AmazonOrderList('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$o = new AmazonOrderList('testStore', true, null, __DIR__.'/../../test-config.php');
$this->assertFalse($o->fetchItems()); //not fetched yet for this object
}

Expand Down
4 changes: 2 additions & 2 deletions test-cases/includes/classes/AmazonOrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonOrderTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonOrder('testStore', null, null, true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonOrder('testStore', null, null, true, null, __DIR__.'/../../test-config.php');
}

/**
Expand All @@ -34,7 +34,7 @@ public function testSetUp(){
$this->assertArrayHasKey('AmazonOrderId.Id.1',$o);
$this->assertEquals('77', $o['AmazonOrderId.Id.1']);

$data = simplexml_load_file('/var/www/athena/plugins/amazon/newAmazon/test-cases/mock/fetchOrder.xml');
$data = simplexml_load_file(__DIR__.'/../../mock/fetchOrder.xml');
$obj2 = new AmazonOrder('testStore', null, $data->GetOrderResult->Orders->Order);

$get = $obj2->getAmazonOrderId();
Expand Down
2 changes: 1 addition & 1 deletion test-cases/includes/classes/AmazonPackageTrackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonPackageTrackerTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonPackageTracker('testStore', null, true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonPackageTracker('testStore', null, true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonParticipationListTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonParticipationList('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonParticipationList('testStore', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test-cases/includes/classes/AmazonProductInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonProductInfoTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonProductInfo('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonProductInfo('testStore', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test-cases/includes/classes/AmazonProductListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonProductListTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonProductList('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonProductList('testStore', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test-cases/includes/classes/AmazonProductSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonProductSearchTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonProductSearch('testStore', null, true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonProductSearch('testStore', null, true, null, __DIR__.'/../../test-config.php');
}

/**
Expand All @@ -28,7 +28,7 @@ protected function tearDown() {
}

public function testSetUp(){
$obj = new AmazonProductSearch('testStore', 'platinum', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$obj = new AmazonProductSearch('testStore', 'platinum', true, null, __DIR__.'/../../test-config.php');

$o = $obj->getOptions();
$this->assertArrayHasKey('Query',$o);
Expand Down
6 changes: 3 additions & 3 deletions test-cases/includes/classes/AmazonProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonProductTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonProduct('testStore', null, true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonProduct('testStore', null, true, null, __DIR__.'/../../test-config.php');
}

/**
Expand All @@ -28,9 +28,9 @@ protected function tearDown() {
}

public function testProduct(){
$data = simplexml_load_file('/var/www/athena/plugins/amazon/newAmazon/test-cases/mock/searchProducts.xml');
$data = simplexml_load_file(__DIR__.'/../../mock/searchProducts.xml');
$p = $data->ListMatchingProductsResult->Products->Product;
$obj = new AmazonProduct('testStore', $p, true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$obj = new AmazonProduct('testStore', $p, true, null, __DIR__.'/../../test-config.php');
$o = $obj->getData();
$this->assertInternalType('array',$o);
$this->assertFalse($this->object->getData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonReportAcknowledgerTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonReportAcknowledger('testStore', null, true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonReportAcknowledger('testStore', null, true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test-cases/includes/classes/AmazonReportListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AmazonReportListTest extends PHPUnit_Framework_TestCase {
*/
protected function setUp() {
resetLog();
$this->object = new AmazonReportList('testStore', true, null, '/var/www/athena/plugins/amazon/newAmazon/test-cases/test-config.php');
$this->object = new AmazonReportList('testStore', true, null, __DIR__.'/../../test-config.php');
}

/**
Expand Down
Loading

0 comments on commit 09be5f8

Please sign in to comment.