forked from LiveCarta/PayPal-PHP-SDK
Updated Payment APIs
- Updated SDK Models to latest Payment APIs - Updated Unit Tests
This commit is contained in:
@@ -1,59 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Test\Api;
|
||||
|
||||
use PayPal\Common\PayPalResourceModel;
|
||||
use PayPal\Validation\ArgumentValidator;
|
||||
use PayPal\Api\Capture;
|
||||
use PayPal\Api\Authorization;
|
||||
use PayPal\Rest\ApiContext;
|
||||
use PayPal\Transport\PPRestCall;
|
||||
use PayPal\Api\Order;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\Details;
|
||||
use PayPal\Api\Links;
|
||||
use PayPal\Test\Constants;
|
||||
|
||||
/**
|
||||
* Class Order
|
||||
*
|
||||
* @package PayPal\Test\Api
|
||||
*/
|
||||
class OrderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/** @var Order */
|
||||
private $order;
|
||||
|
||||
public static $id = 'O-0AA8876533760860M';
|
||||
public static $createTime = '2014-08-25T19:24:04Z';
|
||||
public static $updateTime = '2014-08-25T19:24:51Z';
|
||||
public static $state = 'pending';
|
||||
public static $parentPayment = 'PAY-0AL32935UM2331537KP5Y2VA';
|
||||
public static $reasonCode = 'order';
|
||||
|
||||
public static function createOrder()
|
||||
/**
|
||||
* Gets Json String of Object Order
|
||||
* @return string
|
||||
*/
|
||||
public static function getJson()
|
||||
{
|
||||
$order = new Order();
|
||||
$order->setId(self::$id);
|
||||
$order->setCreateTime(self::$createTime);
|
||||
$order->setUpdateTime(self::$updateTime);
|
||||
$order->setState(self::$state);
|
||||
$order->setAmount(AmountTest::createAmount());
|
||||
|
||||
return $order;
|
||||
return '{"id":"TestSample","purchase_unit_reference_id":"TestSample","amount":' .AmountTest::getJson() . ',"payment_mode":"TestSample","state":"TestSample","reason_code":"TestSample","pending_reason":"TestSample","protection-eligibility":"TestSample","protection-eligibility_type":"TestSample","parent_payment":"TestSample","fmf_details":' .FmfDetailsTest::getJson() . ',"create_time":"TestSample","update_time":"TestSample","links":' .LinksTest::getJson() . '}';
|
||||
}
|
||||
|
||||
public function setup()
|
||||
/**
|
||||
* Gets Object Instance with Json data filled in
|
||||
* @return Order
|
||||
*/
|
||||
public static function getObject()
|
||||
{
|
||||
$this->order = self::createOrder();
|
||||
return new Order(self::getJson());
|
||||
}
|
||||
|
||||
public function testGetterSetter()
|
||||
{
|
||||
|
||||
$this->assertEquals(self::$id, $this->order->getId());
|
||||
$this->assertEquals(self::$createTime, $this->order->getCreateTime());
|
||||
$this->assertEquals(self::$updateTime, $this->order->getUpdateTime());
|
||||
$this->assertEquals(self::$state, $this->order->getState());
|
||||
$this->assertEquals(AmountTest::$currency, $this->order->getAmount()->getCurrency());
|
||||
/**
|
||||
* Tests for Serialization and Deserialization Issues
|
||||
* @return Order
|
||||
*/
|
||||
public function testSerializationDeserialization()
|
||||
{
|
||||
$obj = new Order(self::getJson());
|
||||
$this->assertNotNull($obj);
|
||||
$this->assertNotNull($obj->getId());
|
||||
$this->assertNotNull($obj->getPurchaseUnitReferenceId());
|
||||
$this->assertNotNull($obj->getAmount());
|
||||
$this->assertNotNull($obj->getPaymentMode());
|
||||
$this->assertNotNull($obj->getState());
|
||||
$this->assertNotNull($obj->getReasonCode());
|
||||
$this->assertNotNull($obj->getPendingReason());
|
||||
$this->assertNotNull($obj->getProtectionEligibility());
|
||||
$this->assertNotNull($obj->getProtectionEligibilityType());
|
||||
$this->assertNotNull($obj->getParentPayment());
|
||||
$this->assertNotNull($obj->getFmfDetails());
|
||||
$this->assertNotNull($obj->getCreateTime());
|
||||
$this->assertNotNull($obj->getUpdateTime());
|
||||
$this->assertNotNull($obj->getLinks());
|
||||
$this->assertEquals(self::getJson(), $obj->toJson());
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function testSerializeDeserialize()
|
||||
/**
|
||||
* @depends testSerializationDeserialization
|
||||
* @param Order $obj
|
||||
*/
|
||||
public function testGetters($obj)
|
||||
{
|
||||
$o1 = $this->order;
|
||||
$this->assertEquals($obj->getId(), "TestSample");
|
||||
$this->assertEquals($obj->getPurchaseUnitReferenceId(), "TestSample");
|
||||
$this->assertEquals($obj->getAmount(), AmountTest::getObject());
|
||||
$this->assertEquals($obj->getPaymentMode(), "TestSample");
|
||||
$this->assertEquals($obj->getState(), "TestSample");
|
||||
$this->assertEquals($obj->getReasonCode(), "TestSample");
|
||||
$this->assertEquals($obj->getPendingReason(), "TestSample");
|
||||
$this->assertEquals($obj->getProtectionEligibility(), "TestSample");
|
||||
$this->assertEquals($obj->getProtectionEligibilityType(), "TestSample");
|
||||
$this->assertEquals($obj->getParentPayment(), "TestSample");
|
||||
$this->assertEquals($obj->getFmfDetails(), FmfDetailsTest::getObject());
|
||||
$this->assertEquals($obj->getCreateTime(), "TestSample");
|
||||
$this->assertEquals($obj->getUpdateTime(), "TestSample");
|
||||
$this->assertEquals($obj->getLinks(), LinksTest::getObject());
|
||||
}
|
||||
|
||||
$o2 = new Order();
|
||||
$o2->fromJson($o1->toJson());
|
||||
|
||||
$this->assertEquals($o1, $o2);
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param Order $obj
|
||||
*/
|
||||
public function testGet($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
OrderTest::getJson()
|
||||
));
|
||||
|
||||
$result = $obj->get("orderId", $mockApiContext, $mockPPRestCall);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param Order $obj
|
||||
*/
|
||||
public function testCapture($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
CaptureTest::getJson()
|
||||
));
|
||||
$capture = CaptureTest::getObject();
|
||||
|
||||
$result = $obj->capture($capture, $mockApiContext, $mockPPRestCall);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param Order $obj
|
||||
*/
|
||||
public function testVoid($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
self::getJson()
|
||||
));
|
||||
|
||||
$result = $obj->void($mockApiContext, $mockPPRestCall);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
/**
|
||||
* @dataProvider mockProvider
|
||||
* @param Order $obj
|
||||
*/
|
||||
public function testAuthorize($obj, $mockApiContext)
|
||||
{
|
||||
$mockPPRestCall = $this->getMockBuilder('\PayPal\Transport\PayPalRestCall')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$mockPPRestCall->expects($this->any())
|
||||
->method('execute')
|
||||
->will($this->returnValue(
|
||||
AuthorizationTest::getJson()
|
||||
));
|
||||
|
||||
$authorization = new Authorization();
|
||||
$result = $obj->authorize($authorization, $mockApiContext, $mockPPRestCall);
|
||||
$this->assertNotNull($result);
|
||||
}
|
||||
|
||||
public function mockProvider()
|
||||
{
|
||||
$obj = self::getObject();
|
||||
$mockApiContext = $this->getMockBuilder('ApiContext')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
return array(
|
||||
array($obj, $mockApiContext),
|
||||
array($obj, null)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user