Updated Identity Support from SDK Core

- Moved PPModels required for Identity Support
This commit is contained in:
japatel
2014-10-14 14:15:41 -05:00
parent 0cb302326a
commit dc2ac0fd63
36 changed files with 2652 additions and 587 deletions

View File

@@ -0,0 +1,50 @@
<?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);
}
}

View File

@@ -0,0 +1,45 @@
<?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);
}
}

View File

@@ -0,0 +1,93 @@
<?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");
}
}

View File

@@ -0,0 +1,76 @@
<?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);
}
}

View File

@@ -0,0 +1,60 @@
<?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'));
}
}