Exemplo n.º 1
0
 public function testParseAnime()
 {
     $castContents = file_get_contents(__DIR__ . '/../InputSamples/anime-1887-cast.html');
     $castList = CastParser::parse($castContents);
     $this->assertInternalType('array', $castList);
     $characterList = $castList['Characters'];
     //Kagami
     foreach ($characterList as $characterItem) {
         if ($characterItem->getId() == 2171) {
             $character = $characterItem;
             break;
         }
     }
     $staffList = $castList['Staff'];
     //Yasuhiro Takemoto
     foreach ($staffList as $staffItem) {
         if ($staffItem->getId() == 6771) {
             $staff = $staffItem;
             break;
         }
     }
     $actorList = $characterItem->getActors();
     //Emiri Katou
     foreach ($actorList as $actorItem) {
         if ($actorItem->getId() == 52) {
             $actor = $actorItem;
             break;
         }
     }
     $this->assertInstanceOf('Atarashii\\APIBundle\\Model\\Cast', $character);
     $this->assertInstanceOf('Atarashii\\APIBundle\\Model\\Cast', $staff);
     $this->assertInstanceOf('Atarashii\\APIBundle\\Model\\Actor', $actor);
     //Character Tests
     $this->assertEquals(2171, $character->getId());
     $this->assertEquals('Hiiragi, Kagami', $character->getName());
     $this->assertEquals('Main', $character->getRole());
     $this->assertStringStartsWith('https://myanimelist.cdn-dena.com/images/characters/', $character->getImage());
     //Actor Tests
     $this->assertEquals(52, $actor->getId());
     $this->assertEquals('Katou, Emiri', $actor->getActorName());
     $this->assertStringStartsWith('https://myanimelist.cdn-dena.com/images/voiceactors/', $actor->getActorImage());
     $this->assertEquals('Japanese', $actor->getActorLanguage());
     //Staff Tests
     $this->assertEquals(6771, $staff->getId());
     $this->assertEquals('Takemoto, Yasuhiro', $staff->getName());
     $this->assertContains('Director', $staff->getRank());
     $this->assertStringStartsWith('https://myanimelist.cdn-dena.com/images/voiceactors/', $staff->getImage());
     //Note the path is correct. MAL re-uses this for other non-VA staff images.
 }
 /**
  * Get the cast of an anime or manga.
  *
  * @param int    $id          The ID of the anime or manga as assigned by MyAnimeList
  * @param string $requestType The anime or manga request string
  *
  * @return View
  */
 public function getCastAction($id, $requestType)
 {
     // http://myanimelist.net/anime/#{id}/ /characters
     // http://myanimelist.net/manga/#{id}/ /characters
     $downloader = $this->get('atarashii_api.communicator');
     try {
         $details = $downloader->fetch('/' . $requestType . '/' . $id . '/_/characters');
     } catch (Exception\CurlException $e) {
         return $this->view(array('error' => 'network-error'), 500);
     }
     if (strpos($details, 'No characters') !== false) {
         return $this->view(array('error' => 'not-found'), 200);
     } else {
         $cast = CastParser::parse($details);
         $response = new Response();
         $response->setPublic();
         $response->setMaxAge(86400);
         //One day
         $response->headers->addCacheControlDirective('must-revalidate', true);
         $response->setEtag($requestType . '/cast/' . $id);
         //Also, set "expires" header for caches that don't understand Cache-Control
         $date = new \DateTime();
         $date->modify('+86400 seconds');
         //One day
         $response->setExpires($date);
         $view = $this->view($cast);
         $view->setResponse($response);
         $view->setStatusCode(200);
         return $view;
     }
 }