TokenResponseTest.php (3042B)
1 <?php 2 3 /** 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 namespace fkooman\OAuth\Client; 19 20 class TokenResponseTest extends \PHPUnit_Framework_TestCase 21 { 22 public function testSimple() 23 { 24 $t = new TokenResponse( 25 array( 26 "access_token" => "foo", 27 "token_type" => "Bearer", 28 "expires_in" => 5, 29 "scope" => "foo", 30 "refresh_token" => "bar", 31 "unsupported_key" => "foo", 32 ) 33 ); 34 $this->assertEquals("foo", $t->getAccessToken()); 35 $this->assertEquals("Bearer", $t->getTokenType()); 36 $this->assertEquals(5, $t->getExpiresIn()); 37 $this->assertEquals("bar", $t->getRefreshToken()); 38 $this->assertEquals("foo", $t->getScope()->toString()); 39 } 40 41 public function testScope() 42 { 43 $t = new TokenResponse( 44 array( 45 "access_token" => "foo", 46 "token_type" => "Bearer", 47 "scope" => "foo bar baz baz", 48 ) 49 ); 50 // scope will be sorted de-duplicated string space separated 51 $this->assertEquals("bar baz foo", $t->getScope()->toString()); 52 } 53 54 /** 55 * @expectedException fkooman\OAuth\Client\Exception\TokenResponseException 56 * @expectedExceptionMessage scope must be non empty 57 */ 58 public function testNullScope() 59 { 60 $t = new TokenResponse( 61 array( 62 "access_token" => "foo", 63 "token_type" => "Bearer", 64 "scope" => null, 65 ) 66 ); 67 } 68 69 /** 70 * @expectedException fkooman\OAuth\Client\Exception\TokenResponseException 71 * @expectedExceptionMessage scope must be non empty 72 */ 73 public function testEmptyScope() 74 { 75 $t = new TokenResponse( 76 array( 77 "access_token" => "foo", 78 "token_type" => "Bearer", 79 "scope" => "", 80 ) 81 ); 82 } 83 84 /** 85 * @expectedException fkooman\OAuth\Client\Exception\TokenResponseException 86 * @expectedExceptionMessage expires_in needs to be a positive integer 87 */ 88 public function testNegativeExpiresIn() 89 { 90 $t = new TokenResponse( 91 array( 92 "access_token" => "foo", 93 "token_type" => "Bearer", 94 "expires_in" => -5, 95 ) 96 ); 97 } 98 }