2 use PayPal\Common\PPApiContext;
3 use PayPal\Auth\Openid\PPOpenIdSession;
5 * Test class for PPOpenIdSession.
8 class PPOpenIdSessionTest extends \PHPUnit_Framework_TestCase {
12 * Sets up the fixture, for example, opens a network connection.
13 * This method is called before a test is executed.
15 protected function setUp()
17 $this->context = new PPApiContext(
19 'acct1.ClientId' => 'DummyId',
20 'acct1.ClientSecret' => 'A8VERY8SECRET8VALUE0',
27 * Tears down the fixture, for example, closes a network connection.
28 * This method is called after a test is executed.
30 protected function tearDown()
38 public function testLoginUrlForMultipleScopes() {
40 $redirectUri = 'http://mywebsite.com';
41 $scope = array('this', 'that', 'and more');
43 $expectedBaseUrl = "https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize";
45 $this->assertEquals($expectedBaseUrl . "?client_id=ProxyRP-01&response_type=code&scope=this+that+and+more+openid&redirect_uri=" . urlencode($redirectUri),
46 PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope), "Failed case - custom scope");
49 $this->assertEquals($expectedBaseUrl . "?client_id=ProxyRP-01&response_type=code&scope=openid+profile+address+email+phone+" . urlencode("https://uri.paypal.com/services/paypalattributes") . "&redirect_uri=" . urlencode($redirectUri),
50 PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope), "Failed case - default scope");
52 $scope = array('openid');
53 $this->assertEquals($expectedBaseUrl . "?client_id=ProxyRP-01&response_type=code&scope=openid&redirect_uri=" . urlencode($redirectUri),
54 PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope), "Failed case - openid scope");
60 public function testLoginWithCustomConfig() {
62 $redirectUri = 'http://mywebsite.com';
63 $scope = array('this', 'that', 'and more');
65 $expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize";
67 $this->assertEquals($expectedBaseUrl . "?client_id=DummyId&response_type=code&scope=this+that+and+more+openid&redirect_uri=" . urlencode($redirectUri),
68 PPOpenIdSession::getAuthorizationUrl($redirectUri, $scope, $this->context), "Failed case - custom config");
74 public function testLogoutWithCustomConfig() {
76 $redirectUri = 'http://mywebsite.com';
79 $expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/endsession";
81 $this->assertEquals($expectedBaseUrl . "?id_token=$idToken&redirect_uri=" . urlencode($redirectUri) . "&logout=true",
82 PPOpenIdSession::getLogoutUrl($redirectUri, $idToken, $this->context), "Failed case - custom config");