forked from LiveCarta/PayPal-PHP-SDK
Enabled Payment Experience
- Updated Api to enabled Payment Experience - Updated Tests and Samples - Added Json Validator - Ability for PPModel to return array of self objects
This commit is contained in:
83
tests/PayPal/Test/Api/WebProfileTest.php
Normal file
83
tests/PayPal/Test/Api/WebProfileTest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Test\Api;
|
||||
|
||||
use PayPal\Api\WebProfile;
|
||||
|
||||
/**
|
||||
* Class WebProfile
|
||||
*
|
||||
* @package PayPal\Test\Api
|
||||
*/
|
||||
class WebProfileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testCreateprofileSerialization()
|
||||
{
|
||||
$requestBody = '{"name":"someName2' . uniqid() . '","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"}}';
|
||||
$requestBodyEncoded = json_encode(json_decode($requestBody, true));
|
||||
$object = new WebProfile($requestBodyEncoded);
|
||||
|
||||
$json = $object->toJson();
|
||||
$this->assertEquals($requestBodyEncoded, $json);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
public function testCreateprofileOperation()
|
||||
{
|
||||
$requestBody = '{"name":"someName2' . uniqid() . '","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"}}';
|
||||
$requestBodyEncoded = json_encode(json_decode($requestBody, true));
|
||||
$object = new WebProfile($requestBodyEncoded);
|
||||
$response = $object->create(null);
|
||||
$this->assertNotNull($response);
|
||||
return $response->getId();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @depends testCreateprofileOperation
|
||||
* @group integration
|
||||
*/
|
||||
public function testGetprofileOperation($profileId)
|
||||
{
|
||||
$response = WebProfile::get($profileId, null);
|
||||
$this->assertNotNull($response);
|
||||
$this->assertEquals($response->getId(), $profileId);
|
||||
$this->assertEquals("http://www.ebay.com", $response->getPresentation()->getLogoImage());
|
||||
$this->assertEquals(1, $response->getInputFields()->getNoShipping());
|
||||
$this->assertEquals(1, $response->getInputFields()->getAddressOverride());
|
||||
$this->assertEquals("billing", $response->getFlowConfig()->getLandingPageType());
|
||||
$this->assertEquals("http://www.ebay.com", $response->getFlowConfig()->getBankTxnPendingUrl());
|
||||
return $response->getId();
|
||||
}
|
||||
|
||||
|
||||
public function testValidationerrorSerialization()
|
||||
{
|
||||
$requestBody = '{"name":"sampleName' . uniqid() . '","presentation":{"logo_image":"http://www.ebay.com"},"input_fields":{"no_shipping":4,"address_override":1},"flow_config":{"landing_page_type":"billing","bank_txn_pending_url":"ht//www.ebay.com"}}';
|
||||
$requestBodyEncoded = json_encode(json_decode($requestBody, true));
|
||||
$object = new WebProfile($requestBodyEncoded);
|
||||
|
||||
$json = $object->toJson();
|
||||
$this->assertEquals($requestBodyEncoded, $json);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
* @expectedException PayPal\Exception\PPConnectionException
|
||||
* @expectedExceptionCode 400
|
||||
*/
|
||||
public function testValidationerrorOperation()
|
||||
{
|
||||
$requestBody = '{"name":"sampleName' . uniqid() . '","presentation":{"logo_image":"http://www.ebay.com"},"input_fields":{"no_shipping":4,"address_override":1},"flow_config":{"landing_page_type":"billing","bank_txn_pending_url":"ht//www.ebay.com"}}';
|
||||
$requestBodyEncoded = json_encode(json_decode($requestBody, true));
|
||||
$object = new WebProfile($requestBodyEncoded);
|
||||
$response = $object->create(null);
|
||||
return $response->getId();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,167 +1,167 @@
|
||||
<?php
|
||||
namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Core\PPConfigManager;
|
||||
|
||||
class ModelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testSimpleClassConversion()
|
||||
{
|
||||
$o = new SimpleClass();
|
||||
$o->setName("test");
|
||||
$o->setDescription("description");
|
||||
|
||||
$this->assertEquals("test", $o->getName());
|
||||
$this->assertEquals("description", $o->getDescription());
|
||||
|
||||
$json = $o->toJSON();
|
||||
$this->assertEquals('{"name":"test","description":"description"}', $json);
|
||||
|
||||
$newO = new SimpleClass();
|
||||
$newO->fromJson($json);
|
||||
$this->assertEquals($o, $newO);
|
||||
|
||||
}
|
||||
|
||||
public function testConstructorJSON()
|
||||
{
|
||||
$obj = new SimpleClass('{"name":"test","description":"description"}');
|
||||
$this->assertEquals($obj->getName(), "test");
|
||||
$this->assertEquals($obj->getDescription(), "description");
|
||||
}
|
||||
|
||||
public function testConstructorArray()
|
||||
{
|
||||
$arr = array('name' => 'test', 'description' => 'description');
|
||||
$obj = new SimpleClass($arr);
|
||||
$this->assertEquals($obj->getName(), "test");
|
||||
$this->assertEquals($obj->getDescription(), "description");
|
||||
}
|
||||
|
||||
public function testConstructorNull()
|
||||
{
|
||||
$obj = new SimpleClass(null);
|
||||
$this->assertNotEquals($obj->getName(), "test");
|
||||
$this->assertNotEquals($obj->getDescription(), "description");
|
||||
$this->assertNull($obj->getName());
|
||||
$this->assertNull($obj->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage data should be either json or array representation of object
|
||||
*/
|
||||
public function testConstructorInvalidInput()
|
||||
{
|
||||
new SimpleClass("Something that is not even correct");
|
||||
}
|
||||
|
||||
public function testSimpleClassObjectConversion()
|
||||
{
|
||||
$json = '{"name":"test","description":"description"}';
|
||||
|
||||
$obj = new SimpleClass();
|
||||
$obj->fromJson($json);
|
||||
|
||||
$this->assertEquals("test", $obj->getName());
|
||||
$this->assertEquals("description", $obj->getDescription());
|
||||
|
||||
}
|
||||
|
||||
public function testSimpleClassObjectInvalidConversion()
|
||||
{
|
||||
try {
|
||||
$json = '{"name":"test","description":"description","invalid":"value"}';
|
||||
|
||||
$obj = new SimpleClass();
|
||||
$obj->fromJson($json);
|
||||
|
||||
$this->assertEquals("test", $obj->getName());
|
||||
$this->assertEquals("description", $obj->getDescription());
|
||||
} catch (\PHPUnit_Framework_Error_Notice $ex) {
|
||||
echo $ex->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @outputBuffering enabled
|
||||
*/
|
||||
public function testInvalidMagicMethod()
|
||||
{
|
||||
$obj = new SimpleClass();
|
||||
try {
|
||||
$obj->invalid = "value2";
|
||||
$this->assertEquals($obj->invalid, "value2");
|
||||
if (PPConfigManager::getInstance()->get('validation.level') == 'strict') {
|
||||
$this->fail("It should have thrown a Notice Error");
|
||||
}
|
||||
} catch (\PHPUnit_Framework_Error_Notice $ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @outputBuffering enabled
|
||||
*/
|
||||
public function testInvalidMagicMethodWithDisabledValidation()
|
||||
{
|
||||
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'disabled'));
|
||||
$obj = new SimpleClass();
|
||||
try {
|
||||
$obj->invalid = "value2";
|
||||
$this->assertEquals($obj->invalid, "value2");
|
||||
} catch (\PHPUnit_Framework_Error_Notice $ex) {
|
||||
$this->fail("It should not have thrown a Notice Error as it is disabled.");
|
||||
}
|
||||
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict'));
|
||||
}
|
||||
|
||||
public function testInvalidMagicMethodWithValidationLevel()
|
||||
{
|
||||
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'log'));
|
||||
$obj = new SimpleClass();
|
||||
$obj->invalid2 = "value2";
|
||||
$this->assertEquals($obj->invalid2, "value2");
|
||||
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict'));
|
||||
}
|
||||
|
||||
public function testArrayClassConversion()
|
||||
{
|
||||
$o = new ArrayClass();
|
||||
$o->setName("test");
|
||||
$o->setDescription("description");
|
||||
$o->setTags(array('payment', 'info', 'test'));
|
||||
|
||||
$this->assertEquals("test", $o->getName());
|
||||
$this->assertEquals("description", $o->getDescription());
|
||||
$this->assertEquals(array('payment', 'info', 'test'), $o->getTags());
|
||||
|
||||
$json = $o->toJSON();
|
||||
$this->assertEquals('{"name":"test","description":"description","tags":["payment","info","test"]}', $json);
|
||||
|
||||
$newO = new ArrayClass();
|
||||
$newO->fromJson($json);
|
||||
$this->assertEquals($o, $newO);
|
||||
}
|
||||
|
||||
public function testNestedClassConversion()
|
||||
{
|
||||
$n = new ArrayClass();
|
||||
$n->setName("test");
|
||||
$n->setDescription("description");
|
||||
$o = new NestedClass();
|
||||
$o->setId('123');
|
||||
$o->setInfo($n);
|
||||
|
||||
$this->assertEquals("123", $o->getId());
|
||||
$this->assertEquals("test", $o->getInfo()->getName());
|
||||
|
||||
$json = $o->toJSON();
|
||||
$this->assertEquals('{"id":"123","info":{"name":"test","description":"description"}}', $json);
|
||||
|
||||
$newO = new NestedClass();
|
||||
$newO->fromJson($json);
|
||||
$this->assertEquals($o, $newO);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Core\PPConfigManager;
|
||||
|
||||
class ModelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testSimpleClassConversion()
|
||||
{
|
||||
$o = new SimpleClass();
|
||||
$o->setName("test");
|
||||
$o->setDescription("description");
|
||||
|
||||
$this->assertEquals("test", $o->getName());
|
||||
$this->assertEquals("description", $o->getDescription());
|
||||
|
||||
$json = $o->toJSON();
|
||||
$this->assertEquals('{"name":"test","description":"description"}', $json);
|
||||
|
||||
$newO = new SimpleClass();
|
||||
$newO->fromJson($json);
|
||||
$this->assertEquals($o, $newO);
|
||||
|
||||
}
|
||||
|
||||
public function testConstructorJSON()
|
||||
{
|
||||
$obj = new SimpleClass('{"name":"test","description":"description"}');
|
||||
$this->assertEquals($obj->getName(), "test");
|
||||
$this->assertEquals($obj->getDescription(), "description");
|
||||
}
|
||||
|
||||
public function testConstructorArray()
|
||||
{
|
||||
$arr = array('name' => 'test', 'description' => 'description');
|
||||
$obj = new SimpleClass($arr);
|
||||
$this->assertEquals($obj->getName(), "test");
|
||||
$this->assertEquals($obj->getDescription(), "description");
|
||||
}
|
||||
|
||||
public function testConstructorNull()
|
||||
{
|
||||
$obj = new SimpleClass(null);
|
||||
$this->assertNotEquals($obj->getName(), "test");
|
||||
$this->assertNotEquals($obj->getDescription(), "description");
|
||||
$this->assertNull($obj->getName());
|
||||
$this->assertNull($obj->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Invalid JSON String
|
||||
*/
|
||||
public function testConstructorInvalidInput()
|
||||
{
|
||||
new SimpleClass("Something that is not even correct");
|
||||
}
|
||||
|
||||
public function testSimpleClassObjectConversion()
|
||||
{
|
||||
$json = '{"name":"test","description":"description"}';
|
||||
|
||||
$obj = new SimpleClass();
|
||||
$obj->fromJson($json);
|
||||
|
||||
$this->assertEquals("test", $obj->getName());
|
||||
$this->assertEquals("description", $obj->getDescription());
|
||||
|
||||
}
|
||||
|
||||
public function testSimpleClassObjectInvalidConversion()
|
||||
{
|
||||
try {
|
||||
$json = '{"name":"test","description":"description","invalid":"value"}';
|
||||
|
||||
$obj = new SimpleClass();
|
||||
$obj->fromJson($json);
|
||||
|
||||
$this->assertEquals("test", $obj->getName());
|
||||
$this->assertEquals("description", $obj->getDescription());
|
||||
} catch (\PHPUnit_Framework_Error_Notice $ex) {
|
||||
echo $ex->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @outputBuffering enabled
|
||||
*/
|
||||
public function testInvalidMagicMethod()
|
||||
{
|
||||
$obj = new SimpleClass();
|
||||
try {
|
||||
$obj->invalid = "value2";
|
||||
$this->assertEquals($obj->invalid, "value2");
|
||||
if (PPConfigManager::getInstance()->get('validation.level') == 'strict') {
|
||||
$this->fail("It should have thrown a Notice Error");
|
||||
}
|
||||
} catch (\PHPUnit_Framework_Error_Notice $ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @outputBuffering enabled
|
||||
*/
|
||||
public function testInvalidMagicMethodWithDisabledValidation()
|
||||
{
|
||||
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'disabled'));
|
||||
$obj = new SimpleClass();
|
||||
try {
|
||||
$obj->invalid = "value2";
|
||||
$this->assertEquals($obj->invalid, "value2");
|
||||
} catch (\PHPUnit_Framework_Error_Notice $ex) {
|
||||
$this->fail("It should not have thrown a Notice Error as it is disabled.");
|
||||
}
|
||||
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict'));
|
||||
}
|
||||
|
||||
public function testInvalidMagicMethodWithValidationLevel()
|
||||
{
|
||||
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'log'));
|
||||
$obj = new SimpleClass();
|
||||
$obj->invalid2 = "value2";
|
||||
$this->assertEquals($obj->invalid2, "value2");
|
||||
PPConfigManager::getInstance()->addConfigs(array('validation.level' => 'strict'));
|
||||
}
|
||||
|
||||
public function testArrayClassConversion()
|
||||
{
|
||||
$o = new ArrayClass();
|
||||
$o->setName("test");
|
||||
$o->setDescription("description");
|
||||
$o->setTags(array('payment', 'info', 'test'));
|
||||
|
||||
$this->assertEquals("test", $o->getName());
|
||||
$this->assertEquals("description", $o->getDescription());
|
||||
$this->assertEquals(array('payment', 'info', 'test'), $o->getTags());
|
||||
|
||||
$json = $o->toJSON();
|
||||
$this->assertEquals('{"name":"test","description":"description","tags":["payment","info","test"]}', $json);
|
||||
|
||||
$newO = new ArrayClass();
|
||||
$newO->fromJson($json);
|
||||
$this->assertEquals($o, $newO);
|
||||
}
|
||||
|
||||
public function testNestedClassConversion()
|
||||
{
|
||||
$n = new ArrayClass();
|
||||
$n->setName("test");
|
||||
$n->setDescription("description");
|
||||
$o = new NestedClass();
|
||||
$o->setId('123');
|
||||
$o->setInfo($n);
|
||||
|
||||
$this->assertEquals("123", $o->getId());
|
||||
$this->assertEquals("test", $o->getInfo()->getName());
|
||||
|
||||
$json = $o->toJSON();
|
||||
$this->assertEquals('{"id":"123","info":{"name":"test","description":"description"}}', $json);
|
||||
|
||||
$newO = new NestedClass();
|
||||
$newO->fromJson($json);
|
||||
$this->assertEquals($o, $newO);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user