1<?php 2/** 3 * This file is part of the Tmdb PHP API created by Michael Roterman. 4 * 5 * For the full copyright and license information, please view the LICENSE 6 * file that was distributed with this source code. 7 * 8 * @package Tmdb 9 * @author Michael Roterman <michael@wtfz.net> 10 * @copyright (c) 2013, Michael Roterman 11 * @version 0.0.1 12 */ 13namespace Tmdb\Tests\Repository; 14 15use Tmdb\Api\Authentication; 16use Tmdb\HttpClient\Response; 17use Tmdb\Repository\AuthenticationRepository; 18use Tmdb\RequestToken; 19 20class AuthenticationRepositoryTest extends TestCase 21{ 22 /** 23 * @test 24 */ 25 public function shouldGetRequestToken() 26 { 27 $repository = $this->getRepositoryWithMockedHttpAdapter(); 28 29 $this->getAdapter()->expects($this->once()) 30 ->method('get') 31 ->with($this->getRequest('https://api.themoviedb.org/3/authentication/token/new', [])) 32 ; 33 34 $repository->getRequestToken(); 35 } 36 37 /** 38 * @test 39 */ 40 public function shouldGetNewSession() 41 { 42 $repository = $this->getRepositoryWithMockedHttpAdapter(); 43 44 $this->getAdapter() 45 ->expects($this->once()) 46 ->method('get') 47 ->with($this->getRequest('https://api.themoviedb.org/3/authentication/session/new', ['request_token' => 'request_token'])) 48 ; 49 50 $repository->getSessionToken(new RequestToken('request_token')); 51 } 52 53 /** 54 * @test 55 */ 56 public function shouldValidateRequestTokenWithLogin() 57 { 58 $repository = $this->getRepositoryWithMockedHttpAdapter(); 59 60 $response = new Response(200); 61 $response->setBody(json_encode([ 62 'success' => true, 63 'request_token' => 'abcdefghijklmnopqrstuvwxyz' 64 ])); 65 66 $this->getAdapter() 67 ->expects($this->any()) 68 ->method('get') 69 ->with($this->getRequest('https://api.themoviedb.org/3/authentication/token/validate_with_login', [ 70 'request_token' => 'request_token', 71 'username' => 'piet', 72 'password' => 'henk' 73 ])) 74 ->will($this->returnValue($response)) 75 ; 76 77 $repository->validateRequestTokenWithLogin(new RequestToken('request_token'), 'piet', 'henk'); 78 } 79 80 /** 81 * @test 82 */ 83 public function shouldGetGuestSession() 84 { 85 $repository = $this->getRepositoryWithMockedHttpAdapter(); 86 87 $this->getAdapter()->expects($this->once()) 88 ->method('get') 89 ->with($this->getRequest('https://api.themoviedb.org/3/authentication/guest_session/new', [])) 90 ; 91 92 $repository->getGuestSessionToken(); 93 } 94 95 /** 96 * @return Authentication 97 */ 98 protected function getApiClass() 99 { 100 return 'Tmdb\Api\Authentication'; 101 } 102 103 /** 104 * @return AuthenticationRepository 105 */ 106 protected function getRepositoryClass() 107 { 108 return 'Tmdb\Repository\AuthenticationRepository'; 109 } 110} 111