|
10 | 10 |
|
11 | 11 | namespace chillerlan\OAuthTest\Providers\Steam; |
12 | 12 |
|
| 13 | +use chillerlan\OAuth\Core\ProviderException; |
13 | 14 | use chillerlan\OAuth\Providers\Steam\SteamOpenID; |
14 | 15 | use chillerlan\OAuthTest\Providers\OAuthProviderTestAbstract; |
15 | 16 |
|
|
20 | 21 | */ |
21 | 22 | class SteamOpenIDTest extends OAuthProviderTestAbstract{ |
22 | 23 |
|
| 24 | + protected const ID_VALID = "ns:http://specs.openid.net/auth/2.0\x0ais_valid:true\x0a"; |
| 25 | + protected const ID_INVALID = "ns:http://specs.openid.net/auth/2.0\x0ais_valid:false\x0a"; |
| 26 | + |
23 | 27 | protected string $FQN = SteamOpenID::class; |
24 | 28 |
|
25 | 29 | protected array $testResponses = [ |
26 | | - '/steam/id' => "ns:http://specs.openid.net/auth/2.0\x0ais_valid:true\x0a", |
| 30 | + '/steam/id' => self::ID_VALID, |
| 31 | + '/steam/api/request' => '{"data":"such data! much wow!"}', |
27 | 32 | ]; |
28 | 33 |
|
29 | 34 | protected function setUp():void{ |
30 | 35 | parent::setUp(); // TODO: Change the autogenerated stub |
31 | 36 |
|
32 | 37 | $this->setProperty($this->provider, 'accessTokenURL', 'https://localhost/steam/id'); |
| 38 | + $this->setProperty($this->provider, 'apiURL', '/steam/api/request'); |
33 | 39 | } |
34 | 40 |
|
35 | 41 | public function testGetAuthURL():void{ |
@@ -63,4 +69,49 @@ public function testGetAccessToken():void{ |
63 | 69 |
|
64 | 70 | $this::assertSame('69420', $this->provider->getAccessToken($received)->accessToken); |
65 | 71 | } |
| 72 | + |
| 73 | + public function testParseTokenResponse():void{ |
| 74 | + $r = $this->responseFactory |
| 75 | + ->createResponse() |
| 76 | + ->withBody($this->streamFactory->createStream(self::ID_VALID)) |
| 77 | + ; |
| 78 | + |
| 79 | + $token = $this |
| 80 | + ->getMethod('parseTokenResponse') |
| 81 | + ->invokeArgs($this->provider, [$r]); |
| 82 | + |
| 83 | + $this::assertSame('SteamID', $token->accessToken); |
| 84 | + } |
| 85 | + |
| 86 | + public function testParseTokenResponseNoData():void{ |
| 87 | + $this->expectException(ProviderException::class); |
| 88 | + $this->expectExceptionMessage('unable to parse token response'); |
| 89 | + |
| 90 | + $this |
| 91 | + ->getMethod('parseTokenResponse') |
| 92 | + ->invokeArgs($this->provider, [$this->responseFactory->createResponse()]); |
| 93 | + } |
| 94 | + |
| 95 | + public function testParseTokenResponseInvalidID():void{ |
| 96 | + $this->expectException(ProviderException::class); |
| 97 | + $this->expectExceptionMessage('invalid id'); |
| 98 | + |
| 99 | + $r = $this->responseFactory |
| 100 | + ->createResponse() |
| 101 | + ->withBody($this->streamFactory->createStream(self::ID_INVALID)) |
| 102 | + ; |
| 103 | + |
| 104 | + $this |
| 105 | + ->getMethod('parseTokenResponse') |
| 106 | + ->invokeArgs($this->provider, [$r]); |
| 107 | + } |
| 108 | + |
| 109 | + // coverage |
| 110 | + public function testRequest():void{ |
| 111 | + $r = $this->provider->request(''); |
| 112 | + |
| 113 | + $this::assertSame('such data! much wow!', $this->responseJson($r)->data); |
| 114 | + } |
| 115 | + |
| 116 | + |
66 | 117 | } |
0 commit comments