Updated Payment APIs

- Updated SDK Models to latest Payment APIs
- Updated Unit Tests
This commit is contained in:
Jay Patel
2015-02-26 15:03:59 -06:00
parent 241d80cd17
commit 3e43f93f9b
93 changed files with 6079 additions and 1735 deletions

View File

@@ -1,83 +1,60 @@
<?php
namespace PayPal\Test\Api;
use PayPal\Api\Item;
use PayPal\Common\PayPalModel;
use PayPal\Api\ItemList;
use PayPal\Test\Constants;
/**
* Class ItemList
*
* @package PayPal\Test\Api
*/
class ItemListTest extends \PHPUnit_Framework_TestCase
{
/** @var ItemList */
private $items;
private static $name = "item name";
private static $price = "1.12";
private static $quantity = "10";
private static $sku = "AXVTY123";
private static $currency = "USD";
public static function createItemList()
/**
* Gets Json String of Object ItemList
* @return string
*/
public static function getJson()
{
/** @var Item $item */
$item = ItemTest::createItem();
$itemList = new ItemList();
$itemList->setItems(array($item));
$itemList->setShippingAddress(ShippingAddressTest::getObject());
return $itemList;
return '{"items":' .ItemTest::getJson() . ',"shipping_address":' .ShippingAddressTest::getJson() . ',"shipping_method":"TestSample"}';
}
public function setup()
/**
* Gets Object Instance with Json data filled in
* @return ItemList
*/
public static function getObject()
{
$this->items = self::createItemList();
return new ItemList(self::getJson());
}
public function testGetterSetters()
/**
* Tests for Serialization and Deserialization Issues
* @return ItemList
*/
public function testSerializationDeserialization()
{
$items = $this->items->getItems();
$this->assertEquals(ItemTest::createItem(), $items[0]);
$this->assertEquals(ShippingAddressTest::getObject(), $this->items->getShippingAddress());
$obj = new ItemList(self::getJson());
$this->assertNotNull($obj);
$this->assertNotNull($obj->getItems());
$this->assertNotNull($obj->getShippingAddress());
$this->assertNotNull($obj->getShippingMethod());
$this->assertEquals(self::getJson(), $obj->toJson());
return $obj;
}
public function testSerializeDeserialize()
/**
* @depends testSerializationDeserialization
* @param ItemList $obj
*/
public function testGetters($obj)
{
$itemList = new ItemList();
$itemList->fromJson($this->items->toJSON());
$this->assertEquals($itemList, $this->items);
$this->assertEquals($obj->getItems(), ItemTest::getObject());
$this->assertEquals($obj->getShippingAddress(), ShippingAddressTest::getObject());
$this->assertEquals($obj->getShippingMethod(), "TestSample");
}
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");
}
}