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\Factory; 14 15use Tmdb\Factory\ListFactory; 16use Tmdb\Model\Lists; 17 18class ListFactoryTest extends TestCase 19{ 20 private $data; 21 22 /** 23 * @var Lists 24 */ 25 private $lists; 26 27 public function setUp() 28 { 29 $this->data = $this->loadByFile('lists/get.json'); 30 31 /** 32 * @var ListFactory $factory 33 */ 34 $factory = $this->getFactory(); 35 36 /** 37 * @var Lists $list 38 */ 39 $this->lists = $factory->create($this->data); 40 } 41 42 /** 43 * @test 44 */ 45 public function shouldBeAbleToSetFactories() 46 { 47 /** 48 * @var ListFactory $factory 49 */ 50 $factory = $this->getFactory(); 51 52 $class = new \stdClass(); 53 54 $factory->setImageFactory($class); 55 $factory->setListItemFactory($class); 56 57 $this->assertInstanceOf('stdClass', $factory->getImageFactory()); 58 $this->assertInstanceOf('stdClass', $factory->getListItemFactory()); 59 } 60 61 /** 62 * @test 63 */ 64 public function shouldBeFunctional() 65 { 66 $this->assertEquals('Travis Bell', $this->lists->getCreatedBy()); 67 $this->assertEquals('Here\'s my list of best picture winners for the Oscars. Thought it would be neat to see them all together. There\'s a lot of movies here I have never even heard of.', $this->lists->getDescription()); 68 $this->assertEquals(18, $this->lists->getFavoriteCount()); 69 $this->assertEquals('509ec17b19c2950a0600050d', $this->lists->getId()); 70 $this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->lists->getItems()); 71 $this->assertEquals(85, $this->lists->getItemCount()); 72 $this->assertEquals('en', $this->lists->getIso6391()); 73 $this->assertEquals('Best Picture Winners - The Academy Awards', $this->lists->getName()); 74 $this->assertEquals('/efBm2Nm2v5kQnO0w3hYcW6hVsJU.jpg', $this->lists->getPosterPath()); 75 $this->assertInstanceOf('Tmdb\Model\Image\PosterImage', $this->lists->getPosterImage()); 76 } 77 78 /** 79 * @test 80 */ 81 public function shouldGetItemStatus() 82 { 83 /** 84 * @var ListFactory $factory 85 */ 86 $factory = $this->getFactory(); 87 88 $result = $factory->createItemStatus($this->loadByFile('lists/item_status.json')); 89 90 $this->assertEquals('509ec17b19c2950a0600050d', $result->getId()); 91 $this->assertEquals(true, $result->getItemPresent()); 92 } 93 94 /** 95 * @test 96 */ 97 public function shouldCreateList() 98 { 99 /** 100 * @var ListFactory $factory 101 */ 102 $factory = $this->getFactory(); 103 104 $result = $factory->createResultWithListId($this->loadByFile('lists/list_create.json')); 105 106 $this->assertEquals(1, $result->getStatusCode()); 107 $this->assertEquals('Success', $result->getStatusMessage()); 108 $this->assertEquals('50941077760ee35e1500000c', $result->getListId()); 109 } 110 111 /** 112 * @test 113 */ 114 public function shouldAddItemToList() 115 { 116 /** 117 * @var ListFactory $factory 118 */ 119 $factory = $this->getFactory(); 120 121 $result = $factory->createResult($this->loadByFile('lists/add.json')); 122 123 $this->assertEquals(12, $result->getStatusCode()); 124 $this->assertEquals('The item/record was updated successfully', $result->getStatusMessage()); 125 } 126 127 /** 128 * @test 129 */ 130 public function shouldRemoveItemFromList() 131 { 132 /** 133 * @var ListFactory $factory 134 */ 135 $factory = $this->getFactory(); 136 137 $result = $factory->createResult($this->loadByFile('lists/remove.json')); 138 139 $this->assertEquals(12, $result->getStatusCode()); 140 $this->assertEquals('The item/record was updated successfully', $result->getStatusMessage()); 141 } 142 143 /** 144 * @test 145 */ 146 public function shouldRemoveList() 147 { 148 /** 149 * @var ListFactory $factory 150 */ 151 $factory = $this->getFactory(); 152 153 $result = $factory->createResult($this->loadByFile('lists/list_delete.json')); 154 155 $this->assertEquals(13, $result->getStatusCode()); 156 $this->assertEquals('The item/record was deleted successfully', $result->getStatusMessage()); 157 } 158 159 protected function getFactoryClass() 160 { 161 return 'Tmdb\Factory\ListFactory'; 162 } 163} 164