public function testParseSubBoard() { $boardContent = file_get_contents(__DIR__ . '/../InputSamples/forum-sub-2.html'); $boardIndex = ForumParser::parseSubBoards($boardContent); //Some sanity checking on the pages and main content $this->assertInternalType('array', $boardIndex); $this->assertGreaterThan(0, $boardIndex['pages']); $this->assertInternalType('array', $boardIndex['list']); $topic = $boardIndex['list'][0]; //Some sanity checking on the topic details $this->assertInstanceOf('Atarashii\\APIBundle\\Model\\Forum', $topic); $this->assertInternalType('int', $topic->getId()); $this->assertInternalType('string', $topic->getName()); $this->assertInternalType('string', $topic->getUsername()); $this->assertInternalType('int', $topic->getReplies()); $this->assertInstanceOf('\\DateTime', new \DateTime($topic->getTime())); //Some sanity checking on the reply class in the topic details $topicReply = $topic->getReply(); $this->assertInternalType('array', $topicReply); $this->assertInternalType('string', $topicReply['username']); $this->assertInstanceOf('\\DateTime', new \DateTime($topicReply['time'])); }
/** * Get the forum sub board of MAL. * * @param Request $request HTTP Request object * @param int $id The ID of the forum sub board as assigned by MyAnimeList * * @return View */ public function getForumSubBoardAction(Request $request, $id) { // http://myanimelist.net/forum/?subboard=#{id} $page = (int) $request->query->get('page'); if ($page <= 0) { $page = 1; } if ((int) $id == '') { return $this->view(array('error' => 'Invalid board ID'), 200); } $downloader = $this->get('atarashii_api.communicator'); try { $forumcontent = $downloader->fetch('/forum/?subboard=' . $id . '&show=' . ($page * 50 - 50)); } catch (Exception\CurlException $e) { return $this->view(array('error' => 'network-error'), 500); } if ($id == 1 || $id == 4) { $forumtopic = ForumParser::parseSubBoards($forumcontent); } else { $forumtopic = ForumParser::parseTopics($forumcontent); } $response = new Response(); $response->setPublic(); $response->setMaxAge(300); //5 minutes $response->headers->addCacheControlDirective('must-revalidate', true); $response->setEtag('forum/topic/' . $id); //Also, set "expires" header for caches that don't understand Cache-Control $date = new \DateTime(); $date->modify('+300 seconds'); //5 minutes $response->setExpires($date); $view = $this->view($forumtopic); $view->setResponse($response); $view->setStatusCode(200); return $view; }