Fixing Breaking Changes in ItemList

This commit is contained in:
japatel
2014-10-14 16:54:43 -05:00
parent dc2ac0fd63
commit 89855f4624
18 changed files with 632 additions and 75 deletions

View File

@@ -7,8 +7,8 @@ use PayPal\Test\Constants;
class ItemListTest extends \PHPUnit_Framework_TestCase
{
private $items = array();
/** @var ItemList */
private $items;
private static $name = "item name";
private static $price = "1.12";
@@ -19,6 +19,7 @@ class ItemListTest extends \PHPUnit_Framework_TestCase
public static function createItemList()
{
/** @var Item $item */
$item = ItemTest::createItem();
$itemList = new ItemList();
@@ -48,4 +49,35 @@ class ItemListTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($itemList, $this->items);
}
}
public function testAddItemMethod()
{
$item2 = ItemTest::createItem();
$item2->setName("Item2");
$this->items->addItem($item2);
$found = false;
foreach ($this->items->getItems() as $item) {
if ($item->getName() == $item2->getName()) {
$found = true;
}
}
$this->assertTrue($found);
}
public function testRemoveItemMethod()
{
$itemList = new ItemList();
$item1 = ItemTest::createItem();
$item1->setName("Name1");
$item2 = ItemTest::createItem();
$itemList->addItem($item1);
$itemList->addItem($item2);
$itemList->removeItem($item2);
$this->assertEquals(sizeof($itemList->getItems()), 1);
$remainingElements = $itemList->getItems();
$this->assertEquals($remainingElements[0]->getName(), "Name1");
}
}

View File

@@ -49,4 +49,4 @@ class ItemTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($item, $this->item);
}
}
}

View File

@@ -0,0 +1,165 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Patch;
use PayPal\Common\PPModel;
use PayPal\Rest\ApiContext;
use PayPal\Rest\IResource;
use PayPal\Api\CreateProfileResponse;
use PayPal\Transport\PPRestCall;
use PayPal\Api\WebProfile;
/**
* Class WebProfile
*
* @package PayPal\Test\Api
*/
class WebProfileFunctionalTest extends \PHPUnit_Framework_TestCase
{
public $operation;
public $response;
public $mode = 'mock';
public $mockPPRestCall;
public function setUp()
{
$className = $this->getClassName();
$testName = $this->getName();
$operationString = file_get_contents(__DIR__ . "/../resources/$className/$testName.json");
$this->operation = json_decode($operationString, true);
$this->response = true;
if (array_key_exists('body', $this->operation['response'])) {
$this->response = json_encode($this->operation['response']['body']);
}
$this->mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
if ($this->mode != 'sandbox') {
// Mock PPRest Caller if mode set to mock
$this->mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PPRestCall')
->disableOriginalConstructor()
->getMock();
$this->mockPPRestCall->expects($this->any())
->method('execute')
->will($this->returnValue(
$this->response
));
}
}
/**
* Returns just the classname of the test you are executing. It removes the namespaces.
* @return string
*/
public function getClassName()
{
return join('', array_slice(explode('\\', get_class($this)), -1));
}
public function testCreate()
{
$request = $this->operation['request']['body'];
$obj = new WebProfile($request);
$obj->setName(uniqid());
$result = $obj->create(null, $this->mockPPRestCall);
$this->assertNotNull($result);
return $result;
}
/**
* @depends testCreate
* @param $createProfileResponse CreateProfileResponse
* @return WebProfile
*/
public function testGet($createProfileResponse)
{
$result = WebProfile::get($createProfileResponse->getId(), null, $this->mockPPRestCall);
$this->assertNotNull($result);
$this->assertEquals($createProfileResponse->getId(), $result->getId());
$this->assertEquals($this->operation['response']['body']['presentation']['logo_image'], $result->getPresentation()->getLogoImage());
$this->assertEquals($this->operation['response']['body']['input_fields']['no_shipping'], $result->getInputFields()->getNoShipping());
$this->assertEquals($this->operation['response']['body']['input_fields']['address_override'], $result->getInputFields()->getAddressOverride());
return $result;
}
/**
* @depends testGet
* @param $webProfile WebProfile
*/
public function testGetList($webProfile)
{
$result = WebProfile::get_list(null, $this->mockPPRestCall);
$this->assertNotNull($result);
$found = false;
$foundObject = null;
foreach ($result as $webProfileObject) {
if ($webProfileObject->getId() == $webProfile->getId()) {
$found = true;
$foundObject = $webProfileObject;
break;
}
}
$this->assertTrue($found, "The Created Web Profile was not found in the get list");
$this->assertEquals($webProfile->getId(), $foundObject->getId());
$this->assertEquals($this->operation['response']['body'][0]['presentation']['logo_image'], $foundObject->getPresentation()->getLogoImage());
$this->assertEquals($this->operation['response']['body'][0]['input_fields']['no_shipping'], $foundObject->getInputFields()->getNoShipping());
$this->assertEquals($this->operation['response']['body'][0]['input_fields']['address_override'], $foundObject->getInputFields()->getAddressOverride());
}
/**
* @depends testGet
* @param $webProfile WebProfile
*/
public function testUpdate($webProfile)
{
$boolValue = $webProfile->getInputFields()->getNoShipping();
$newValue = ($boolValue + 1) % 2;
$webProfile->getInputFields()->setNoShipping($newValue);
$result = $webProfile->update(null, $this->mockPPRestCall);
$this->assertNotNull($result);
$this->assertEquals($webProfile->getInputFields()->getNoShipping(), $newValue);
}
/**
* @depends testGet
* @param $webProfile WebProfile
*/
public function testPartialUpdate($webProfile)
{
$patches = array();
$patches[] = new Patch('{
"op": "add",
"path": "/presentation/brand_name",
"value":"new_brand_name"
}');
$patches[] = new Patch('{
"op": "remove",
"path": "/flow_config/landing_page_type"
}');
$result = $webProfile->partial_update($patches, null, $this->mockPPRestCall);
$this->assertTrue($result);
}
/**
* @depends testGet
* @param $createProfileResponse CreateProfileResponse
*/
public function testDelete($createProfileResponse)
{
$webProfile = new WebProfile();
$webProfile->setId($createProfileResponse->getId());
$result = $webProfile->delete(null, $this->mockPPRestCall);
$this->assertTrue($result);
}
}

