From bc8822e72510bb12ba396310b193cf7fda930350 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Fri, 24 Mar 2017 09:58:27 -0400 Subject: [PATCH] Update all the page titles --- src/Controller/Anime.php | 18 ++++++++++------ src/Controller/Character.php | 16 ++++++++------ src/Controller/Collection.php | 5 ++++- src/Controller/Manga.php | 22 +++++++++++++++----- src/ControllerTrait.php | 11 ++++++++++ tests/ControllerTest.php | 7 ++++++- tests/ControllerTraitTest.php | 39 +++++++++++++++++++++++++++++++++++ 7 files changed, 99 insertions(+), 19 deletions(-) create mode 100644 tests/ControllerTraitTest.php diff --git a/src/Controller/Anime.php b/src/Controller/Anime.php index 6f55b038..ad81bc9f 100644 --- a/src/Controller/Anime.php +++ b/src/Controller/Anime.php @@ -82,8 +82,10 @@ class Anime extends BaseController { public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL) { $title = (array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE)) - ? $this->config->get('whose_list') . - "'s Anime List · " . AnimeWatchingStatus::ROUTE_TO_TITLE[$type] + ? $this->formatTitle( + $this->config->get('whose_list') . "'s Anime List", + AnimeWatchingStatus::ROUTE_TO_TITLE[$type] + ) : ''; $viewMap = [ @@ -110,8 +112,10 @@ class Anime extends BaseController { { $this->setSessionRedirect(); $this->outputHTML('anime/add', [ - 'title' => $this->config->get('whose_list') . - "'s Anime List · Add", + 'title' => $this->formatTitle( + $this->config->get('whose_list') . "'s Anime List", + 'Add' + ), 'action_url' => $this->urlGenerator->url('anime/add'), 'status_list' => AnimeWatchingStatus::KITSU_TO_TITLE ]); @@ -158,8 +162,10 @@ class Anime extends BaseController { $this->setSessionRedirect(); $this->outputHTML('anime/edit', [ - 'title' => $this->config->get('whose_list') . - "'s Anime List · Edit", + 'title' => $this->formatTitle( + $this->config->get('whose_list') . "'s Anime List", + 'Edit' + ), 'item' => $item, 'statuses' => AnimeWatchingStatus::KITSU_TO_TITLE, 'action' => $this->container->get('url-generator') diff --git a/src/Controller/Character.php b/src/Controller/Character.php index e33c5ac3..dff0561e 100644 --- a/src/Controller/Character.php +++ b/src/Controller/Character.php @@ -29,17 +29,21 @@ class Character extends BaseController { if (( ! array_key_exists('data', $data)) || empty($data['data'])) { return $this->notFound( - $this->config->get('whose_list') . - "'s Anime List · Characters · " . - 'Character not found', + $this->formatTitle( + $this->config->get('whose_list') . "'s Anime List", + 'Characters', + 'Character not found' + ), 'Character Not Found' ); } - // $this->outputJSON($data); $this->outputHTML('character', [ - 'title' => $this->config->get('whose_list') . - "'s Anime List · Characters · " . $data['data'][0]['attributes']['name'], + 'title' => $this->formatTitle( + $this->config->get('whose_list') . "'s Anime List", + 'Characters', + $data['data'][0]['attributes']['name'] + ), 'data' => $data['data'][0]['attributes'] ]); } diff --git a/src/Controller/Collection.php b/src/Controller/Collection.php index 1fcc2928..14c43993 100644 --- a/src/Controller/Collection.php +++ b/src/Controller/Collection.php @@ -122,7 +122,10 @@ class Collection extends BaseController { $this->outputHTML('collection/' . strtolower($action), [ 'action' => $action, 'action_url' => $this->urlGenerator->fullUrl('collection/' . strtolower($action)), - 'title' => $this->config->get('whose_list') . " Anime Collection · {$action}", + 'title' => $this->formatTitle( + $this->config->get('whose_list') . "'s Anime Collection", + $action + ), 'media_items' => $this->animeCollectionModel->getMediaTypeList(), 'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : [] ]); diff --git a/src/Controller/Manga.php b/src/Controller/Manga.php index 7fee7393..f41ca754 100644 --- a/src/Controller/Manga.php +++ b/src/Controller/Manga.php @@ -71,7 +71,10 @@ class Manga extends Controller { { $statusTitle = MangaReadingStatus::ROUTE_TO_TITLE[$status]; - $title = $this->config->get('whose_list') . "'s Manga List · {$statusTitle}"; + $title = $this->formatTitle( + $this->config->get('whose_list') . "'s Manga List", + $statusTitle + ); $view_map = [ '' => 'cover', @@ -109,8 +112,10 @@ class Manga extends Controller { $this->setSessionRedirect(); $this->outputHTML('manga/add', [ - 'title' => $this->config->get('whose_list') . - "'s Manga List · Add", + 'title' => $this->formatTitle( + $this->config->get('whose_list') . "'s Manga List", + 'Add' + ), 'action_url' => $this->urlGenerator->url('manga/add'), 'status_list' => $statuses ]); @@ -155,7 +160,10 @@ class Manga extends Controller { { $this->setSessionRedirect(); $item = $this->model->getLibraryItem($id); - $title = $this->config->get('whose_list') . "'s Manga List · Edit"; + $title = $this->formatTitle( + $this->config->get('whose_list') . "'s Manga List", + 'Edit' + ); $this->outputHTML('manga/edit', [ 'title' => $title, @@ -263,7 +271,11 @@ class Manga extends Controller { $data = $this->model->getManga($manga_id); $this->outputHTML('manga/details', [ - 'title' => 'Manga · ' . $data['title'], + 'title' => $this->formatTitle( + $this->config->get('whose_list') . "'s Manga List", + 'Manga', + $data['title'] + ), 'data' => $data, ]); } diff --git a/src/ControllerTrait.php b/src/ControllerTrait.php index 03197051..86474a3d 100644 --- a/src/ControllerTrait.php +++ b/src/ControllerTrait.php @@ -301,6 +301,17 @@ trait ControllerTrait { ], NULL, 200); } + /** + * Helper for consistent page titles + * + * @param string ...$parts Title segements + * @return string + */ + public function formatTitle(string ...$parts) : string + { + return implode(' · ', $parts); + } + /** * Add a message box to the page * diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index 6d3e7c84..57ba8dee 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -21,12 +21,13 @@ use Aura\Web\WebFactory; use Aviat\AnimeClient\Controller; use Aviat\AnimeClient\Controller\{ Anime as AnimeController, + Character as CharacterController, Collection as CollectionController, Manga as MangaController }; class ControllerTest extends AnimeClientTestCase { - + protected $BaseController; public function setUp() @@ -64,6 +65,10 @@ class ControllerTest extends AnimeClientTestCase { 'Aviat\AnimeClient\Controller', new MangaController($this->container) ); + $this->assertInstanceOf( + 'Aviat\AnimeClient\Controller', + new CharacterController($this->container) + ); $this->assertInstanceOf( 'Aviat\AnimeClient\Controller', new CollectionController($this->container) diff --git a/tests/ControllerTraitTest.php b/tests/ControllerTraitTest.php new file mode 100644 index 00000000..256acafd --- /dev/null +++ b/tests/ControllerTraitTest.php @@ -0,0 +1,39 @@ + + * @copyright 2015 - 2017 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @version 4.0 + * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient + */ + +namespace Aviat\AnimeClient\Tests; + +use Aviat\AnimeClient\ControllerTrait; + +class ControllerTraitTest extends AnimeClientTestCase { + + public function setUp() + { + parent::setUp(); + + $this->controller = new class { + use ControllerTrait; + }; + } + + public function testFormatTitle() + { + $this->assertEquals( + $this->controller->formatTitle('foo', 'bar', 'baz'), + 'foo · bar · baz' + ); + } +} \ No newline at end of file