More tests

This commit is contained in:
Timothy Warren 2017-03-29 15:14:30 -04:00
parent 88c65dd0df
commit 9dfc99f49b
6 changed files with 135 additions and 15 deletions

View File

@ -8,6 +8,11 @@
searchResults = JSON.parse(searchResults); searchResults = JSON.parse(searchResults);
_.$('.cssload-loader')[0].setAttribute('hidden', 'hidden'); _.$('.cssload-loader')[0].setAttribute('hidden', 'hidden');
// Give mustache a key to iterate over
searchResults = {
data: searchResults.data
};
Mustache.parse(tempHtml); Mustache.parse(tempHtml);
_.$('#series_list')[0].innerHTML = Mustache.render(tempHtml, searchResults); _.$('#series_list')[0].innerHTML = Mustache.render(tempHtml, searchResults);
}); });

View File

@ -64,21 +64,6 @@ trait MALTrait {
return $this; 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 * Create a request object
* *

View File

@ -0,0 +1,40 @@
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
*
* PHP version 7
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @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'));
}
}

View File

@ -0,0 +1,51 @@
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
*
* PHP version 7
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @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(), '');
}
}

View File

@ -0,0 +1,35 @@
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
*
* PHP version 7
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @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'));
}
}

View File

@ -102,6 +102,10 @@ class AnimeClientTestCase extends TestCase {
'routes' => [ 'routes' => [
] ]
],
'mal' => [
'username' => 'foo',
'password' => 'bar'
] ]
]; ];