From 69b4d0c88bc42af06143af34b2a91a7288ddb695 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 29 Mar 2017 15:14:30 -0400 Subject: [PATCH] More tests --- public/js/manga_collection.js | 5 ++++ src/API/MAL/MALTrait.php | 15 ---------- tests/API/MAL/ListItemTest.php | 40 ++++++++++++++++++++++++++ tests/API/MAL/MALTraitTest.php | 51 ++++++++++++++++++++++++++++++++++ tests/API/MAL/ModelTest.php | 35 +++++++++++++++++++++++ tests/AnimeClientTestCase.php | 4 +++ 6 files changed, 135 insertions(+), 15 deletions(-) create mode 100644 tests/API/MAL/ListItemTest.php create mode 100644 tests/API/MAL/MALTraitTest.php create mode 100644 tests/API/MAL/ModelTest.php diff --git a/public/js/manga_collection.js b/public/js/manga_collection.js index 1d3dccbf..6d1c0c31 100644 --- a/public/js/manga_collection.js +++ b/public/js/manga_collection.js @@ -8,6 +8,11 @@ searchResults = JSON.parse(searchResults); _.$('.cssload-loader')[0].setAttribute('hidden', 'hidden'); + // Give mustache a key to iterate over + searchResults = { + data: searchResults.data + }; + Mustache.parse(tempHtml); _.$('#series_list')[0].innerHTML = Mustache.render(tempHtml, searchResults); }); diff --git a/src/API/MAL/MALTrait.php b/src/API/MAL/MALTrait.php index 430f2a15..32bd299c 100644 --- a/src/API/MAL/MALTrait.php +++ b/src/API/MAL/MALTrait.php @@ -64,21 +64,6 @@ trait MALTrait { return $this; } - /** - * Unencode the dual-encoded ampersands in the body - * - * This is a dirty hack until I can fully track down where - * the dual-encoding happens - * - * @param FormBody $formBody The form builder object to fix - * @return string - */ - private function fixBody(FormBody $formBody): string - { - $rawBody = \Amp\wait($formBody->getBody()); - return html_entity_decode($rawBody, \ENT_HTML5, 'UTF-8'); - } - /** * Create a request object * diff --git a/tests/API/MAL/ListItemTest.php b/tests/API/MAL/ListItemTest.php new file mode 100644 index 00000000..510010fb --- /dev/null +++ b/tests/API/MAL/ListItemTest.php @@ -0,0 +1,40 @@ + + * @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\API\MAL; + +use Aviat\AnimeClient\API\MAL\ListItem; +use Aviat\AnimeClient\API\MAL\MALRequestBuilder; +use Aviat\AnimeClient\Tests\AnimeClientTestCase; +use Aviat\Ion\Di\ContainerAware; + +class ListItemTest extends AnimeClientTestCase { + + protected $listItem; + + public function setUp() + { + parent::setUp(); + $this->listItem = new ListItem(); + $this->listItem->setContainer($this->container); + $this->listItem->setRequestBuilder(new MALRequestBuilder()); + } + + public function testGet() + { + $this->assertEquals([], $this->listItem->get('foo')); + } +} \ No newline at end of file diff --git a/tests/API/MAL/MALTraitTest.php b/tests/API/MAL/MALTraitTest.php new file mode 100644 index 00000000..10ec1151 --- /dev/null +++ b/tests/API/MAL/MALTraitTest.php @@ -0,0 +1,51 @@ + + * @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\API\MAL; + +use Aviat\AnimeClient\API\MAL\MALRequestBuilder; +use Aviat\AnimeClient\API\MAL\MALTrait; +use Aviat\AnimeClient\Tests\AnimeClientTestCase; +use Aviat\Ion\Di\ContainerAware; + +class MALTraitTest extends AnimeClientTestCase { + + protected $obj; + + public function setUp() + { + parent::setUp(); + $this->obj = new class { + use ContainerAware; + use MALTrait; + }; + $this->obj->setContainer($this->container); + $this->obj->setRequestBuilder(new MALRequestBuilder()); + } + + public function testSetupRequest() + { + $request = $this->obj->setUpRequest('GET', 'foo', [ + 'query' => [ + 'foo' => 'bar' + ], + 'body' => '' + ]); + $this->assertInstanceOf(\Amp\Artax\Request::class, $request); + $this->assertEquals($request->getUri(), 'https://myanimelist.net/api/foo?foo=bar'); + $this->assertEquals($request->getBody(), ''); + } +} \ No newline at end of file diff --git a/tests/API/MAL/ModelTest.php b/tests/API/MAL/ModelTest.php new file mode 100644 index 00000000..b626bb07 --- /dev/null +++ b/tests/API/MAL/ModelTest.php @@ -0,0 +1,35 @@ + + * @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\API\MAL; + +use Aviat\AnimeClient\Tests\AnimeClientTestCase; + +class ModelTest extends AnimeClientTestCase { + + protected $model; + + public function setUp() + { + parent::setUp(); + $this->model = $this->container->get('mal-model'); + } + + public function testGetListItem() + { + $this->assertEquals([], $this->model->getListItem('foo')); + } +} \ No newline at end of file diff --git a/tests/AnimeClientTestCase.php b/tests/AnimeClientTestCase.php index d4b2d429..e7f8bc19 100644 --- a/tests/AnimeClientTestCase.php +++ b/tests/AnimeClientTestCase.php @@ -102,6 +102,10 @@ class AnimeClientTestCase extends TestCase { 'routes' => [ ] + ], + 'mal' => [ + 'username' => 'foo', + 'password' => 'bar' ] ];