46e84d1539c65f24c24adeeccfac68809b107058
[WP-Plugins/glm-member-db-registrations.git] /
1 <?php
2 use PayPal\Common\PPApiContext;
3 use PayPal\Auth\Openid\PPOpenIdSession;
4 /**
5  * Test class for PPOpenIdSession.
6  *
7  */
8 class PPOpenIdSessionTest extends \PHPUnit_Framework_TestCase {
9         
10         private $context;
11         /**
12          * Sets up the fixture, for example, opens a network connection.
13          * This method is called before a test is executed.
14          */
15         protected function setUp()
16         {
17                 $this->context = new PPApiContext(
18                         array(
19                                 'acct1.ClientId' => 'DummyId',
20                                 'acct1.ClientSecret' => 'A8VERY8SECRET8VALUE0',
21                                 'mode' => 'live'
22                         )
23                 );
24         }
25         
26         /**
27          * Tears down the fixture, for example, closes a network connection.
28          * This method is called after a test is executed.
29          */
30         protected function tearDown()
31         {
32         }
33         
34
35         /**
36          * @test
37          */
38         public function testLoginUrlForMultipleScopes() {
39         
40                 $redirectUri = 'http://mywebsite.com';
41                 $scope = array('this', 'that', 'and more');
42         
43                 $expectedBaseUrl = "https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize";
44         
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");
47         
48                 $scope = array();
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");
51         
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");
55         }
56         
57         /**
58          * @test
59          */
60         public function testLoginWithCustomConfig() {
61         
62                 $redirectUri = 'http://mywebsite.com';
63                 $scope = array('this', 'that', 'and more');
64         
65                 $expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize";
66                         
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");
69         }
70         
71         /**
72          * @test
73          */
74         public function testLogoutWithCustomConfig() {
75                 
76                 $redirectUri = 'http://mywebsite.com';
77                 $idToken = 'abc';
78                 
79                 $expectedBaseUrl = "https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/endsession";
80                         
81                 $this->assertEquals($expectedBaseUrl . "?id_token=$idToken&redirect_uri=" . urlencode($redirectUri) . "&logout=true",
82                                 PPOpenIdSession::getLogoutUrl($redirectUri, $idToken, $this->context), "Failed case - custom config");
83         }
84 }