1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @category OAuth |
5
|
|
|
* @package Tests |
6
|
|
|
* @author David Desberg <[email protected]> |
7
|
|
|
* @author Hannes Van De Vreken <[email protected]> |
8
|
|
|
* @copyright Copyright (c) 2012 The authors |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace OAuth\Unit\Common\Storage; |
13
|
|
|
|
14
|
|
|
use \OAuth\OAuth2\Token\StdOAuth2Token; |
15
|
|
|
|
16
|
|
|
abstract class StorageTest extends \PHPUnit_Framework_TestCase |
17
|
|
|
{ |
18
|
|
|
protected $storage; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Check that the token gets properly stored. |
22
|
|
|
*/ |
23
|
|
|
public function testStorage() |
24
|
|
|
{ |
25
|
|
|
// arrange |
26
|
|
|
$service_1 = 'Facebook'; |
27
|
|
|
$service_2 = 'Foursquare'; |
28
|
|
|
|
29
|
|
|
$token_1 = new StdOAuth2Token('access_1', 'refresh_1', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); |
30
|
|
|
$token_2 = new StdOAuth2Token('access_2', 'refresh_2', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); |
31
|
|
|
|
32
|
|
|
// act |
33
|
|
|
$this->storage->storeAccessToken($service_1, $token_1); |
34
|
|
|
$this->storage->storeAccessToken($service_2, $token_2); |
35
|
|
|
|
36
|
|
|
// assert |
37
|
|
|
$extraParams = $this->storage->retrieveAccessToken($service_1)->getExtraParams(); |
38
|
|
|
$this->assertEquals('param', $extraParams['extra']); |
39
|
|
|
$this->assertEquals($token_1, $this->storage->retrieveAccessToken($service_1)); |
40
|
|
|
$this->assertEquals($token_2, $this->storage->retrieveAccessToken($service_2)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Test hasAccessToken. |
45
|
|
|
*/ |
46
|
|
|
public function testHasAccessToken() |
47
|
|
|
{ |
48
|
|
|
// arrange |
49
|
|
|
$service = 'Facebook'; |
50
|
|
|
$this->storage->clearToken($service); |
51
|
|
|
|
52
|
|
|
// act |
53
|
|
|
// assert |
54
|
|
|
$this->assertFalse($this->storage->hasAccessToken($service)); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Check that the token gets properly deleted. |
59
|
|
|
*/ |
60
|
|
|
public function testStorageClears() |
61
|
|
|
{ |
62
|
|
|
// arrange |
63
|
|
|
$service = 'Facebook'; |
64
|
|
|
$token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); |
65
|
|
|
|
66
|
|
|
// act |
67
|
|
|
$this->storage->storeAccessToken($service, $token); |
68
|
|
|
$this->storage->clearToken($service); |
69
|
|
|
|
70
|
|
|
// assert |
71
|
|
|
$this->setExpectedException('OAuth\Common\Storage\Exception\TokenNotFoundException'); |
72
|
|
|
$this->storage->retrieveAccessToken($service); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|