From f2fcc8ee9331ec4f569635f8bf466a8300302cb3 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 16 Dec 2016 21:52:59 -0500 Subject: [PATCH] Remove Hummingbird stuff --- build.xml | 169 ------------ src/Auth/HummingbirdAuth.php | 108 -------- src/Hummingbird/Enum/AnimeAiringStatus.php | 29 -- src/Hummingbird/Enum/AnimeShowType.php | 32 --- src/Hummingbird/Enum/AnimeWatchingStatus.php | 31 --- src/Hummingbird/Enum/MangaReadingStatus.php | 31 --- .../Transformer/AnimeListTransformer.php | 147 ---------- .../Transformer/MangaListTransformer.php | 121 --------- .../Transformer/MangaListsZipper.php | 92 ------- tests/Auth/HummingbirdAuthTest.php | 88 ------ tests/Model/AnimeCollectionModelTest.php | 76 ------ tests/Model/AnimeModelTest.php | 55 ---- tests/Model/BaseApiModelTest.php | 252 ------------------ tests/Model/MangaModelTest.php | 71 ----- .../Transformer/AnimeListTransformerTest.php | 50 ---- .../Transformer/MangaListTransformerTest.php | 114 -------- tests/Transformer/MangaListsZipperTest.php | 28 -- 17 files changed, 1494 deletions(-) delete mode 100644 build.xml delete mode 100644 src/Auth/HummingbirdAuth.php delete mode 100644 src/Hummingbird/Enum/AnimeAiringStatus.php delete mode 100644 src/Hummingbird/Enum/AnimeShowType.php delete mode 100644 src/Hummingbird/Enum/AnimeWatchingStatus.php delete mode 100644 src/Hummingbird/Enum/MangaReadingStatus.php delete mode 100644 src/Hummingbird/Transformer/AnimeListTransformer.php delete mode 100644 src/Hummingbird/Transformer/MangaListTransformer.php delete mode 100644 src/Hummingbird/Transformer/MangaListsZipper.php delete mode 100644 tests/Auth/HummingbirdAuthTest.php delete mode 100644 tests/Model/AnimeCollectionModelTest.php delete mode 100644 tests/Model/AnimeModelTest.php delete mode 100644 tests/Model/BaseApiModelTest.php delete mode 100644 tests/Model/MangaModelTest.php delete mode 100644 tests/Transformer/AnimeListTransformerTest.php delete mode 100644 tests/Transformer/MangaListTransformerTest.php delete mode 100644 tests/Transformer/MangaListsZipperTest.php diff --git a/build.xml b/build.xml deleted file mode 100644 index 35dbaf72..00000000 --- a/build.xml +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Auth/HummingbirdAuth.php b/src/Auth/HummingbirdAuth.php deleted file mode 100644 index ef2fefe9..00000000 --- a/src/Auth/HummingbirdAuth.php +++ /dev/null @@ -1,108 +0,0 @@ - - * @copyright 2015 - 2016 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 3.1 - * @link https://github.com/timw4mail/HummingBirdAnimeClient - */ - -namespace Aviat\AnimeClient\Auth; - -use Aviat\AnimeClient\AnimeClient; -use Aviat\Ion\Di\ContainerInterface; - -/** - * Hummingbird API Authentication - */ -class HummingbirdAuth { - - use \Aviat\Ion\Di\ContainerAware; - - /** - * Anime API Model - * - * @var \Aviat\AnimeClient\Model\API - */ - protected $model; - - /** - * Session object - * - * @var Aura\Session\Segment - */ - protected $segment; - - /** - * Constructor - * - * @param ContainerInterface $container - */ - public function __construct(ContainerInterface $container) - { - $this->setContainer($container); - $this->segment = $container->get('session') - ->getSegment(AnimeClient::SESSION_SEGMENT); - $this->model = $container->get('api-model'); - } - - /** - * Make the appropriate authentication call, - * and save the resulting auth token if successful - * - * @param string $password - * @return boolean - */ - public function authenticate($password) - { - $username = $this->container->get('config') - ->get('hummingbird_username'); - $auth_token = $this->model->authenticate($username, $password); - - if (FALSE !== $auth_token) - { - $this->segment->set('auth_token', $auth_token); - return TRUE; - } - - return FALSE; - } - - /** - * Check whether the current user is authenticated - * - * @return boolean - */ - public function is_authenticated() - { - return ($this->get_auth_token() !== FALSE); - } - - /** - * Clear authentication values - * - * @return void - */ - public function logout() - { - $this->segment->clear(); - } - - /** - * Retrieve the authentication token from the session - * - * @return string|false - */ - public function get_auth_token() - { - return $this->segment->get('auth_token', FALSE); - } -} -// End of HummingbirdAuth.php \ No newline at end of file diff --git a/src/Hummingbird/Enum/AnimeAiringStatus.php b/src/Hummingbird/Enum/AnimeAiringStatus.php deleted file mode 100644 index ae420a78..00000000 --- a/src/Hummingbird/Enum/AnimeAiringStatus.php +++ /dev/null @@ -1,29 +0,0 @@ - - * @copyright 2015 - 2016 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 3.1 - * @link https://github.com/timw4mail/HummingBirdAnimeClient - */ - -namespace Aviat\AnimeClient\Hummingbird\Enum; - -use Aviat\Ion\Enum as BaseEnum; - -/** - * Status of when anime is being/was/will be aired - */ -class AnimeAiringStatus extends BaseEnum { - const NOT_YET_AIRED = 'Not Yet Aired'; - const AIRING = 'Currently Airing'; - const FINISHED_AIRING = 'Finished Airing'; -} -// End of AnimeAiringStatus.php \ No newline at end of file diff --git a/src/Hummingbird/Enum/AnimeShowType.php b/src/Hummingbird/Enum/AnimeShowType.php deleted file mode 100644 index 47dcf6f5..00000000 --- a/src/Hummingbird/Enum/AnimeShowType.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @copyright 2015 - 2016 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 3.1 - * @link https://github.com/timw4mail/HummingBirdAnimeClient - */ - -namespace Aviat\AnimeClient\Hummingbird\Enum; - -use Aviat\Ion\Enum as BaseEnum; - -/** - * Type of Anime - */ -class AnimeShowType extends BaseEnum { - const TV = 'TV'; - const MOVIE = 'Movie'; - const OVA = 'OVA'; - const ONA = 'ONA'; - const SPECIAL = 'Special'; - const MUSIC = 'Music'; -} -// End of AnimeShowType.php \ No newline at end of file diff --git a/src/Hummingbird/Enum/AnimeWatchingStatus.php b/src/Hummingbird/Enum/AnimeWatchingStatus.php deleted file mode 100644 index 103ac128..00000000 --- a/src/Hummingbird/Enum/AnimeWatchingStatus.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @copyright 2015 - 2016 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 3.1 - * @link https://github.com/timw4mail/HummingBirdAnimeClient - */ - -namespace Aviat\AnimeClient\Hummingbird\Enum; - -use Aviat\Ion\Enum as BaseEnum; - -/** - * Possible values for watching status for the current anime - */ -class AnimeWatchingStatus extends BaseEnum { - const WATCHING = 'currently-watching'; - const PLAN_TO_WATCH = 'plan-to-watch'; - const COMPLETED = 'completed'; - const ON_HOLD = 'on-hold'; - const DROPPED = 'dropped'; -} -// End of AnimeWatchingStatus.php \ No newline at end of file diff --git a/src/Hummingbird/Enum/MangaReadingStatus.php b/src/Hummingbird/Enum/MangaReadingStatus.php deleted file mode 100644 index 5743c792..00000000 --- a/src/Hummingbird/Enum/MangaReadingStatus.php +++ /dev/null @@ -1,31 +0,0 @@ - - * @copyright 2015 - 2016 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 3.1 - * @link https://github.com/timw4mail/HummingBirdAnimeClient - */ - -namespace Aviat\AnimeClient\Hummingbird\Enum; - -use Aviat\Ion\Enum as BaseEnum; - -/** - * Possible values for current reading status of manga - */ -class MangaReadingStatus extends BaseEnum { - const READING = 'Currently Reading'; - const PLAN_TO_READ = 'Plan to Read'; - const DROPPED = 'Dropped'; - const ON_HOLD = 'On Hold'; - const COMPLETED = 'Completed'; -} -// End of MangaReadingStatus.php \ No newline at end of file diff --git a/src/Hummingbird/Transformer/AnimeListTransformer.php b/src/Hummingbird/Transformer/AnimeListTransformer.php deleted file mode 100644 index 4a6388bd..00000000 --- a/src/Hummingbird/Transformer/AnimeListTransformer.php +++ /dev/null @@ -1,147 +0,0 @@ - - * @copyright 2015 - 2016 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 3.1 - * @link https://github.com/timw4mail/HummingBirdAnimeClient - */ - -namespace Aviat\AnimeClient\Hummingbird\Transformer; - -use Aviat\Ion\Transformer\AbstractTransformer; - -/** - * Transformer for anime list - */ -class AnimeListTransformer extends AbstractTransformer { - - /** - * Convert raw api response to a more - * logical and workable structure - * - * @param array $item API library item - * @return array - */ - public function transform($item) - { - $anime =& $item['anime']; - $genres = $this->linearizeGenres($item['anime']['genres']); - - $rating = NULL; - if ($item['rating']['type'] === 'advanced') - { - $rating = is_numeric($item['rating']['value']) - ? (int) 2 * $item['rating']['value'] - : '-'; - } - - $total_episodes = is_numeric($anime['episode_count']) - ? $anime['episode_count'] - : '-'; - - $alternate_title = NULL; - if (array_key_exists('alternate_title', $anime)) - { - // If the alternate title is very similar, or - // a subset of the main title, don't list the - // alternate title - $not_subset = stripos($anime['title'], $anime['alternate_title']) === FALSE; - $diff = levenshtein($anime['title'], $anime['alternate_title'] ?? ''); - if ($not_subset && $diff >= 5) - { - $alternate_title = $anime['alternate_title']; - } - } - - return [ - 'id' => $item['id'], - 'episodes' => [ - 'watched' => $item['episodes_watched'], - 'total' => $total_episodes, - 'length' => $anime['episode_length'], - ], - 'airing' => [ - 'status' => $anime['status'], - 'started' => $anime['started_airing'], - 'ended' => $anime['finished_airing'] - ], - 'anime' => [ - 'age_rating' => $anime['age_rating'], - 'title' => $anime['title'], - 'alternate_title' => $alternate_title, - 'slug' => $anime['slug'], - 'url' => $anime['url'], - 'type' => $anime['show_type'], - 'image' => $anime['cover_image'], - 'genres' => $genres, - ], - 'watching_status' => $item['status'], - 'notes' => $item['notes'], - 'rewatching' => (bool) $item['rewatching'], - 'rewatched' => $item['rewatched_times'], - 'user_rating' => $rating, - 'private' => (bool) $item['private'], - ]; - } - - /** - * Convert transformed data to - * api response format - * - * @param array $item Transformed library item - * @return array API library item - */ - public function untransform($item) - { - // Messy mapping of boolean values to their API string equivalents - $privacy = 'public'; - if (array_key_exists('private', $item) && $item['private']) - { - $privacy = 'private'; - } - - $rewatching = 'false'; - if (array_key_exists('rewatching', $item) && $item['rewatching']) - { - $rewatching = 'true'; - } - - return [ - 'id' => $item['id'], - 'status' => $item['watching_status'], - 'sane_rating_update' => $item['user_rating'] / 2, - 'rewatching' => $rewatching, - 'rewatched_times' => $item['rewatched'], - 'notes' => $item['notes'], - 'episodes_watched' => $item['episodes_watched'], - 'privacy' => $privacy - ]; - } - - /** - * Simplify structure of genre list - * - * @param array $rawGenres - * @return array - */ - protected function linearizeGenres(array $rawGenres): array - { - $genres = []; - - foreach ($rawGenres as $genre) - { - $genres[] = $genre['name']; - } - - return $genres; - } -} -// End of AnimeListTransformer.php \ No newline at end of file diff --git a/src/Hummingbird/Transformer/MangaListTransformer.php b/src/Hummingbird/Transformer/MangaListTransformer.php deleted file mode 100644 index 7f32ca4a..00000000 --- a/src/Hummingbird/Transformer/MangaListTransformer.php +++ /dev/null @@ -1,121 +0,0 @@ - - * @copyright 2015 - 2016 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 3.1 - * @link https://github.com/timw4mail/HummingBirdAnimeClient - */ - -namespace Aviat\AnimeClient\Hummingbird\Transformer; - -use Aviat\Ion\Transformer\AbstractTransformer; - -/** - * Data transformation class for zippered Hummingbird manga - */ -class MangaListTransformer extends AbstractTransformer { - - use \Aviat\Ion\StringWrapper; - - /** - * Remap zipped anime data to a more logical form - * - * @param array $item manga entry item - * @return array - */ - public function transform($item) - { - $manga =& $item['manga']; - - $rating = (is_numeric($item['rating'])) - ? intval(2 * $item['rating']) - : '-'; - - $total_chapters = ($manga['chapter_count'] > 0) - ? $manga['chapter_count'] - : '-'; - - $total_volumes = ($manga['volume_count'] > 0) - ? $manga['volume_count'] - : '-'; - - $map = [ - 'id' => $item['id'], - 'chapters' => [ - 'read' => $item['chapters_read'], - 'total' => $total_chapters - ], - 'volumes' => [ - 'read' => $item['volumes_read'], - 'total' => $total_volumes - ], - 'manga' => [ - 'title' => $manga['romaji_title'], - 'alternate_title' => NULL, - 'slug' => $manga['id'], - 'url' => 'https://hummingbird.me/manga/' . $manga['id'], - 'type' => $manga['manga_type'], - 'image' => $manga['poster_image_thumb'], - 'genres' => $manga['genres'], - ], - 'reading_status' => $item['status'], - 'notes' => $item['notes'], - 'rereading' => (bool)$item['rereading'], - 'reread' => $item['reread_count'], - 'user_rating' => $rating, - ]; - - if (array_key_exists('english_title', $manga)) - { - $diff = levenshtein($manga['romaji_title'], $manga['english_title']); - - // If the titles are REALLY similar, don't bother showing both - if ($diff >= 5) - { - $map['manga']['alternate_title'] = $manga['english_title']; - } - } - - return $map; - } - - /** - * Untransform data to update the api - * - * @param array $item - * @return array - */ - public function untransform($item) - { - $rereading = (array_key_exists('rereading', $item)) && (bool)$item['rereading']; - - $map = [ - 'id' => $item['id'], - 'manga_id' => $item['manga_id'], - 'status' => $item['status'], - 'chapters_read' => (int)$item['chapters_read'], - 'volumes_read' => (int)$item['volumes_read'], - 'rereading' => $rereading, - 'reread_count' => (int)$item['reread_count'], - 'notes' => $item['notes'], - ]; - - if ($item['new_rating'] !== $item['old_rating'] && $item['new_rating'] !== "") - { - $map['rating'] = ($item['new_rating'] > 0) - ? $item['new_rating'] / 2 - : $item['old_rating'] / 2; - } - - return $map; - } -} -// End of MangaListTransformer.php \ No newline at end of file diff --git a/src/Hummingbird/Transformer/MangaListsZipper.php b/src/Hummingbird/Transformer/MangaListsZipper.php deleted file mode 100644 index c3db0458..00000000 --- a/src/Hummingbird/Transformer/MangaListsZipper.php +++ /dev/null @@ -1,92 +0,0 @@ - - * @copyright 2015 - 2016 Timothy J. Warren - * @license http://www.opensource.org/licenses/mit-license.html MIT License - * @version 3.1 - * @link https://github.com/timw4mail/HummingBirdAnimeClient - */ - -namespace Aviat\AnimeClient\Hummingbird\Transformer; - -/** - * Merges the two separate manga lists together - */ -class MangaListsZipper { - - /** - * List of manga information - * - * @var array - */ - protected $manga_series_list = []; - - /** - * List of manga tracking information - * - * @var array - */ - protected $manga_tracking_list = []; - - /** - * Create the transformer - * - * @param array $merge_lists The raw manga data - */ - public function __construct(array $merge_lists) - { - $this->manga_series_list = $merge_lists['manga']; - $this->manga_tracking_list = $merge_lists['manga_library_entries']; - } - - /** - * Do the transformation, and return the output - * - * @return array - */ - public function transform() - { - $this->index_manga_entries(); - - $output = []; - - foreach ($this->manga_tracking_list as &$entry) - { - $id = $entry['manga_id']; - $entry['manga'] = $this->manga_series_list[$id]; - unset($entry['manga_id']); - - $output[] = $entry; - } - - return $output; - } - - /** - * Index manga series by the id - * - * @return void - */ - protected function index_manga_entries() - { - $orig_list = $this->manga_series_list; - $indexed_list = []; - - foreach ($orig_list as $manga) - { - $id = $manga['id']; - $indexed_list[$id] = $manga; - } - - $this->manga_series_list = $indexed_list; - } - -} -// End of ManagListsZipper.php \ No newline at end of file diff --git a/tests/Auth/HummingbirdAuthTest.php b/tests/Auth/HummingbirdAuthTest.php deleted file mode 100644 index 260f0494..00000000 --- a/tests/Auth/HummingbirdAuthTest.php +++ /dev/null @@ -1,88 +0,0 @@ -newInstance([]); - } - - public function setUp() - { - parent::setUp(); - $auth = new HummingbirdAuth($this->container); - $friend = new Friend($auth); - $this->auth = $friend; - $this->container->setInstance('session', self::$session); - } - - public function dataAuthenticate() - { - $testToken = 'notReallyAValidTokenButThisIsATest'; - - return [ - 'successful auth call' => [ - 'username' => 'timw4mailtest', - 'password' => 'password', - 'response_data' => [ - 'code' => 201, - 'body' => json_encode($testToken) - ], - 'session_value' => $testToken, - 'expected' => TRUE, - ], - 'unsuccessful auth call' => [ - 'username' => 'foo', - 'password' => 'foobarbaz', - 'response_data' => [ - 'code' => 401, - 'body' => '{"error":"Invalid credentials"}', - ], - 'session_value' => FALSE, - 'expected' => FALSE, - ] - ]; - } - - /** - * @dataProvider dataAuthenticate - */ - public function testAuthenticate($username, $password, $response_data, $session_value, $expected) - { - $this->container->get('config') - ->set('hummingbird_username', $username); - $model = new MockBaseApiModel($this->container); - $mock = new MockHandler([ - new Response($response_data['code'], [], $response_data['body']) - ]); - $handler = HandlerStack::create($mock); - $client = new Client([ - 'handler' => $handler, - 'http_errors' => FALSE // Don't throw an exception for 400/500 class status codes - ]); - $model->__set('client', $client); - $this->auth->__set('model', $model); - - $actual = $this->auth->authenticate($password); - $this->assertEquals($expected, $actual); - } - - public function testIsAuthenticated() - { - $data = $this->dataAuthenticate(); - call_user_func_array([$this, 'testAuthenticate'], $data['successful auth call']); - $this->assertTrue($this->auth->is_authenticated()); - $this->auth->logout(); - $this->assertFalse($this->auth->is_authenticated()); - } -} \ No newline at end of file diff --git a/tests/Model/AnimeCollectionModelTest.php b/tests/Model/AnimeCollectionModelTest.php deleted file mode 100644 index be984aab..00000000 --- a/tests/Model/AnimeCollectionModelTest.php +++ /dev/null @@ -1,76 +0,0 @@ -container->setInstance('config', new Config([ - 'database' => [ - 'collection' => [ - 'type' => 'sqlite', - 'host' => '', - 'user' => '', - 'pass' => '', - 'port' => '', - 'name' => 'default', - 'database' => '', - 'file' => ':memory:', - ] - ] - ])); - $this->config = $this->container->get('config'); - $this->collectionModel = new AnimeCollectionModel($this->container); - } - - public function testSanity() - { - $friend = new Friend($this->collectionModel); - $this->assertInstanceOf('Aviat\Ion\Model\DB', $this->collectionModel); - $this->assertInstanceOf('Aviat\AnimeClient\Model\Anime', $friend->anime_model); - } - - public function testInvalidDatabase() - { - $this->container->setInstance('config', new Config([ - 'database' => [ - 'collection' => [ - 'type' => 'sqlite', - 'host' => '', - 'user' => '', - 'pass' => '', - 'port' => '', - 'name' => 'default', - 'database' => '', - 'file' => __FILE__, - ] - ] - ])); - $collectionModel = new Friend(new AnimeCollectionModel($this->container)); - $this->assertFalse($collectionModel->valid_database); - } - - public function testNonExistentDatabase() - { - $this->container->setInstance('config', new Config([ - 'database' => [ - 'collection' => [ - 'type' => 'sqlite', - 'host' => '', - 'user' => '', - 'pass' => '', - 'port' => '', - 'name' => 'default', - 'database' => '', - 'file' => '/foo/bar/baz/foobazbar.db', - ] - ] - ])); - $collectionModel = new Friend(new AnimeCollectionModel($this->container)); - $this->assertFalse($collectionModel->valid_database); - } -} \ No newline at end of file diff --git a/tests/Model/AnimeModelTest.php b/tests/Model/AnimeModelTest.php deleted file mode 100644 index 3f311067..00000000 --- a/tests/Model/AnimeModelTest.php +++ /dev/null @@ -1,55 +0,0 @@ -animeModel = new Friend(new TestAnimeModel($this->container)); - $this->mockDir = __DIR__ . '/../test_data/anime_list/search_mocks'; - } - - public function dataSearch() - { - return [ - 'nonsense search' => [ - 'search' => 'foo', - ], - 'search for common series' => [ - 'search' => 'Fate', - ], - 'search for weird series' => [ - 'search' => 'Twintails', - ] - ]; - } - - /** - * @dataProvider dataSearch - */ - public function testSearch($search) - { - // Mock requests - $json = file_get_contents(_dir($this->mockDir, "{$search}.json")); - $client = $this->getMockClient(200, [ - 'Content-Type' => 'application/json' - ], $json); - $this->animeModel->__set('client', $client); - - $actual = $this->animeModel->search($search); - $this->assertEquals(json_decode($json, TRUE), $actual); - } - - public function testSearchBadResponse() - { - $client = $this->getMockClient(400, [ - 'Content-Type' => 'application/json' - ], "[]"); - $this->animeModel->__set('client', $client); - - $this->expectException('RuntimeException'); - - $this->animeModel->search(''); - } -} \ No newline at end of file diff --git a/tests/Model/BaseApiModelTest.php b/tests/Model/BaseApiModelTest.php deleted file mode 100644 index c97515b9..00000000 --- a/tests/Model/BaseApiModelTest.php +++ /dev/null @@ -1,252 +0,0 @@ -model = new MockBaseApiModel($this->container); - } - - protected function getIp() - { - $response = $this->model->get('/ip'); - $json = json_decode($response->getBody(), TRUE); - $ip = $json['origin']; - return $ip; - } - - public function dataClient() - { - $user_agent = "Tim's Anime Client/2.0"; - $headers = [ - 'User-Agent' => $user_agent - ]; - - return [ - 'invalid method' => [ - 'method' => 'foo', - 'uri' => '', - 'options' => [], - 'expected' => NULL, - 'is_json' => FALSE, - ], - 'get' => [ - 'method' => 'get', - 'uri' => '/get', - 'options' => [ - 'query' => [ - 'foo' => 'bar' - ], - 'headers' => $headers - ], - 'expected' => [ - 'args' => [ - 'foo' => 'bar' - ], - 'headers' => [ - 'Host' => 'httpbin.org', - 'User-Agent' => $user_agent - ], - 'url' => 'https://httpbin.org/get?foo=bar' - ], - 'is_json' => TRUE - ], - 'post' => [ - 'method' => 'post', - 'uri' => '/post', - 'options' => [ - 'form_params' => [ - 'foo' => 'bar', - 'baz' => 'foobar' - ], - 'headers' => $headers - ], - 'expected' => [ - 'args' => [], - 'data' => '', - 'files' => [], - 'form' => [ - 'foo' => 'bar', - 'baz' => 'foobar' - ], - 'headers' => [ - 'Host' => 'httpbin.org', - 'User-Agent' => $user_agent, - 'Content-Length' => '18', - 'Content-Type' => 'application/x-www-form-urlencoded' - ], - 'json' => NULL, - 'url' => 'https://httpbin.org/post' - ], - 'is_json' => TRUE - ], - 'put' => [ - 'method' => 'put', - 'uri' => '/put', - 'options' => [ - 'form_params' => [ - 'foo' => 'bar', - 'baz' => 'foobar' - ], - 'headers' => $headers - ], - 'expected' => [ - 'args' => [], - 'data' => '', - 'files' => [], - 'form' => [ - 'foo' => 'bar', - 'baz' => 'foobar' - ], - 'headers' => [ - 'Host' => 'httpbin.org', - 'User-Agent' => $user_agent, - 'Content-Length' => '18', - 'Content-Type' => 'application/x-www-form-urlencoded' - ], - 'json' => NULL, - 'url' => 'https://httpbin.org/put' - ], - 'is_json' => TRUE - ], - 'patch' => [ - 'method' => 'patch', - 'uri' => '/patch', - 'options' => [ - 'form_params' => [ - 'foo' => 'bar', - 'baz' => 'foobar' - ], - 'headers' => $headers - ], - 'expected' => [ - 'args' => [], - 'data' => '', - 'files' => [], - 'form' => [ - 'foo' => 'bar', - 'baz' => 'foobar' - ], - 'headers' => [ - 'Host' => 'httpbin.org', - 'User-Agent' => $user_agent, - 'Content-Length' => '18', - 'Content-Type' => 'application/x-www-form-urlencoded' - ], - 'json' => NULL, - 'url' => 'https://httpbin.org/patch' - ], - 'is_json' => TRUE - ], - 'delete' => [ - 'method' => 'delete', - 'uri' => '/delete', - 'options' => [ - 'form_params' => [ - 'foo' => 'bar', - 'baz' => 'foobar' - ], - 'headers' => $headers - ], - 'expected' => [ - 'args' => [], - 'data' => '', - 'files' => [], - 'form' => [ - 'foo' => 'bar', - 'baz' => 'foobar' - ], - 'headers' => [ - 'Host' => 'httpbin.org', - 'User-Agent' => $user_agent, - 'Content-Length' => '18', - 'Content-Type' => 'application/x-www-form-urlencoded' - ], - 'json' => NULL, - 'url' => 'https://httpbin.org/delete' - ], - 'is_json' => TRUE - ] - ]; - } - - /** - * @dataProvider dataClient - */ - public function testClient($method, $uri, $options, $expected, $is_json) - { - - $result = $this->model->$method($uri, $options); - - if (is_null($result)) - { - $this->assertNull($expected); - return; - } - - // Because you have to make another api call to get the origin ip - // address, it needs to be retreived outside of the dataProvider method - $expected['origin'] = $this->getIp(); - $actual = ($is_json) - ? json_decode($result->getBody(), TRUE) - : (string) $result->getBody(); - - $this->assertEquals($expected, $actual); - } - - public function dataAuthenticate() - { - $test_token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI4YTA5ZDk4Ny1iZWQxLTQyMTktYWVmOS0wMTcxYWVjYTE3ZWUiLCJzY29wZSI6WyJhbGwiXSwic3ViIjoxMDgwMTIsImlzcyI6MTQ0NTAxNzczNSwiZXhwIjoxNDUyOTY2NTM1fQ.fpha1ZDN9dSFAuHeJesfOP9pCk5-ZnZk4uv3zumRMY0'; - - return [ - 'successful authentication' => [ - 'username' => 'timw4mailtest', - 'password' => 'password', - 'response_data' => [ - 'code' => 201, - 'body' => json_encode($test_token) - ], - 'expected' => $test_token - ], - 'failed authentication' => [ - 'username' => 'foo', - 'password' => 'foobarbaz', - 'response_data' => [ - 'code' => 401, - 'body' => '{"error":"Invalid credentials"}', - ], - 'expected' => FALSE - ] - ]; - } - - /** - * @dataProvider dataAuthenticate - */ - public function testAuthenticate($username, $password, $response_data, $expected) - { - $mock = new MockHandler([ - new Response($response_data['code'], [], $response_data['body']) - ]); - $handler = HandlerStack::create($mock); - $client = new Client([ - 'handler' => $handler, - 'http_errors' => FALSE // Don't throw an exception for 400/500 class status codes - ]); - - // Set the mock client - $this->model->__set('client', $client); - - // Check results based on mock data - $actual = $this->model->authenticate($username, $password); - $this->assertEquals($expected, $actual, "Incorrect method return value"); - } - -} \ No newline at end of file diff --git a/tests/Model/MangaModelTest.php b/tests/Model/MangaModelTest.php deleted file mode 100644 index 813876d9..00000000 --- a/tests/Model/MangaModelTest.php +++ /dev/null @@ -1,71 +0,0 @@ -container->setInstance('util', new MockUtil($this->container)); - $this->model = new Friend(new TestMangaModel($this->container)); - $this->mockDir = __DIR__ . '/../test_data/manga_list'; - } - - public function testZipperLists() - { - $raw_data = Json::decodeFile($this->mockDir . '/manga.json'); - $expected = Json::decodeFile($this->mockDir . '/manga-zippered.json'); - - $this->assertEquals($expected, $this->model->zipperLists($raw_data)); - } - - public function testMapByStatus() - { - $original = Json::decodeFile($this->mockDir . '/manga-transformed.json'); - $expected = Json::decodeFile($this->mockDir . '/manga-mapped.json'); - $actual = $this->model->map_by_status($original); - - $this->assertEquals($expected, $actual); - } - - public function testGetListFromApi() - { - $data = file_get_contents($this->mockDir . '/manga.json'); - $client = $this->getMockClient(200, [ - 'Content-type' => 'application/json' - ], $data); - $this->model->__set('client', $client); - - $reflect = new ReflectionClass($this->model); - $constants = $reflect->getConstants(); - - $expected_all = Json::decodeFile($this->mockDir . '/manga-mapped.json'); - - $this->assertEquals($expected_all, $this->model->_get_list_from_api()); - - foreach($constants as $name => $value) - { - $key = $reflect->getConstant($name); - $this->assertEquals($expected_all[$key], $this->model->_get_list_from_api($key)); - } - } - - public function testGetList() - { - if (($var = getenv('CI'))) - { - $this->markTestSkipped(); - } - - $data = file_get_contents($this->mockDir . '/manga.json'); - $client = $this->getMockClient(200, [ - 'Content-type' => 'application/json' - ], $data); - $this->model->__set('client', $client); - - $expected = Json::decodeFile($this->mockDir . '/get-all-lists.json'); - $this->assertEquals($expected['Reading'], $this->model->get_list('Reading')); - } -} \ No newline at end of file diff --git a/tests/Transformer/AnimeListTransformerTest.php b/tests/Transformer/AnimeListTransformerTest.php deleted file mode 100644 index 67a18139..00000000 --- a/tests/Transformer/AnimeListTransformerTest.php +++ /dev/null @@ -1,50 +0,0 @@ -start_file = __DIR__ . '/../test_data/anime_list/anime-completed.json'; - $this->res_file = __DIR__ . '/../test_data/anime_list/anime-completed-transformed.json'; - $this->transformer = new AnimeListTransformer(); - $this->transformerFriend = new Friend($this->transformer); - } - - public function dataLinearizeGenres() - { - return [ - [ - 'original' => [ - ['name' => 'Action'], - ['name' => 'Comedy'], - ['name' => 'Magic'], - ['name' => 'Fantasy'], - ['name' => 'Mahou Shoujo'] - ], - 'expected' => ['Action', 'Comedy', 'Magic', 'Fantasy', 'Mahou Shoujo'] - ] - ]; - } - - /** - * @dataProvider dataLinearizeGenres - */ - public function testLinearizeGenres($original, $expected) - { - $actual = $this->transformerFriend->linearizeGenres($original); - $this->assertEquals($expected, $actual); - } - - public function testTransform() - { - $json = Json::decodeFile($this->start_file); - $expected = Json::decodeFile($this->res_file); - $actual = $this->transformer->transformCollection($json); - $this->assertEquals($expected, $actual); - } -} \ No newline at end of file diff --git a/tests/Transformer/MangaListTransformerTest.php b/tests/Transformer/MangaListTransformerTest.php deleted file mode 100644 index 2524de1d..00000000 --- a/tests/Transformer/MangaListTransformerTest.php +++ /dev/null @@ -1,114 +0,0 @@ -start_file = __DIR__ . '/../test_data/manga_list/manga-zippered.json'; - $this->res_file = __DIR__ . '/../test_data/manga_list/manga-transformed.json'; - $this->transformer = new MangaListTransformer(); - } - - - public function testTransform() - { - $orig_json = Json::decodeFile($this->start_file); - $expected = Json::decodeFile($this->res_file); - - $actual = $this->transformer->transformCollection($orig_json); - $this->assertEquals($expected, $actual); - } - - public function dataUntransform() - { - return [ - 'same_rating' => [ - 'orig' => [ - 'id' => 401735, - 'manga_id' => "love-hina", - 'status' => "Plan to Read", - 'chapters_read' => 16, - 'volumes_read' => 2, - 'rereading' => true, - 'reread_count' => 1, - 'notes' => "Some text notes", - 'old_rating' => 7, - 'new_rating' => 7, - ], - 'expected' => [ - 'id' => 401735, - 'manga_id' => "love-hina", - 'status' => "Plan to Read", - 'chapters_read' => 16, - 'volumes_read' => 2, - 'rereading' => true, - 'reread_count' => 1, - 'notes' => "Some text notes", - ] - ], - 'update_rating' => [ - 'orig' => [ - 'id' => 401735, - 'manga_id' => "love-hina", - 'status' => "Plan to Read", - 'chapters_read' => 16, - 'volumes_read' => 2, - 'rereading' => true, - 'reread_count' => 1, - 'notes' => "Some text notes", - 'old_rating' => 7, - 'new_rating' => 8, - ], - 'expected' => [ - 'id' => 401735, - 'manga_id' => "love-hina", - 'status' => "Plan to Read", - 'chapters_read' => 16, - 'volumes_read' => 2, - 'rereading' => true, - 'reread_count' => 1, - 'notes' => "Some text notes", - 'rating' => 4, - ] - ], - 'remove_rating' => [ - 'orig' => [ - 'id' => 401735, - 'manga_id' => "love-hina", - 'status' => "Plan to Read", - 'chapters_read' => 16, - 'volumes_read' => 2, - 'rereading' => true, - 'reread_count' => 1, - 'notes' => "Some text notes", - 'old_rating' => 7, - 'new_rating' => 0, - ], - 'expected' => [ - 'id' => 401735, - 'manga_id' => "love-hina", - 'status' => "Plan to Read", - 'chapters_read' => 16, - 'volumes_read' => 2, - 'rereading' => true, - 'reread_count' => 1, - 'notes' => "Some text notes", - 'rating' => 3.5, - ] - ] - ]; - } - - /** - * @dataProvider dataUntransform - */ - public function testUntransform($orig, $expected) - { - $actual = $this->transformer->untransform($orig); - $this->assertEquals($expected, $actual); - } -} \ No newline at end of file diff --git a/tests/Transformer/MangaListsZipperTest.php b/tests/Transformer/MangaListsZipperTest.php deleted file mode 100644 index c213fbbd..00000000 --- a/tests/Transformer/MangaListsZipperTest.php +++ /dev/null @@ -1,28 +0,0 @@ -start_file = __DIR__ . '/../test_data/manga_list/manga.json'; - $this->res_file = __DIR__ . '/../test_data/manga_list/manga-zippered.json'; - - $json = Json::decodeFile($this->start_file); - $this->mangaListsZipper = new MangaListsZipper($json); - } - - public function testTransform() - { - $zippered_json = Json::decodeFile($this->res_file); - $transformed = $this->mangaListsZipper->transform(); - - $this->assertEquals($zippered_json, $transformed); - } - -} \ No newline at end of file