forked from LiveCarta/PayPal-PHP-SDK
Enabled EC Parameters support
- Updated Api to enabled EC Parameters - Updated Tests - Updated Logging Manager - Added a feature to do validation on accessors.
This commit is contained in:
@@ -1,29 +1,41 @@
|
||||
<?php
|
||||
namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Common\PPModel;
|
||||
class ArrayClass extends PPModel {
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
class ArrayClass extends PPModel
|
||||
{
|
||||
|
||||
public function setDescription($desc) {
|
||||
$this->desc = $desc;
|
||||
}
|
||||
public function getDescription() {
|
||||
return $this->desc;
|
||||
}
|
||||
|
||||
public function setTags($tags) {
|
||||
if(!is_array($tags)) {
|
||||
$tags = array($tags);
|
||||
}
|
||||
$this->tags = $tags;
|
||||
}
|
||||
public function getTags() {
|
||||
return $this->tags;
|
||||
}
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function setTags($tags)
|
||||
{
|
||||
if (!is_array($tags)) {
|
||||
$tags = array($tags);
|
||||
}
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
public function getTags()
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,24 @@
|
||||
<?php
|
||||
namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Common\PPArrayUtil;
|
||||
|
||||
class ArrayUtilTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testIsAssocArray() {
|
||||
|
||||
$arr = array(1, 2, 3);
|
||||
$this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
|
||||
|
||||
$arr = array(
|
||||
'name' => 'John Doe',
|
||||
'City' => 'San Jose'
|
||||
);
|
||||
$this->assertEquals(true, PPArrayUtil::isAssocArray($arr));
|
||||
|
||||
$arr[] = 'CA';
|
||||
$this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
|
||||
}
|
||||
class ArrayUtilTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testIsAssocArray()
|
||||
{
|
||||
|
||||
$arr = array(1, 2, 3);
|
||||
$this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
|
||||
|
||||
$arr = array(
|
||||
'name' => 'John Doe',
|
||||
'City' => 'San Jose'
|
||||
);
|
||||
$this->assertEquals(true, PPArrayUtil::isAssocArray($arr));
|
||||
|
||||
$arr[] = 'CA';
|
||||
$this->assertEquals(false, PPArrayUtil::isAssocArray($arr));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Common\PPModel;
|
||||
class ChildClass extends SimpleClass {
|
||||
|
||||
|
||||
class ChildClass extends SimpleClass
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,66 +1,167 @@
|
||||
<?php
|
||||
<?php
|
||||
namespace PayPal\Test\Common;
|
||||
use PayPal\Common\PPModel;
|
||||
use PayPal\Test\Common\ArrayClass;
|
||||
use PayPal\Test\Common\SimpleClass;
|
||||
use PayPal\Test\Common\NestedClass;
|
||||
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","desc":"description"}', $json);
|
||||
|
||||
$newO = new SimpleClass();
|
||||
$newO->fromJson($json);
|
||||
$this->assertEquals($o, $newO);
|
||||
|
||||
}
|
||||
|
||||
|
||||
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","desc":"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");
|
||||
// $n->setTags(array('payment', 'info', 'test'));
|
||||
$o = new NestedClass();
|
||||
$o->setId('123');
|
||||
$o->setInfo($n);
|
||||
|
||||
$this->assertEquals("123", $o->getId());
|
||||
$this->assertEquals("test", $o->getInfo()->getName());
|
||||
// $this->assertEquals(array('payment', 'info', 'test'), $o->getInfo()->getTags());
|
||||
|
||||
$json = $o->toJSON();
|
||||
// $this->assertEquals('{"id":"123","info":{"name":"test","desc":"description","tags":["payment","info","test"]}}', $json);
|
||||
$this->assertEquals('{"id":"123","info":{"name":"test","desc":"description"}}', $json);
|
||||
|
||||
$newO = new NestedClass();
|
||||
$newO->fromJson($json);
|
||||
$this->assertEquals($o, $newO);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,36 @@
|
||||
<?php
|
||||
namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Common\PPModel;
|
||||
class NestedClass extends PPModel {
|
||||
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param PayPal\Test\Common\ArrayClass $info
|
||||
*/
|
||||
public function setInfo($info) {
|
||||
$this->info = $info;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return PayPal\Test\Common\ArrayClass
|
||||
*/
|
||||
public function getInfo() {
|
||||
return $this->info;
|
||||
}
|
||||
|
||||
class NestedClass extends PPModel
|
||||
{
|
||||
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param PayPal\Test\Common\ArrayClass $info
|
||||
*/
|
||||
public function setInfo($info)
|
||||
{
|
||||
$this->info = $info;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return PayPal\Test\Common\ArrayClass
|
||||
*/
|
||||
public function getInfo()
|
||||
{
|
||||
return $this->info;
|
||||
}
|
||||
}
|
||||
@@ -2,130 +2,144 @@
|
||||
|
||||
use PayPal\Common\PPModel;
|
||||
|
||||
class SimpleModelTestClass extends PPModel {
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param string $field1
|
||||
*/
|
||||
public function setField1($field1) {
|
||||
$this->field1 = $field1;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getField1() {
|
||||
return $this->field1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param string $field2
|
||||
*/
|
||||
public function setField2($field2) {
|
||||
$this->field2 = $field2;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getField2() {
|
||||
return $this->field2;
|
||||
}
|
||||
|
||||
class SimpleModelTestClass extends PPModel
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param string $field1
|
||||
*/
|
||||
public function setField1($field1)
|
||||
{
|
||||
$this->field1 = $field1;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getField1()
|
||||
{
|
||||
return $this->field1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param string $field2
|
||||
*/
|
||||
public function setField2($field2)
|
||||
{
|
||||
$this->field2 = $field2;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getField2()
|
||||
{
|
||||
return $this->field2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class ContainerModelTestClass extends PPModel
|
||||
{
|
||||
|
||||
class ContainerModelTestClass extends PPModel {
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param string $field1
|
||||
*/
|
||||
public function setField1($field1)
|
||||
{
|
||||
$this->field1 = $field1;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param string $field1
|
||||
*/
|
||||
public function setField1($field1) {
|
||||
$this->field1 = $field1;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getField1()
|
||||
{
|
||||
return $this->field1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getField1() {
|
||||
return $this->field1;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param SimpleModelTestClass $field1
|
||||
*/
|
||||
public function setNested1($nested1)
|
||||
{
|
||||
$this->nested1 = $nested1;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param SimpleModelTestClass $field1
|
||||
*/
|
||||
public function setNested1($nested1) {
|
||||
$this->nested1 = $nested1;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return SimpleModelTestClass
|
||||
*/
|
||||
public function getNested1() {
|
||||
return $this->nested1;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return SimpleModelTestClass
|
||||
*/
|
||||
public function getNested1()
|
||||
{
|
||||
return $this->nested1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class ListModelTestClass extends PPModel {
|
||||
class ListModelTestClass extends PPModel
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param string $list1
|
||||
*/
|
||||
public function setList1($list1) {
|
||||
$this->list1 = $list1;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param string $list1
|
||||
*/
|
||||
public function setList1($list1)
|
||||
{
|
||||
$this->list1 = $list1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getList1() {
|
||||
return $this->list1;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getList1()
|
||||
{
|
||||
return $this->list1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param SimpleModelTestClass $list2 array of SimpleModelTestClass
|
||||
*/
|
||||
public function setList2($list2) {
|
||||
$this->list2 = $list2;
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @param SimpleModelTestClass $list2 array of SimpleModelTestClass
|
||||
*/
|
||||
public function setList2($list2)
|
||||
{
|
||||
$this->list2 = $list2;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return SimpleModelTestClass array of SimpleModelTestClass
|
||||
*/
|
||||
public function getList2() {
|
||||
return $this->list2;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @access public
|
||||
* @return SimpleModelTestClass array of SimpleModelTestClass
|
||||
*/
|
||||
public function getList2()
|
||||
{
|
||||
return $this->list2;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -136,93 +150,99 @@ class ListModelTestClass extends PPModel {
|
||||
*/
|
||||
class PPModelTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testSimpleConversion() {
|
||||
$o = new SimpleModelTestClass();
|
||||
$o->setField1('value 1');
|
||||
$o->setField2("value 2");
|
||||
|
||||
$this->assertEquals('{"field1":"value 1","field2":"value 2"}', $o->toJSON());
|
||||
|
||||
$oCopy = new SimpleModelTestClass();
|
||||
$oCopy->fromJson($o->toJSON());
|
||||
$this->assertEquals($o, $oCopy);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testSpecialChars() {
|
||||
$o = new SimpleModelTestClass();
|
||||
$o->setField1('value "1');
|
||||
$o->setField2("value 2");
|
||||
|
||||
$this->assertEquals('{"field1":"value \"1","field2":"value 2"}', $o->toJSON());
|
||||
|
||||
$oCopy = new SimpleModelTestClass();
|
||||
$oCopy->fromJson($o->toJSON());
|
||||
$this->assertEquals($o, $oCopy);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testNestedConversion() {
|
||||
$child = new SimpleModelTestClass();
|
||||
$child->setField1('value 1');
|
||||
$child->setField2("value 2");
|
||||
|
||||
$parent = new ContainerModelTestClass();
|
||||
$parent->setField1("parent");
|
||||
$parent->setNested1($child);
|
||||
|
||||
$this->assertEquals('{"field1":"parent","nested1":{"field1":"value 1","field2":"value 2"}}',
|
||||
$parent->toJSON());
|
||||
|
||||
$parentCopy = new ContainerModelTestClass();
|
||||
$parentCopy->fromJson($parent->toJSON());
|
||||
$this->assertEquals($parent, $parentCopy);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testListConversion() {
|
||||
$c1 = new SimpleModelTestClass();
|
||||
$c1->setField1("a")->setField2('value');
|
||||
|
||||
$c2 = new SimpleModelTestClass();
|
||||
$c1->setField1("another")->setField2('object');
|
||||
|
||||
$parent = new ListModelTestClass();
|
||||
$parent->setList1(array('simple', 'list', 'with', 'integer', 'keys'));
|
||||
$parent->setList2(array($c1, $c2));
|
||||
|
||||
$parentCopy = new ListModelTestClass();
|
||||
$parentCopy->fromJson($parent->toJSON());
|
||||
$this->assertEquals($parent, $parentCopy);
|
||||
|
||||
}
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testSimpleConversion()
|
||||
{
|
||||
$o = new SimpleModelTestClass();
|
||||
$o->setField1('value 1');
|
||||
$o->setField2("value 2");
|
||||
|
||||
$this->assertEquals('{"field1":"value 1","field2":"value 2"}', $o->toJSON());
|
||||
|
||||
$oCopy = new SimpleModelTestClass();
|
||||
$oCopy->fromJson($o->toJSON());
|
||||
$this->assertEquals($o, $oCopy);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testSpecialChars()
|
||||
{
|
||||
$o = new SimpleModelTestClass();
|
||||
$o->setField1('value "1');
|
||||
$o->setField2("value 2");
|
||||
|
||||
$this->assertEquals('{"field1":"value \"1","field2":"value 2"}', $o->toJSON());
|
||||
|
||||
$oCopy = new SimpleModelTestClass();
|
||||
$oCopy->fromJson($o->toJSON());
|
||||
$this->assertEquals($o, $oCopy);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testNestedConversion()
|
||||
{
|
||||
$child = new SimpleModelTestClass();
|
||||
$child->setField1('value 1');
|
||||
$child->setField2("value 2");
|
||||
|
||||
$parent = new ContainerModelTestClass();
|
||||
$parent->setField1("parent");
|
||||
$parent->setNested1($child);
|
||||
|
||||
$this->assertEquals('{"field1":"parent","nested1":{"field1":"value 1","field2":"value 2"}}',
|
||||
$parent->toJSON());
|
||||
|
||||
$parentCopy = new ContainerModelTestClass();
|
||||
$parentCopy->fromJson($parent->toJSON());
|
||||
$this->assertEquals($parent, $parentCopy);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testListConversion()
|
||||
{
|
||||
$c1 = new SimpleModelTestClass();
|
||||
$c1->setField1("a")->setField2('value');
|
||||
|
||||
$c2 = new SimpleModelTestClass();
|
||||
$c1->setField1("another")->setField2('object');
|
||||
|
||||
$parent = new ListModelTestClass();
|
||||
$parent->setList1(array('simple', 'list', 'with', 'integer', 'keys'));
|
||||
$parent->setList2(array($c1, $c2));
|
||||
|
||||
$parentCopy = new ListModelTestClass();
|
||||
$parentCopy->fromJson($parent->toJSON());
|
||||
$this->assertEquals($parent, $parentCopy);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,28 @@
|
||||
<?php
|
||||
namespace PayPal\Test\Common;
|
||||
use PayPal\Common\PPModel;
|
||||
class SimpleClass extends PPModel {
|
||||
|
||||
public function setName($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
public function getName() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setDescription($desc) {
|
||||
$this->desc = $desc;
|
||||
}
|
||||
public function getDescription() {
|
||||
return $this->desc;
|
||||
}
|
||||
use PayPal\Common\PPModel;
|
||||
|
||||
class SimpleClass extends PPModel
|
||||
{
|
||||
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setDescription($description)
|
||||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
}
|
||||
@@ -2,25 +2,27 @@
|
||||
|
||||
use PayPal\Common\PPUserAgent;
|
||||
|
||||
class UserAgentTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testGetValue() {
|
||||
$ua = PPUserAgent::getValue("name", "version");
|
||||
list($id, $version, $features) = sscanf($ua, "PayPalSDK/%s %s (%s)");
|
||||
|
||||
// Check that we pass the useragent in the expected format
|
||||
$this->assertNotNull($id);
|
||||
$this->assertNotNull($version);
|
||||
$this->assertNotNull($features);
|
||||
|
||||
$this->assertEquals("name", $id);
|
||||
$this->assertEquals("version", $version);
|
||||
|
||||
// Check that we pass in these mininal features
|
||||
$this->assertThat($features, $this->stringContains("OS="));
|
||||
$this->assertThat($features, $this->stringContains("Bit="));
|
||||
$this->assertThat($features, $this->stringContains("Lang="));
|
||||
$this->assertThat($features, $this->stringContains("V="));
|
||||
$this->assertGreaterThan(5, count(explode(';', $features)));
|
||||
}
|
||||
class UserAgentTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testGetValue()
|
||||
{
|
||||
$ua = PPUserAgent::getValue("name", "version");
|
||||
list($id, $version, $features) = sscanf($ua, "PayPalSDK/%s %s (%s)");
|
||||
|
||||
// Check that we pass the useragent in the expected format
|
||||
$this->assertNotNull($id);
|
||||
$this->assertNotNull($version);
|
||||
$this->assertNotNull($features);
|
||||
|
||||
$this->assertEquals("name", $id);
|
||||
$this->assertEquals("version", $version);
|
||||
|
||||
// Check that we pass in these mininal features
|
||||
$this->assertThat($features, $this->stringContains("OS="));
|
||||
$this->assertThat($features, $this->stringContains("Bit="));
|
||||
$this->assertThat($features, $this->stringContains("Lang="));
|
||||
$this->assertThat($features, $this->stringContains("V="));
|
||||
$this->assertGreaterThan(5, count(explode(';', $features)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user