This repository has been archived by the owner on Aug 29, 2019. It is now read-only.
forked from russpos/AWeber-API-PHP-Library
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from geoffp-aweber/master
Fixes nested objects in request
- Loading branch information
Showing
8 changed files
with
254 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
language: php | ||
|
||
sudo: required | ||
php: | ||
- 5.3 | ||
- 5.4 | ||
|
||
script: phpunit --configuration build/phpunit.xml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,60 @@ public function setUp() { | |
$this->found = $this->subscribers->find($this->params); | ||
} | ||
|
||
/** | ||
* Test to ensure that the nested objects, such as "custom_fields", are formatted correctly for GET request. The | ||
* nested objects should be a JSON encoded string. | ||
*/ | ||
public function testFormatOfGetData() { | ||
$findParams = array('custom_fields' => array('test' => 'test')); | ||
$expectedUri = '/accounts/1/lists/303449/subscribers?custom_fields=%7B%22test%22%3A%22test%22%7D&ws.op=find'; | ||
|
||
$this->adapter->clearRequests(); | ||
|
||
$resp = $this->subscribers->find($findParams); | ||
|
||
$req = $this->adapter->requestsMade[0]; | ||
$this->assertEquals($req['method'], 'GET'); | ||
$this->assertEquals($expectedUri, $req['uri']); | ||
$this->assertEmpty($req['headers'], "Find request shouldn't have a Content-Type header"); | ||
} | ||
|
||
/** | ||
* Checks that the nested objects, such as "custom_fields", are formatted correctly. The "create" method | ||
* is a POST with Content-Type of 'application/json'. The data should be formatted as JSON. | ||
*/ | ||
public function testFormatOfPostData() { | ||
|
||
$createParams = array( | ||
'email' => '[email protected]', | ||
'ip_address' => '127.0.0.1', | ||
'name' => 'John Doe', | ||
'custom_fields' => array( | ||
'custom' => 'test' | ||
) | ||
); | ||
|
||
$expectedCreateParams = array( | ||
'ws.op' => 'create', | ||
'email' => '[email protected]', | ||
'ip_address' => '127.0.0.1', | ||
'name' => 'John Doe', | ||
'custom_fields' => array( | ||
'custom' => 'test' | ||
) | ||
); | ||
|
||
$this->adapter->clearRequests(); | ||
|
||
$resp = $this->subscribers->create($createParams); | ||
|
||
$req = $this->adapter->requestsMade[0]; | ||
$this->assertEquals($req['method'], 'POST'); | ||
$this->assertEquals($req['data'], $expectedCreateParams); | ||
$this->assertEquals(array('Content-Type: application/json'), $req['headers'], "Create request should have a Content-Type header"); | ||
|
||
} | ||
|
||
/** | ||
* The find method makes two requests, one for the collection, and the other to get total_size. | ||
*/ | ||
|
@@ -30,15 +84,15 @@ public function testShouldInitiallyMake2APIRequests() { | |
public function testShouldRequestCollectionPageFirst() { | ||
#$this->subscribers->find($this->params); | ||
$uri = $this->adapter->requestsMade[0]['uri']; | ||
$this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.size=1&ws.start=0&ws.op=find'); | ||
$this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.op=find&ws.size=1&ws.start=0'); | ||
} | ||
|
||
/** | ||
* The second of two requests, verify the url to get the total size. | ||
*/ | ||
public function testShouldRequestTotalSizePageSecond() { | ||
$uri = $this->adapter->requestsMade[1]['uri']; | ||
$this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.size=1&ws.start=0&ws.op=find&ws.show=total_size'); | ||
$this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.op=find&ws.show=total_size&ws.size=1&ws.start=0'); | ||
} | ||
|
||
/** | ||
|
@@ -57,7 +111,7 @@ public function testShouldRequestCorrectCollectionPage() { | |
$this->adapter->clearRequests(); | ||
$subscriber = $this->found[1]; | ||
$uri = $this->adapter->requestsMade[0]['uri']; | ||
$this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.size=1&ws.start=1&ws.op=find'); | ||
$this->assertEquals($uri, '/accounts/1/lists/303449/subscribers?status=unsubscribed&ws.op=find&ws.size=1&ws.start=1'); | ||
} | ||
|
||
/** | ||
|
Oops, something went wrong.