From 83a6629f03cde9132df475050b05bc78d69ff46f Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Tue, 16 Oct 2018 14:32:52 -0400 Subject: [PATCH] Fix tests, and category list for Manga detail page --- .../Kitsu/Transformer/MangaTransformer.php | 7 +- .../Kitsu/animeListItemBeforeTransform.json | 120 +++++++-------- .../Kitsu/mangaListBeforeTransform.json | 140 +++++++++--------- 3 files changed, 135 insertions(+), 132 deletions(-) diff --git a/src/API/Kitsu/Transformer/MangaTransformer.php b/src/API/Kitsu/Transformer/MangaTransformer.php index 6e9e35e1..fd235df5 100644 --- a/src/API/Kitsu/Transformer/MangaTransformer.php +++ b/src/API/Kitsu/Transformer/MangaTransformer.php @@ -35,9 +35,12 @@ final class MangaTransformer extends AbstractTransformer { { $genres = []; - foreach($included['categories'] as $cat) + foreach($item['included'] as $included) { - $genres[] = $cat['title']; + if ($included['type'] === 'categories') + { + $genres[] = $included['attributes']['title']; + } } sort($genres); diff --git a/tests/test_data/Kitsu/animeListItemBeforeTransform.json b/tests/test_data/Kitsu/animeListItemBeforeTransform.json index 242d0405..223ce859 100644 --- a/tests/test_data/Kitsu/animeListItemBeforeTransform.json +++ b/tests/test_data/Kitsu/animeListItemBeforeTransform.json @@ -115,19 +115,19 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "3": { - "name": "Comedy", + "title": "Comedy", "slug": "comedy", "description": null }, "11": { - "name": "Fantasy", + "title": "Fantasy", "slug": "fantasy", "description": "" }, "16": { - "name": "Slice of Life", + "title": "Slice of Life", "slug": "slice-of-life", "description": "" } @@ -189,24 +189,24 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "8": { - "name": "Magic", + "title": "Magic", "slug": "magic", "description": null }, "40": { - "name": "Kids", + "title": "Kids", "slug": "kids", "description": null }, "47": { - "name": "Mahou Shoujo", + "title": "Mahou Shoujo", "slug": "mahou-shoujo", "description": "Magical Girls" }, "11": { - "name": "Fantasy", + "title": "Fantasy", "slug": "fantasy", "description": "" } @@ -265,9 +265,9 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "35": { - "name": "Music", + "title": "Music", "slug": "music", "description": null } @@ -325,19 +325,19 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "3": { - "name": "Comedy", + "title": "Comedy", "slug": "comedy", "description": null }, "9": { - "name": "Supernatural", + "title": "Supernatural", "slug": "supernatural", "description": null }, "24": { - "name": "School", + "title": "School", "slug": "school", "description": null } @@ -399,29 +399,29 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "2": { - "name": "Adventure", + "title": "Adventure", "slug": "adventure", "description": null }, "3": { - "name": "Comedy", + "title": "Comedy", "slug": "comedy", "description": null }, "8": { - "name": "Magic", + "title": "Magic", "slug": "magic", "description": null }, "9": { - "name": "Supernatural", + "title": "Supernatural", "slug": "supernatural", "description": null }, "11": { - "name": "Fantasy", + "title": "Fantasy", "slug": "fantasy", "description": "" } @@ -479,14 +479,14 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "3": { - "name": "Comedy", + "title": "Comedy", "slug": "comedy", "description": null }, "16": { - "name": "Slice of Life", + "title": "Slice of Life", "slug": "slice-of-life", "description": "" } @@ -547,24 +547,24 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "3": { - "name": "Comedy", + "title": "Comedy", "slug": "comedy", "description": null }, "24": { - "name": "School", + "title": "School", "slug": "school", "description": null }, "34": { - "name": "Harem", + "title": "Harem", "slug": "harem", "description": null }, "14": { - "name": "Romance", + "title": "Romance", "slug": "romance", "description": "" } @@ -619,19 +619,19 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "3": { - "name": "Comedy", + "title": "Comedy", "slug": "comedy", "description": null }, "9": { - "name": "Supernatural", + "title": "Supernatural", "slug": "supernatural", "description": null }, "24": { - "name": "School", + "title": "School", "slug": "school", "description": null } @@ -689,24 +689,24 @@ "showType": "special", "nsfw": false, "relationships": { - "genres": { + "categories": { "8": { - "name": "Magic", + "title": "Magic", "slug": "magic", "description": null }, "9": { - "name": "Supernatural", + "title": "Supernatural", "slug": "supernatural", "description": null }, "11": { - "name": "Fantasy", + "title": "Fantasy", "slug": "fantasy", "description": "" }, "1": { - "name": "Action", + "title": "Action", "slug": "action", "description": "" } @@ -764,14 +764,14 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "3": { - "name": "Comedy", + "title": "Comedy", "slug": "comedy", "description": null }, "35": { - "name": "Music", + "title": "Music", "slug": "music", "description": null } @@ -829,29 +829,29 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "8": { - "name": "Magic", + "title": "Magic", "slug": "magic", "description": null }, "27": { - "name": "Historical", + "title": "Historical", "slug": "historical", "description": null }, "28": { - "name": "Military", + "title": "Military", "slug": "military", "description": null }, "4": { - "name": "Drama", + "title": "Drama", "slug": "drama", "description": "" }, "1": { - "name": "Action", + "title": "Action", "slug": "action", "description": "" } @@ -913,9 +913,9 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "3": { - "name": "Comedy", + "title": "Comedy", "slug": "comedy", "description": null } @@ -977,24 +977,24 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "7": { - "name": "Mystery", + "title": "Mystery", "slug": "mystery", "description": null }, "9": { - "name": "Supernatural", + "title": "Supernatural", "slug": "supernatural", "description": null }, "4": { - "name": "Drama", + "title": "Drama", "slug": "drama", "description": "" }, "1": { - "name": "Action", + "title": "Action", "slug": "action", "description": "" } @@ -1056,29 +1056,29 @@ "showType": "TV", "nsfw": false, "relationships": { - "genres": { + "categories": { "9": { - "name": "Supernatural", + "title": "Supernatural", "slug": "supernatural", "description": null }, "21": { - "name": "Thriller", + "title": "Thriller", "slug": "thriller", "description": null }, "47": { - "name": "Mahou Shoujo", + "title": "Mahou Shoujo", "slug": "mahou-shoujo", "description": "Magical Girls" }, "11": { - "name": "Fantasy", + "title": "Fantasy", "slug": "fantasy", "description": "" }, "1": { - "name": "Action", + "title": "Action", "slug": "action", "description": "" } diff --git a/tests/test_data/Kitsu/mangaListBeforeTransform.json b/tests/test_data/Kitsu/mangaListBeforeTransform.json index 67a4af8e..585921e5 100644 --- a/tests/test_data/Kitsu/mangaListBeforeTransform.json +++ b/tests/test_data/Kitsu/mangaListBeforeTransform.json @@ -419,30 +419,30 @@ "mangaType": "manga" }, "relationships": { - "genres": { + "categories": { "links": { - "self": "https://kitsu.io/api/edge/manga/20286/relationships/genres", - "related": "https://kitsu.io/api/edge/manga/20286/genres" + "self": "https://kitsu.io/api/edge/manga/20286/relationships/categories", + "related": "https://kitsu.io/api/edge/manga/20286/categories" }, "data": [ { - "type": "genres", + "type": "categories", "id": "3" }, { - "type": "genres", + "type": "categories", "id": "21" }, { - "type": "genres", + "type": "categories", "id": "24" }, { - "type": "genres", + "type": "categories", "id": "16" }, { - "type": "genres", + "type": "categories", "id": "14" } ] @@ -554,30 +554,30 @@ "mangaType": "manga" }, "relationships": { - "genres": { + "categories": { "links": { - "self": "https://kitsu.io/api/edge/manga/47/relationships/genres", - "related": "https://kitsu.io/api/edge/manga/47/genres" + "self": "https://kitsu.io/api/edge/manga/47/relationships/categories", + "related": "https://kitsu.io/api/edge/manga/47/categories" }, "data": [ { - "type": "genres", + "type": "categories", "id": "3" }, { - "type": "genres", + "type": "categories", "id": "13" }, { - "type": "genres", + "type": "categories", "id": "34" }, { - "type": "genres", + "type": "categories", "id": "14" }, { - "type": "genres", + "type": "categories", "id": "25" } ] @@ -689,38 +689,38 @@ "mangaType": "manga" }, "relationships": { - "genres": { + "categories": { "links": { - "self": "https://kitsu.io/api/edge/manga/11777/relationships/genres", - "related": "https://kitsu.io/api/edge/manga/11777/genres" + "self": "https://kitsu.io/api/edge/manga/11777/relationships/categories", + "related": "https://kitsu.io/api/edge/manga/11777/categories" }, "data": [ { - "type": "genres", + "type": "categories", "id": "3" }, { - "type": "genres", + "type": "categories", "id": "9" }, { - "type": "genres", + "type": "categories", "id": "13" }, { - "type": "genres", + "type": "categories", "id": "24" }, { - "type": "genres", + "type": "categories", "id": "45" }, { - "type": "genres", + "type": "categories", "id": "14" }, { - "type": "genres", + "type": "categories", "id": "25" } ] @@ -832,22 +832,22 @@ "mangaType": "manga" }, "relationships": { - "genres": { + "categories": { "links": { - "self": "https://kitsu.io/api/edge/manga/27175/relationships/genres", - "related": "https://kitsu.io/api/edge/manga/27175/genres" + "self": "https://kitsu.io/api/edge/manga/27175/relationships/categories", + "related": "https://kitsu.io/api/edge/manga/27175/categories" }, "data": [ { - "type": "genres", + "type": "categories", "id": "24" }, { - "type": "genres", + "type": "categories", "id": "16" }, { - "type": "genres", + "type": "categories", "id": "14" } ] @@ -954,22 +954,22 @@ "mangaType": "manga" }, "relationships": { - "genres": { + "categories": { "links": { - "self": "https://kitsu.io/api/edge/manga/25491/relationships/genres", - "related": "https://kitsu.io/api/edge/manga/25491/genres" + "self": "https://kitsu.io/api/edge/manga/25491/relationships/categories", + "related": "https://kitsu.io/api/edge/manga/25491/categories" }, "data": [ { - "type": "genres", + "type": "categories", "id": "3" }, { - "type": "genres", + "type": "categories", "id": "24" }, { - "type": "genres", + "type": "categories", "id": "16" } ] @@ -1026,120 +1026,120 @@ }, { "id": "3", - "type": "genres", + "type": "categories", "links": { - "self": "https://kitsu.io/api/edge/genres/3" + "self": "https://kitsu.io/api/edge/categories/3" }, "attributes": { - "name": "Comedy", + "title": "Comedy", "slug": "comedy", "description": null } }, { "id": "21", - "type": "genres", + "type": "categories", "links": { - "self": "https://kitsu.io/api/edge/genres/21" + "self": "https://kitsu.io/api/edge/categories/21" }, "attributes": { - "name": "Thriller", + "title": "Thriller", "slug": "thriller", "description": null } }, { "id": "24", - "type": "genres", + "type": "categories", "links": { - "self": "https://kitsu.io/api/edge/genres/24" + "self": "https://kitsu.io/api/edge/categories/24" }, "attributes": { - "name": "School", + "title": "School", "slug": "school", "description": null } }, { "id": "16", - "type": "genres", + "type": "categories", "links": { - "self": "https://kitsu.io/api/edge/genres/16" + "self": "https://kitsu.io/api/edge/categories/16" }, "attributes": { - "name": "Slice of Life", + "title": "Slice of Life", "slug": "slice-of-life", "description": "" } }, { "id": "14", - "type": "genres", + "type": "categories", "links": { - "self": "https://kitsu.io/api/edge/genres/14" + "self": "https://kitsu.io/api/edge/categories/14" }, "attributes": { - "name": "Romance", + "title": "Romance", "slug": "romance", "description": "" } }, { "id": "13", - "type": "genres", + "type": "categories", "links": { - "self": "https://kitsu.io/api/edge/genres/13" + "self": "https://kitsu.io/api/edge/categories/13" }, "attributes": { - "name": "Sports", + "title": "Sports", "slug": "sports", "description": null } }, { "id": "34", - "type": "genres", + "type": "categories", "links": { - "self": "https://kitsu.io/api/edge/genres/34" + "self": "https://kitsu.io/api/edge/categories/34" }, "attributes": { - "name": "Harem", + "title": "Harem", "slug": "harem", "description": null } }, { "id": "25", - "type": "genres", + "type": "categories", "links": { - "self": "https://kitsu.io/api/edge/genres/25" + "self": "https://kitsu.io/api/edge/categories/25" }, "attributes": { - "name": "Ecchi", + "title": "Ecchi", "slug": "ecchi", "description": "" } }, { "id": "9", - "type": "genres", + "type": "categories", "links": { - "self": "https://kitsu.io/api/edge/genres/9" + "self": "https://kitsu.io/api/edge/categories/9" }, "attributes": { - "name": "Supernatural", + "title": "Supernatural", "slug": "supernatural", "description": null } }, { "id": "45", - "type": "genres", + "type": "categories", "links": { - "self": "https://kitsu.io/api/edge/genres/45" + "self": "https://kitsu.io/api/edge/categories/45" }, "attributes": { - "name": "Gender Bender", + "title": "Gender Bender", "slug": "gender-bender", "description": "" } @@ -1244,7 +1244,7 @@ "count": 5 }, "links": { - "first": "https://kitsu.io/api/edge/library-entries?fields%5Busers%5D=id&filter%5Bmedia_type%5D=Manga&filter%5Bstatus%5D=1&filter%5Buser_id%5D=2644&include=media%2Cmedia.genres%2Cmedia.mappings&page%5Blimit%5D=200&page%5Boffset%5D=0&sort=-updated_at", - "last": "https://kitsu.io/api/edge/library-entries?fields%5Busers%5D=id&filter%5Bmedia_type%5D=Manga&filter%5Bstatus%5D=1&filter%5Buser_id%5D=2644&include=media%2Cmedia.genres%2Cmedia.mappings&page%5Blimit%5D=200&page%5Boffset%5D=0&sort=-updated_at" + "first": "https://kitsu.io/api/edge/library-entries?fields%5Busers%5D=id&filter%5Bmedia_type%5D=Manga&filter%5Bstatus%5D=1&filter%5Buser_id%5D=2644&include=media%2Cmedia.categories%2Cmedia.mappings&page%5Blimit%5D=200&page%5Boffset%5D=0&sort=-updated_at", + "last": "https://kitsu.io/api/edge/library-entries?fields%5Busers%5D=id&filter%5Bmedia_type%5D=Manga&filter%5Bstatus%5D=1&filter%5Buser_id%5D=2644&include=media%2Cmedia.categories%2Cmedia.mappings&page%5Blimit%5D=200&page%5Boffset%5D=0&sort=-updated_at" } } \ No newline at end of file