From 254afc990ea39354a1005d238ff03139d46f1535 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 18 Nov 2015 10:31:42 -0500 Subject: [PATCH] More test coverage --- src/Aviat/AnimeClient/Model/Anime.php | 1 + src/Aviat/AnimeClient/Model/Manga.php | 3 +- tests/AnimeClient/AnimeClientTest.php | 42 ++++++++++++++++++++++ tests/AnimeClient/Model/MangaModelTest.php | 30 ++++++++++++++++ tests/mocks.php | 4 +-- 5 files changed, 77 insertions(+), 3 deletions(-) diff --git a/src/Aviat/AnimeClient/Model/Anime.php b/src/Aviat/AnimeClient/Model/Anime.php index 6fe27482..bf71634b 100644 --- a/src/Aviat/AnimeClient/Model/Anime.php +++ b/src/Aviat/AnimeClient/Model/Anime.php @@ -228,6 +228,7 @@ class Anime extends API { /** * Sort the list by title * + * @codeCoverageIgnore * @param array $array * @return void */ diff --git a/src/Aviat/AnimeClient/Model/Manga.php b/src/Aviat/AnimeClient/Model/Manga.php index 7aec4f67..9f9a0b99 100644 --- a/src/Aviat/AnimeClient/Model/Manga.php +++ b/src/Aviat/AnimeClient/Model/Manga.php @@ -143,7 +143,7 @@ class Manga extends API { * @codeCoverageIgnore * @return array */ - private function _check_cache($response) + protected function _check_cache($response) { // Bail out early if there isn't any manga data $api_data = json_decode($response->getBody(), TRUE); @@ -215,6 +215,7 @@ class Manga extends API { /** * Sort the manga entries by their title * + * @codeCoverageIgnore * @param array $array * @return void */ diff --git a/tests/AnimeClient/AnimeClientTest.php b/tests/AnimeClient/AnimeClientTest.php index f2314175..3ff1dd6c 100644 --- a/tests/AnimeClient/AnimeClientTest.php +++ b/tests/AnimeClient/AnimeClientTest.php @@ -5,6 +5,13 @@ use Aviat\AnimeClient\AnimeClient; class AnimeClientTest extends AnimeClient_TestCase { + public function setUp() + { + parent::setUp(); + $this->anime_client = new AnimeClient(); + $this->anime_client->setContainer($this->container); + } + /** * Basic sanity test for _dir function */ @@ -30,4 +37,39 @@ class AnimeClientTest extends AnimeClient_TestCase { // Matches $this->assertEquals('', AnimeClient::is_not_selected('foo', 'foo')); } + + public function dataIsViewPage() + { + return [ + [ + 'uri' => '/anime/update', + 'expected' => FALSE + ], + [ + 'uri' => '/anime/watching', + 'expected' => TRUE + ], + [ + 'uri' => '/manga/reading', + 'expected' => TRUE + ], + [ + 'uri' => '/manga/update', + 'expected' => FALSE + ] + ]; + } + + /** + * @dataProvider dataIsViewPage + */ + public function testIsViewPage($uri, $expected) + { + $this->setSuperGlobals([ + '_SERVER' => [ + 'REQUEST_URI' => $uri + ] + ]); + $this->assertEquals($expected, $this->anime_client->is_view_page()); + } } diff --git a/tests/AnimeClient/Model/MangaModelTest.php b/tests/AnimeClient/Model/MangaModelTest.php index 4f39ad8d..58913dd2 100644 --- a/tests/AnimeClient/Model/MangaModelTest.php +++ b/tests/AnimeClient/Model/MangaModelTest.php @@ -53,4 +53,34 @@ class MangaModelTest extends AnimeClient_TestCase { $this->assertEquals($expected_all[$key], $this->model->_get_list_from_api($key)); } } + + public function testGetList() + { + $data = $this->model->get_all_lists(); + $this->assertEquals($data['Reading'], $this->model->get_list('Reading')); + } + + public function testGetAllLists() + { + $data = json_decode(file_get_contents($this->mockDir . '/manga-mapped.json'), TRUE); + + foreach($data as &$val) + { + $this->sort_by_name($val); + } + + $this->assertEquals($data, $this->model->get_all_lists()); + } + + private function sort_by_name(&$array) + { + $sort = array(); + + foreach ($array as $key => $item) + { + $sort[$key] = $item['manga']['title']; + } + + array_multisort($sort, SORT_ASC, $array); + } } \ No newline at end of file diff --git a/tests/mocks.php b/tests/mocks.php index e9b33dda..0f9b11b3 100644 --- a/tests/mocks.php +++ b/tests/mocks.php @@ -143,9 +143,9 @@ class TestAnimeModel extends AnimeModel { class TestMangaModel extends MangaModel { use MockInjectionTrait; - private function _check_cache($response) + protected function _check_cache($response) { - $file = __DIR__ . '/../../test_data/manga_list/manga-transformed.json'; + $file = __DIR__ . '/test_data/manga_list/manga-transformed.json'; return json_decode(file_get_contents($file), TRUE); } }