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,5 +1,6 @@
|
||||
<?php
|
||||
use PayPal\Core\PPCredentialManager;
|
||||
|
||||
/**
|
||||
* Test class for PPCredentialManager.
|
||||
*
|
||||
@@ -7,68 +8,70 @@ use PayPal\Core\PPCredentialManager;
|
||||
*/
|
||||
class PPCredentialManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var PPCredentialManager
|
||||
*/
|
||||
protected $object;
|
||||
/**
|
||||
* @var PPCredentialManager
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
private $config = array(
|
||||
'acct1.ClientId' => 'client-id',
|
||||
'acct1.ClientSecret' => 'client-secret',
|
||||
'http.ConnectionTimeOut' => '30',
|
||||
'http.Retry' => '5',
|
||||
'service.RedirectURL' => 'https://www.sandbox.paypal.com/webscr&cmd=',
|
||||
'service.DevCentralURL' => 'https://developer.paypal.com',
|
||||
'service.EndPoint.IPN' => 'https://www.sandbox.paypal.com/cgi-bin/webscr',
|
||||
'service.EndPoint.AdaptivePayments' => 'https://svcs.sandbox.paypal.com/',
|
||||
'service.SandboxEmailAddress' => 'platform_sdk_seller@gmail.com',
|
||||
'log.FileName' => 'PayPal.log',
|
||||
'log.LogLevel' => 'INFO',
|
||||
'log.LogEnabled' => '1',
|
||||
);
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = PPCredentialManager::getInstance($this->config);
|
||||
}
|
||||
private $config = array(
|
||||
'acct1.ClientId' => 'client-id',
|
||||
'acct1.ClientSecret' => 'client-secret',
|
||||
'http.ConnectionTimeOut' => '30',
|
||||
'http.Retry' => '5',
|
||||
'service.RedirectURL' => 'https://www.sandbox.paypal.com/webscr&cmd=',
|
||||
'service.DevCentralURL' => 'https://developer.paypal.com',
|
||||
'service.EndPoint.IPN' => 'https://www.sandbox.paypal.com/cgi-bin/webscr',
|
||||
'service.EndPoint.AdaptivePayments' => 'https://svcs.sandbox.paypal.com/',
|
||||
'service.SandboxEmailAddress' => 'platform_sdk_seller@gmail.com',
|
||||
'log.FileName' => 'PayPal.log',
|
||||
'log.LogLevel' => 'INFO',
|
||||
'log.LogEnabled' => '1',
|
||||
);
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = PPCredentialManager::getInstance($this->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testGetInstance()
|
||||
{
|
||||
$instance = $this->object->getInstance($this->config);
|
||||
$this->assertTrue($instance instanceof PPCredentialManager);
|
||||
}
|
||||
/**
|
||||
* 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 testGetSpecificCredentialObject()
|
||||
{
|
||||
$cred = $this->object->getCredentialObject('acct1');
|
||||
$this->assertNotNull($cred);
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testGetInstance()
|
||||
{
|
||||
$instance = $this->object->getInstance($this->config);
|
||||
$this->assertTrue($instance instanceof PPCredentialManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testGetSpecificCredentialObject()
|
||||
{
|
||||
$cred = $this->object->getCredentialObject('acct1');
|
||||
$this->assertNotNull($cred);
|
||||
$this->assertAttributeEquals('client-id', 'clientId', $cred);
|
||||
$this->assertAttributeEquals('client-secret', 'clientSecret', $cred);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @after testGetDefaultCredentialObject
|
||||
*
|
||||
* @throws \PayPal\Exception\PPInvalidCredentialException
|
||||
*/
|
||||
public function testSetCredentialObject() {
|
||||
public function testSetCredentialObject()
|
||||
{
|
||||
$authObject = $this->getMockBuilder('\Paypal\Auth\OAuthTokenCredential')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -83,7 +86,8 @@ class PPCredentialManagerTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @throws \PayPal\Exception\PPInvalidCredentialException
|
||||
*/
|
||||
public function testSetCredentialObjectWithUserId() {
|
||||
public function testSetCredentialObjectWithUserId()
|
||||
{
|
||||
$authObject = $this->getMockBuilder('\Paypal\Auth\OAuthTokenCredential')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -97,7 +101,8 @@ class PPCredentialManagerTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @throws \PayPal\Exception\PPInvalidCredentialException
|
||||
*/
|
||||
public function testSetCredentialObjectWithoutDefault() {
|
||||
public function testSetCredentialObjectWithoutDefault()
|
||||
{
|
||||
$authObject = $this->getMockBuilder('\Paypal\Auth\OAuthTokenCredential')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -107,39 +112,39 @@ class PPCredentialManagerTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testGetInvalidCredentialObject()
|
||||
{
|
||||
$this->setExpectedException('PayPal\Exception\PPInvalidCredentialException');
|
||||
$cred = $this->object->getCredentialObject('invalid_biz_api1.gmail.com');
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testGetInvalidCredentialObject()
|
||||
{
|
||||
$this->setExpectedException('PayPal\Exception\PPInvalidCredentialException');
|
||||
$cred = $this->object->getCredentialObject('invalid_biz_api1.gmail.com');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testGetDefaultCredentialObject()
|
||||
{
|
||||
*/
|
||||
public function testGetDefaultCredentialObject()
|
||||
{
|
||||
$cred = $this->object->getCredentialObject();
|
||||
$this->assertNotNull($cred);
|
||||
$this->assertAttributeEquals('client-id', 'clientId', $cred);
|
||||
$this->assertAttributeEquals('client-secret', 'clientSecret', $cred);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testGetRestCredentialObject() {
|
||||
$cred = $this->object->getCredentialObject('acct1');
|
||||
|
||||
$this->assertNotNull($cred);
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testGetRestCredentialObject()
|
||||
{
|
||||
$cred = $this->object->getCredentialObject('acct1');
|
||||
|
||||
$this->assertAttributeEquals($this->config['acct1.ClientId'], 'clientId', $cred);
|
||||
$this->assertNotNull($cred);
|
||||
|
||||
$this->assertAttributeEquals($this->config['acct1.ClientId'], 'clientId', $cred);
|
||||
|
||||
$this->assertAttributeEquals($this->config['acct1.ClientSecret'], 'clientSecret', $cred);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
<?php
|
||||
use PayPal\Core\PPHttpConfig;
|
||||
|
||||
/**
|
||||
* Test class for PPAPIService.
|
||||
*
|
||||
*/
|
||||
class PPHttpConfigTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
|
||||
protected $object;
|
||||
|
||||
|
||||
private $config = array(
|
||||
'http.ConnectionTimeOut' => '30',
|
||||
'http.Retry' => '5' ,
|
||||
'http.ConnectionTimeOut' => '30',
|
||||
'http.Retry' => '5',
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -20,7 +21,7 @@ class PPHttpConfigTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,87 +36,88 @@ class PPHttpConfigTest extends PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*/
|
||||
public function testHeaderFunctions()
|
||||
{
|
||||
$o = new PPHttpConfig();
|
||||
$o->addHeader('key1', 'value1');
|
||||
$o->addHeader('key2', 'value');
|
||||
$o->addHeader('key2', 'overwritten');
|
||||
|
||||
$this->assertEquals(2, count($o->getHeaders()));
|
||||
$this->assertEquals('overwritten', $o->getHeader('key2'));
|
||||
$this->assertNull($o->getHeader('key3'));
|
||||
|
||||
$o = new PPHttpConfig();
|
||||
$o->addHeader('key1', 'value1');
|
||||
$o->addHeader('key2', 'value');
|
||||
$o->addHeader('key2', 'and more', false);
|
||||
|
||||
$this->assertEquals(2, count($o->getHeaders()));
|
||||
$this->assertEquals('value;and more', $o->getHeader('key2'));
|
||||
|
||||
$o->removeHeader('key2');
|
||||
$this->assertEquals(1, count($o->getHeaders()));
|
||||
$this->assertNull($o->getHeader('key2'));
|
||||
{
|
||||
$o = new PPHttpConfig();
|
||||
$o->addHeader('key1', 'value1');
|
||||
$o->addHeader('key2', 'value');
|
||||
$o->addHeader('key2', 'overwritten');
|
||||
|
||||
$this->assertEquals(2, count($o->getHeaders()));
|
||||
$this->assertEquals('overwritten', $o->getHeader('key2'));
|
||||
$this->assertNull($o->getHeader('key3'));
|
||||
|
||||
$o = new PPHttpConfig();
|
||||
$o->addHeader('key1', 'value1');
|
||||
$o->addHeader('key2', 'value');
|
||||
$o->addHeader('key2', 'and more', false);
|
||||
|
||||
$this->assertEquals(2, count($o->getHeaders()));
|
||||
$this->assertEquals('value;and more', $o->getHeader('key2'));
|
||||
|
||||
$o->removeHeader('key2');
|
||||
$this->assertEquals(1, count($o->getHeaders()));
|
||||
$this->assertNull($o->getHeader('key2'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testCurlOpts()
|
||||
{
|
||||
$o = new PPHttpConfig();
|
||||
$o->setCurlOptions(array('k' => 'v'));
|
||||
|
||||
$curlOpts = $o->getCurlOptions();
|
||||
$this->assertEquals(1, count($curlOpts));
|
||||
$this->assertEquals('v', $curlOpts['k']);
|
||||
$o = new PPHttpConfig();
|
||||
$o->setCurlOptions(array('k' => 'v'));
|
||||
|
||||
$curlOpts = $o->getCurlOptions();
|
||||
$this->assertEquals(1, count($curlOpts));
|
||||
$this->assertEquals('v', $curlOpts['k']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testUserAgent()
|
||||
{
|
||||
$ua = 'UAString';
|
||||
$o = new PPHttpConfig();
|
||||
$o->setUserAgent($ua);
|
||||
|
||||
$curlOpts= $o->getCurlOptions();
|
||||
$this->assertEquals($ua, $curlOpts[CURLOPT_USERAGENT]);
|
||||
$ua = 'UAString';
|
||||
$o = new PPHttpConfig();
|
||||
$o->setUserAgent($ua);
|
||||
|
||||
$curlOpts = $o->getCurlOptions();
|
||||
$this->assertEquals($ua, $curlOpts[CURLOPT_USERAGENT]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testSSLOpts()
|
||||
{
|
||||
$sslCert = '../cacert.pem';
|
||||
$sslPass = 'passPhrase';
|
||||
|
||||
$o = new PPHttpConfig();
|
||||
$o->setSSLCert($sslCert, $sslPass);
|
||||
|
||||
$curlOpts= $o->getCurlOptions();
|
||||
$this->assertArrayHasKey(CURLOPT_SSLCERT, $curlOpts);
|
||||
$this->assertEquals($sslPass, $curlOpts[CURLOPT_SSLCERTPASSWD]);
|
||||
$sslCert = '../cacert.pem';
|
||||
$sslPass = 'passPhrase';
|
||||
|
||||
$o = new PPHttpConfig();
|
||||
$o->setSSLCert($sslCert, $sslPass);
|
||||
|
||||
$curlOpts = $o->getCurlOptions();
|
||||
$this->assertArrayHasKey(CURLOPT_SSLCERT, $curlOpts);
|
||||
$this->assertEquals($sslPass, $curlOpts[CURLOPT_SSLCERTPASSWD]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testProxyOpts()
|
||||
{
|
||||
$proxy = 'http://me:secret@hostname:8081';
|
||||
|
||||
$o = new PPHttpConfig();
|
||||
$o->setHttpProxy($proxy);
|
||||
|
||||
$curlOpts= $o->getCurlOptions();
|
||||
$this->assertEquals('hostname:8081', $curlOpts[CURLOPT_PROXY]);
|
||||
$this->assertEquals('me:secret', $curlOpts[CURLOPT_PROXYUSERPWD]);
|
||||
|
||||
$this->setExpectedException('PayPal\Exception\PPConfigurationException');
|
||||
$o->setHttpProxy('invalid string');
|
||||
$proxy = 'http://me:secret@hostname:8081';
|
||||
|
||||
$o = new PPHttpConfig();
|
||||
$o->setHttpProxy($proxy);
|
||||
|
||||
$curlOpts = $o->getCurlOptions();
|
||||
$this->assertEquals('hostname:8081', $curlOpts[CURLOPT_PROXY]);
|
||||
$this->assertEquals('me:secret', $curlOpts[CURLOPT_PROXYUSERPWD]);
|
||||
|
||||
$this->setExpectedException('PayPal\Exception\PPConfigurationException');
|
||||
$o->setHttpProxy('invalid string');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
use PayPal\Core\PPLoggingManager;
|
||||
|
||||
/**
|
||||
* Test class for PPLoggingManager.
|
||||
*
|
||||
@@ -17,7 +18,7 @@ class PPLoggingManagerTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new PPLoggingManager('InvoiceTest');
|
||||
$this->object = PPLoggingManager::getInstance('InvoiceTest');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ class PPLoggingManagerTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testError()
|
||||
{
|
||||
$this->object->error('Test Error Message');
|
||||
$this->object->error('Test Error Message');
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +43,7 @@ class PPLoggingManagerTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testWarning()
|
||||
{
|
||||
$this->object->warning('Test Warning Message');
|
||||
$this->object->warning('Test Warning Message');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +59,8 @@ class PPLoggingManagerTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testFine()
|
||||
{
|
||||
$this->object->fine('Test fine Message');
|
||||
$this->object->fine('Test fine Message');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user