forked from LiveCarta/PayPal-PHP-SDK
Updating model classes to use dynamic config - Moving common classes to sdk-core-php
This commit is contained in:
@@ -1,33 +1,34 @@
|
||||
<?php
|
||||
|
||||
// namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
use PayPal\Test\Constants;
|
||||
|
||||
class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testGetAccessToken() {
|
||||
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
|
||||
|
||||
$token = $cred->getAccessToken();
|
||||
$this->assertNotNull($token);
|
||||
|
||||
// Check that we get the same token when issuing a new call before token expiry
|
||||
$newToken = $cred->getAccessToken();
|
||||
$this->assertNotNull($newToken);
|
||||
$this->assertEquals($token, $newToken);
|
||||
|
||||
// sleep(60*8);
|
||||
// $newToken = $cred->getAccessToken();
|
||||
// $this->assertNotNull($newToken);
|
||||
// $this->assertNotEqual($token, $newToken);
|
||||
|
||||
}
|
||||
|
||||
public function testInvalidCredentials() {
|
||||
$this->setExpectedException('\PPConnectionException');
|
||||
$cred = new OAuthTokenCredential('dummy', 'secret');
|
||||
$this->assertNull($cred->getAccessToken());
|
||||
}
|
||||
<?php
|
||||
|
||||
// namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
use PayPal\Test\Constants;
|
||||
|
||||
class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testGetAccessToken() {
|
||||
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
|
||||
$config = \PPConfigManager::getInstance()->getConfigHashmap();
|
||||
|
||||
$token = $cred->getAccessToken($config);
|
||||
$this->assertNotNull($token);
|
||||
|
||||
// Check that we get the same token when issuing a new call before token expiry
|
||||
$newToken = $cred->getAccessToken($config);
|
||||
$this->assertNotNull($newToken);
|
||||
$this->assertEquals($token, $newToken);
|
||||
|
||||
// sleep(60*8);
|
||||
// $newToken = $cred->getAccessToken();
|
||||
// $this->assertNotNull($newToken);
|
||||
// $this->assertNotEqual($token, $newToken);
|
||||
|
||||
}
|
||||
|
||||
public function testInvalidCredentials() {
|
||||
$this->setExpectedException('\PPConnectionException');
|
||||
$cred = new OAuthTokenCredential('dummy', 'secret');
|
||||
$this->assertNull($cred->getAccessToken(\PPConfigManager::getInstance()->getConfigHashmap()));
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,21 @@
|
||||
<?php
|
||||
// namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Common\ArrayUtil;
|
||||
|
||||
class ArrayUtilTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testIsAssocArray() {
|
||||
|
||||
$arr = array(1, 2, 3);
|
||||
$this->assertEquals(false, ArrayUtil::isAssocArray($arr));
|
||||
|
||||
$arr = array(
|
||||
'name' => 'John Doe',
|
||||
'City' => 'San Jose'
|
||||
);
|
||||
$this->assertEquals(true, ArrayUtil::isAssocArray($arr));
|
||||
|
||||
$arr[] = 'CA';
|
||||
$this->assertEquals(false, ArrayUtil::isAssocArray($arr));
|
||||
}
|
||||
}
|
||||
<?php
|
||||
// namespace PayPal\Test\Common;
|
||||
|
||||
|
||||
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,135 +1,138 @@
|
||||
<?php
|
||||
|
||||
// namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Common\Model;
|
||||
|
||||
class SimpleClass extends Model {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
class ArrayClass extends Model {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function setTags($tags) {
|
||||
if(!is_array($tags)) {
|
||||
$tags = array($tags);
|
||||
}
|
||||
$this->tags = $tags;
|
||||
}
|
||||
public function getTags() {
|
||||
return $this->tags;
|
||||
}
|
||||
}
|
||||
|
||||
class NestedClass extends Model {
|
||||
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ArrayClass $info
|
||||
*/
|
||||
public function setInfo($info) {
|
||||
$this->info = $info;
|
||||
}
|
||||
public function getInfo() {
|
||||
return $this->info;
|
||||
}
|
||||
}
|
||||
|
||||
class ChildClass extends SimpleClass {
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
// namespace PayPal\Test\Common;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
class ArrayClass 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;
|
||||
}
|
||||
|
||||
public function setTags($tags) {
|
||||
if(!is_array($tags)) {
|
||||
$tags = array($tags);
|
||||
}
|
||||
$this->tags = $tags;
|
||||
}
|
||||
public function getTags() {
|
||||
return $this->tags;
|
||||
}
|
||||
}
|
||||
|
||||
class NestedClass extends \PPModel {
|
||||
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ArrayClass $info
|
||||
*/
|
||||
public function setInfo($info) {
|
||||
$this->info = $info;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return ArrayClass
|
||||
*/
|
||||
public function getInfo() {
|
||||
return $this->info;
|
||||
}
|
||||
}
|
||||
|
||||
class ChildClass extends SimpleClass {
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
<?php
|
||||
|
||||
use PayPal\Common\UserAgent;
|
||||
|
||||
class UserAgentTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
public function testGetValue() {
|
||||
$ua = UserAgent::getValue();
|
||||
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);
|
||||
|
||||
// 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)));
|
||||
}
|
||||
<?php
|
||||
|
||||
use PayPal\Common\UserAgent;
|
||||
|
||||
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