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
15class ListRepositoryTest extends TestCase
16{
17    const LIST_ID  = '509fb10819c29510bb000675';
18    const MOVIE_ID = 150;
19
20    /**
21     * @test
22     */
23    public function shouldLoadList()
24    {
25        $repository = $this->getRepositoryWithMockedHttpAdapter();
26
27        $this->getAdapter()->expects($this->once())
28            ->method('get')
29            ->with($this->getRequest('https://api.themoviedb.org/3/list/' . self::LIST_ID))
30        ;
31
32        $repository->load(self::LIST_ID);
33    }
34
35    /**
36     * @test
37     */
38    public function shouldGetItemStatus()
39    {
40        $repository = $this->getRepositoryWithMockedHttpAdapter();
41
42        $this->getAdapter()->expects($this->once())
43            ->method('get')
44            ->with($this->getRequest('https://api.themoviedb.org/3/list/' . self::LIST_ID . '/item_status', ['movie_id' => self::MOVIE_ID]))
45        ;
46
47        $repository->getItemStatus(self::LIST_ID, self::MOVIE_ID);
48    }
49
50    /**
51     * @test
52     */
53    public function shouldCreateList()
54    {
55        $repository = $this->getRepositoryWithMockedHttpAdapter();
56
57        $this->getAdapter()->expects($this->once())
58            ->method('post')
59            ->with($this->getRequest('https://api.themoviedb.org/3/list', [], 'POST', [], ['name' => 'list-name', 'description' => 'list-description']))
60        ;
61
62        $repository->createList('list-name', 'list-description');
63    }
64
65    /**
66     * @test
67     */
68    public function shouldAdd()
69    {
70        $repository = $this->getRepositoryWithMockedHttpAdapter();
71
72        $this->getAdapter()->expects($this->once())
73            ->method('post')
74            ->with($this->getRequest('https://api.themoviedb.org/3/list/'.self::LIST_ID.'/add_item', [], 'POST', [], ['media_id' => self::MOVIE_ID]))
75        ;
76
77        $repository->add(self::LIST_ID, self::MOVIE_ID);
78    }
79
80    /**
81     * @test
82     */
83    public function shouldRemove()
84    {
85        $repository = $this->getRepositoryWithMockedHttpAdapter();
86
87        $this->getAdapter()->expects($this->once())
88            ->method('post')
89            ->with($this->getRequest('https://api.themoviedb.org/3/list/'.self::LIST_ID.'/remove_item', [], 'POST', [], ['media_id' => self::MOVIE_ID]))
90        ;
91
92        $repository->remove(self::LIST_ID, self::MOVIE_ID);
93    }
94
95    /**
96     * @test
97     */
98    public function shouldDeleteList()
99    {
100        $repository = $this->getRepositoryWithMockedHttpAdapter();
101
102        $this->getAdapter()->expects($this->once())
103            ->method('delete')
104            ->with($this->getRequest('https://api.themoviedb.org/3/list/' . self::LIST_ID, [], 'DELETE'))
105        ;
106
107        $repository->deleteList(self::LIST_ID);
108    }
109
110    /**
111     * @test
112     */
113    public function shouldClearList()
114    {
115        $repository = $this->getRepositoryWithMockedHttpAdapter();
116
117        $this->getAdapter()->expects($this->once())
118            ->method('post')
119            ->with($this->getRequest('https://api.themoviedb.org/3/list/'.self::LIST_ID.'/clear', ['confirm'=>'true'], 'POST'))
120        ;
121
122        $repository->clearList(self::LIST_ID, true);
123    }
124
125    protected function getApiClass()
126    {
127        return 'Tmdb\Api\Lists';
128    }
129
130    protected function getRepositoryClass()
131    {
132        return 'Tmdb\Repository\ListRepository';
133    }
134}
135