View File

@@ -0,0 +1,50 @@
{
"description": "Create a web experience profile.",
"title": "Create profile",
"runnable": true,
"operationId": "web-profile.create",
"user": {
"scopes": [
"https://api.paypal.com/v1/payments/.*"
]
},
"credentials": {
"oauth": {
"clientId": "test-client-01",
"clientSecret": "test_secret_a",
"path": "/v1/oauth2/token"
}
},
"request": {
"path": "v1/payment-experience/web-profiles/",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"PayPal-Request-Id": "abcdefgh123",
"Authorization": "Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn"
},
"body": {
"name":"someName2",
"presentation":{
"logo_image":"http://www.ebay.com"
},
"input_fields":{
"no_shipping":1,
"address_override":1
},
"flow_config":{
"landing_page_type":"billing",
"bank_txn_pending_url":"http://www.ebay.com"
}
}
},
"response": {
"status": "201",
"headers": {
"Content-Type": "application/json"
},
"body": {
"id": "XP-RFV4-PVD8-AGHJ-8E5J"
}
}
}

View File

@@ -0,0 +1,30 @@
{
"description": "Delete a web experience profile list.",
"title": "Delete profile",
"runnable": true,
"operationId": "web-profile.delete",
"user": {
"scopes": [
"https://api.paypal.com/v1/payments/.*"
]
},
"credentials": {
"oauth": {
"clientId": "test-client-01",
"clientSecret": "test_secret_a",
"path": "/v1/oauth2/token"
}
},
"request": {
"path": "v1/payment-experience/web-profiles/XP-RFV4-PVD8-AGHJ-8E5J",
"method": "DELETE",
"headers": {
"Authorization": "Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn"
}
},
"response": {
"status": "204",
"headers": {
}
}
}

View File

@@ -0,0 +1,46 @@
{
"description": "Fetch a web experience profile.",
"title": "Get profile",
"runnable": true,
"operationId": "web-profile.get",
"user": {
"scopes": [
"https://api.paypal.com/v1/payments/.*"
]
},
"credentials": {
"oauth": {
"clientId": "test-client-01",
"clientSecret": "test_secret_a",
"path": "/v1/oauth2/token"
}
},
"request": {
"path": "/v1/payment-experience/web-profiles/XP-RFV4-PVD8-AGHJ-8E5J",
"method": "GET",
"headers": {
"Authorization": "Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn"
}
},
"response": {
"status": "200",
"headers": {
"Content-Type": "application/json"
},
"body": {
"id": "XP-RFV4-PVD8-AGHJ-8E5J",
"name":"someName2",
"presentation":{
"logo_image":"http://www.ebay.com"
},
"input_fields":{
"no_shipping":1,
"address_override":1
},
"flow_config":{
"landing_page_type":"billing",
"bank_txn_pending_url":"http://www.ebay.com"
}
}
}
}

