| 1 | <?php |
||
| 3 | class TokenTest extends PHPUnit_Framework_TestCase { |
||
| 4 | |||
| 5 | public function testEncode(){ |
||
| 6 | $results = Token::encode("TEST","1234"); |
||
| 7 | $this->assertEquals("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.IlRFU1Qi.zPCpn5hHX3CdtmvSDt_apcanyuDjGT9W8KcCgTMyrXE", $results); |
||
| 8 | } |
||
| 9 | |||
| 10 | public function testDecode(){ |
||
| 11 | |||
| 12 | try { |
||
| 13 | $results = Token::decode("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.IlRFU1Qi.zPCpn5hHX3CdtmvSDt_apcanyuDjGT9W8KcCgTMyrXE","1234"); |
||
| 14 | } catch(Exception $e) { |
||
| 15 | $this->fail("Exception throwed"); |
||
| 16 | } |
||
| 17 | |||
| 18 | $this->assertEquals("TEST", $results); |
||
| 19 | } |
||
| 20 | |||
| 21 | public function testWrongSecret(){ |
||
| 22 | |||
| 23 | try { |
||
| 24 | $results = Token::decode("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.IlRFU1Qi.zPCpn5hHX3CdtmvSDt_apcanyuDjGT9W8KcCgTMyrXE","41231"); |
||
| 25 | $this->fail("Expected exception 'WrongSecret' not thrown"); |
||
| 26 | } catch(Exception $e) { |
||
| 27 | $results = false; |
||
| 28 | } |
||
| 29 | |||
| 30 | $this->assertFalse($results); |
||
| 31 | } |
||
| 32 | |||
| 33 | public function testInvalidToken(){ |
||
| 34 | |||
| 35 | try { |
||
| 36 | $results = Token::decode("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.IlRFU1Qi","1234"); |
||
| 37 | $this->fail("Expected exception 'InvalidToken' not thrown"); |
||
| 38 | } catch(Exception $e) { |
||
| 39 | $results = false; |
||
| 40 | } |
||
| 41 | |||
| 42 | $this->assertFalse($results); |
||
| 43 | } |
||
| 44 | |||
| 45 | } |
||
| 46 | |||
| 47 |