forked from LiveCarta/PayPal-PHP-SDK
Renaming Namespaces and Organizing Classes
- Updated OpenId classes to be in API namespace - Updated PP Naming Convention to PayPal Naming Convention - FormatConverter Class got its own namespace - Handlers are grouped in Handler namespace - Samples and Tests Updated Accordingly
This commit is contained in:
@@ -1,38 +1,38 @@
|
||||
<?php
|
||||
|
||||
// namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
use PayPal\Test\Constants;
|
||||
use PayPal\Core\PPConfigManager;
|
||||
use PayPal\Exception\PPConnectionException;
|
||||
|
||||
class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
public function testInvalidCredentials()
|
||||
{
|
||||
$this->setExpectedException('PayPal\Exception\PPConnectionException');
|
||||
$cred = new OAuthTokenCredential('dummy', 'secret');
|
||||
$this->assertNull($cred->getAccessToken(PPConfigManager::getInstance()->getConfigHashmap()));
|
||||
}
|
||||
}
|
||||
<?php
|
||||
|
||||
// namespace PayPal\Test\Common;
|
||||
|
||||
use PayPal\Auth\OAuthTokenCredential;
|
||||
use PayPal\Test\Constants;
|
||||
use PayPal\Core\PayPalConfigManager;
|
||||
use PayPal\Exception\PayPalConnectionException;
|
||||
|
||||
class OAuthTokenCredentialTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
public function testGetAccessToken()
|
||||
{
|
||||
$cred = new OAuthTokenCredential(Constants::CLIENT_ID, Constants::CLIENT_SECRET);
|
||||
$config = PayPalConfigManager::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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
public function testInvalidCredentials()
|
||||
{
|
||||
$this->setExpectedException('PayPal\Exception\PayPalConnectionException');
|
||||
$cred = new OAuthTokenCredential('dummy', 'secret');
|
||||
$this->assertNull($cred->getAccessToken(PayPalConfigManager::getInstance()->getConfigHashmap()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
use PayPal\Auth\Openid\PPOpenIdAddress;
|
||||
|
||||
/**
|
||||
* Test class for PPOpenIdAddress.
|
||||
*
|
||||
*/
|
||||
class PPOpenIdAddressTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/** @var PPOpenIdAddress */
|
||||
private $addr;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->addr = self::getTestData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
public static function getTestData()
|
||||
{
|
||||
$addr = new PPOpenIdAddress();
|
||||
$addr->setCountry("US")->setLocality("San Jose")
|
||||
->setPostalCode("95112")->setRegion("CA")
|
||||
->setStreetAddress("1, North 1'st street");
|
||||
return $addr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testSerializationDeserialization()
|
||||
{
|
||||
$addrCopy = new PPOpenIdAddress();
|
||||
$addrCopy->fromJson($this->addr->toJson());
|
||||
|
||||
$this->assertEquals($this->addr, $addrCopy);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
use PayPal\Auth\Openid\PPOpenIdError;
|
||||
|
||||
/**
|
||||
* Test class for PPOpenIdError.
|
||||
*
|
||||
*/
|
||||
class PPOpenIdErrorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/** @var PPOpenIdError */
|
||||
private $error;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->error = new PPOpenIdError();
|
||||
$this->error->setErrorDescription('error description')
|
||||
->setErrorUri('http://developer.paypal.com/api/error')
|
||||
->setError('VALIDATION_ERROR');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 testSerializationDeserialization()
|
||||
{
|
||||
$errorCopy = new PPOpenIdError();
|
||||
$errorCopy->fromJson($this->error->toJson());
|
||||
|
||||
$this->assertEquals($this->error, $errorCopy);
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
<?php
|
||||
use PayPal\Common\PPApiContext;
|
||||
use PayPal\Auth\Openid\PPOpenIdSession;
|
||||
|
||||
/**
|
||||
* Test class for PPOpenIdSession.
|
||||
*
|
||||
*/
|
||||
class PPOpenIdSessionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
private $context;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->context = new \PayPal\Rest\ApiContext();
|
||||
$this->context->setConfig(
|
||||
array(
|
||||
'acct1.ClientId' => 'DummyId',
|
||||
'acct1.ClientSecret' => 'A8VERY8SECRET8VALUE0',
|
||||
'mode' => 'live'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 testLoginUrlForMultipleScopes()
|
||||
{
|
||||
|
||||
$clientId = "AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd";
|
||||
$redirectUri = 'https://devtools-paypal.com/';
|
||||
$scope = array('this', 'that', 'and more');
|
||||
|
||||
$expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize";
|
||||
|
||||
$this->assertEquals($expectedBaseUrl . "?client_id=$clientId&response_type=code&scope=this+that+and+more+openid&redirect_uri=" . urlencode($redirectUri),
|
||||
PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope, $clientId), "Failed case - custom scope");
|
||||
|
||||
$scope = array();
|
||||
$this->assertEquals($expectedBaseUrl . "?client_id=$clientId&response_type=code&scope=openid+profile+address+email+phone+" . urlencode("https://uri.paypal.com/services/paypalattributes") . "+" . urlencode('https://uri.paypal.com/services/expresscheckout') . "&redirect_uri=" . urlencode($redirectUri),
|
||||
PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope, $clientId), "Failed case - default scope");
|
||||
|
||||
|
||||
$scope = array('openid');
|
||||
$this->assertEquals($expectedBaseUrl . "?client_id=$clientId&response_type=code&scope=openid&redirect_uri=" . urlencode($redirectUri),
|
||||
PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope, $clientId), "Failed case - openid scope");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testLoginWithCustomConfig()
|
||||
{
|
||||
|
||||
$redirectUri = 'http://mywebsite.com';
|
||||
$scope = array('this', 'that', 'and more');
|
||||
|
||||
$expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize";
|
||||
|
||||
$this->assertEquals($expectedBaseUrl . "?client_id=DummyId&response_type=code&scope=this+that+and+more+openid&redirect_uri=" . urlencode($redirectUri),
|
||||
PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope, "DummyId", null, null, $this->context), "Failed case - custom config");
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testLogoutWithCustomConfig()
|
||||
{
|
||||
|
||||
$redirectUri = 'http://mywebsite.com';
|
||||
$idToken = 'abc';
|
||||
|
||||
$expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/endsession";
|
||||
|
||||
$this->assertEquals($expectedBaseUrl . "?id_token=$idToken&redirect_uri=" . urlencode($redirectUri) . "&logout=true",
|
||||
PPOpenIdSession::getLogoutUrl($redirectUri, $idToken, $this->context), "Failed case - custom config");
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
<?php
|
||||
use PayPal\Auth\Openid\PPOpenIdTokeninfo;
|
||||
|
||||
/**
|
||||
* Test class for PPOpenIdTokeninfo.
|
||||
*
|
||||
*/
|
||||
class PPOpenIdTokeninfoTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/** @var PPOpenIdTokeninfo */
|
||||
public $token;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->token = new PPOpenIdTokeninfo();
|
||||
$this->token->setAccessToken("Access token")
|
||||
->setExpiresIn(900)
|
||||
->setRefreshToken("Refresh token")
|
||||
->setIdToken("id token")
|
||||
->setScope("openid address")
|
||||
->setTokenType("Bearer");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 testSerializationDeserialization()
|
||||
{
|
||||
$tokenCopy = new PPOpenIdTokeninfo();
|
||||
$tokenCopy->fromJson($this->token->toJson());
|
||||
|
||||
$this->assertEquals($this->token, $tokenCopy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @t1est
|
||||
* TODO: Fix Test. This test is disabled
|
||||
*/
|
||||
public function t1estOperations()
|
||||
{
|
||||
|
||||
$clientId = 'AQkquBDf1zctJOWGKWUEtKXm6qVhueUEMvXO_-MCI4DQQ4-LWvkDLIN2fGsd';
|
||||
$clientSecret = 'ELtVxAjhT7cJimnz5-Nsx9k2reTKSVfErNQF-CmrwJgxRtylkGTKlU4RvrX';
|
||||
|
||||
$params = array(
|
||||
'code' => '<FILLME>',
|
||||
'redirect_uri' => 'https://devtools-paypal.com/',
|
||||
'client_id' => $clientId,
|
||||
'client_secret' => $clientSecret
|
||||
);
|
||||
$accessToken = PPOpenIdTokeninfo::createFromAuthorizationCode($params);
|
||||
$this->assertNotNull($accessToken);
|
||||
|
||||
$params = array(
|
||||
'refresh_token' => $accessToken->getRefreshToken(),
|
||||
'client_id' => $clientId,
|
||||
'client_secret' => $clientSecret
|
||||
);
|
||||
$accessToken = $accessToken->createFromRefreshToken($params);
|
||||
$this->assertNotNull($accessToken);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
use PayPal\Auth\Openid\PPOpenIdUserinfo;
|
||||
|
||||
/**
|
||||
* Test class for PPOpenIdUserinfo.
|
||||
*
|
||||
*/
|
||||
class PPOpenIdUserinfoTest 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 testSerializationDeserialization()
|
||||
{
|
||||
$user = new PPOpenIdUserinfo();
|
||||
$user->setAccountType("PERSONAL")->setAgeRange("20-30")->setBirthday("1970-01-01")
|
||||
->setEmail("me@email.com")->setEmailVerified(true)
|
||||
->setFamilyName("Doe")->setMiddleName("A")->setGivenName("John")
|
||||
->setLocale("en-US")->setGender("male")->setName("John A Doe")
|
||||
->setPayerId("A-XZASASA")->setPhoneNumber("1-408-111-1111")
|
||||
->setPicture("http://gravatar.com/me.jpg")
|
||||
->setSub("me@email.com")->setUserId("userId")
|
||||
->setVerified(true)->setVerifiedAccount(true)
|
||||
->setZoneinfo("America/PST")->setLanguage('en_US')
|
||||
->setAddress(PPOpenIdAddressTest::getTestData());
|
||||
|
||||
$userCopy = new PPOpenIdUserinfo();
|
||||
$userCopy->fromJson($user->toJSON());
|
||||
|
||||
$this->assertEquals($user, $userCopy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function testInvalidParamUserInfoCall()
|
||||
{
|
||||
$this->setExpectedException('PayPal\Exception\PPConnectionException');
|
||||
PPOpenIdUserinfo::getUserinfo(array('access_token' => 'accessToken'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user