View File

@@ -0,0 +1,77 @@
{
"description": "Fetch web experience profile list for a given merchant.",
"title": "Get profile list",
"runnable": true,
"operationId": "web-profile.get-list",
"user": {
"scopes": [
"https://api.paypal.com/v1/payments/.*"
]
},
"credentials": {
"oauth": {
"clientId": "test-client-01",
"clientSecret": "test_secret_a",
"path": "/v1/oauth2/token"
}
},
"request": {
"path": "/v1/payment-experience/web-profiles",
"method": "GET",
"headers": {
"Authorization": "Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn"
}
},
"response": {
"status": "200",
"headers": {
"Content-Type": "application/json"
},
"body": [
{
"id": "XP-RFV4-PVD8-AGHJ-8E5J",
"name":"someName2",
"presentation":{
"logo_image":"http://www.ebay.com"
},
"input_fields":{
"no_shipping":1,
"address_override":1
},
"flow_config":{
"landing_page_type":"billing",
"bank_txn_pending_url":"http://www.ebay.com"
}
},
{
"id": "XP-A88A-LYLW-8Y3X-E5ER",
"name": "someName2",
"flow_config": {
"landing_page_type": "billing",
"bank_txn_pending_url": "http://www.ebay.com"
},
"input_fields": {
"no_shipping": 1,
"address_override": 1
},
"presentation": {
"logo_image": "http://www.ebay.com"
}
},
{
"id": "XP-RFV4-PVD8-AGHJ-8E5J",
"name": "someName2",
"flow_config": {
"bank_txn_pending_url": "http://www.ebay.com"
},
"input_fields": {
"no_shipping": 1,
"address_override": 1
},
"presentation": {
"logo_image": "http://www.ebay.com"
}
}
]
}
}

View File

@@ -0,0 +1,45 @@
{
"description": "Partially update a web experience profile.",
"title": "Partially Update profile",
"runnable": true,
"operationId": "web-profile.partial-update",
"user": {
"scopes": [
"https://api.paypal.com/v1/payments/.*"
]
},
"credentials": {
"oauth": {
"clientId": "test-client-01",
"clientSecret": "test_secret_a",
"path": "/v1/oauth2/token"
}
},
"request": {
"path": "v1/payment-experience/web-profiles/XP-RFV4-PVD8-AGHJ-8E5J",
"method": "PATCH",
"headers": {
"Content-Type": "application/json",
"PayPal-Request-Id": "abcdefgh123",
"Authorization": "Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn"
},
"body": [
{
"op": "add",
"path": "/presentation/brand_name",
"value":"new_brand_name"
},
{
"op": "remove",
"path": "/flow_config/landing_page_type"
}
]
},
"response": {
"status": "204",
"headers": {
"Content-Type": "application/json"
}
}
}

View File

@@ -0,0 +1,46 @@
{
"description": "Update a web experience profile.",
"title": "Update profile",
"runnable": true,
"operationId": "web-profile.update",
"user": {
"scopes": [
"https://api.paypal.com/v1/payments/.*"
]
},
"credentials": {
"oauth": {
"clientId": "test-client-01",
"clientSecret": "test_secret_a",
"path": "/v1/oauth2/token"
}
},
"request": {
"path": "v1/payment-experience/web-profiles/XP-RFV4-PVD8-AGHJ-8E5J",
"method": "PUT",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer ECvJ_yBNz_UfMmCvWEbT_2ZWXdzbFFQZ-1Y5K2NGgeHn"
},
"body": {
"name":"someName2",
"presentation":{
"logo_image":"http://www.ebay.com"
},
"input_fields":{
"no_shipping":0,
"address_override":1
},
"flow_config":{
"landing_page_type":"billing",
"bank_txn_pending_url":"http://www.ebay.com"
}
}
},
"response": {
"status": "204",
"headers": {
"Content-Type": "application/json"
}
}
}