2017-01-11 19:35:51 -05:00
|
|
|
<?php declare(strict_types=1);
|
2017-02-07 13:27:41 -05:00
|
|
|
/**
|
2017-02-15 16:13:32 -05:00
|
|
|
* Hummingbird Anime List Client
|
2017-02-07 13:27:41 -05:00
|
|
|
*
|
2018-08-22 13:48:27 -04:00
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
2017-02-07 13:27:41 -05:00
|
|
|
*
|
2018-10-01 11:35:51 -04:00
|
|
|
* PHP version 7.1
|
2017-02-07 13:27:41 -05:00
|
|
|
*
|
2017-02-15 16:13:32 -05:00
|
|
|
* @package HummingbirdAnimeClient
|
2017-02-07 13:27:41 -05:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2018-01-15 14:43:15 -05:00
|
|
|
* @copyright 2015 - 2018 Timothy J. Warren
|
2017-02-07 13:27:41 -05:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2018-10-01 11:35:51 -04:00
|
|
|
* @version 4.1
|
2017-03-07 20:53:58 -05:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2017-02-07 13:27:41 -05:00
|
|
|
*/
|
2017-01-11 19:35:51 -05:00
|
|
|
|
|
|
|
namespace Aviat\AnimeClient\Tests\API;
|
|
|
|
|
|
|
|
use Aviat\AnimeClient\API\XML;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
class XMLTest extends TestCase {
|
2017-02-22 15:08:29 -05:00
|
|
|
|
|
|
|
protected $malExport;
|
|
|
|
protected $xml;
|
|
|
|
protected $expectedXml;
|
|
|
|
protected $object;
|
|
|
|
protected $array;
|
2017-01-11 19:35:51 -05:00
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
2017-01-27 09:43:42 -05:00
|
|
|
$this->malExport = file_get_contents(__DIR__ . '/../test_data/XML/MALExport.xml');
|
2017-01-12 15:41:20 -05:00
|
|
|
$this->xml = file_get_contents(__DIR__ . '/../test_data/XML/xmlTestFile.xml');
|
|
|
|
$this->expectedXml = file_get_contents(__DIR__ . '/../test_data/XML/minifiedXmlTestFile.xml');
|
2017-01-11 19:35:51 -05:00
|
|
|
|
|
|
|
$this->array = [
|
|
|
|
'entry' => [
|
|
|
|
'foo' => [
|
|
|
|
'bar' => [
|
|
|
|
'baz' => 42
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'episode' => '11',
|
|
|
|
'status' => 'watching',
|
|
|
|
'score' => '7',
|
|
|
|
'storage_type' => '1',
|
|
|
|
'storage_value' => '2.5',
|
|
|
|
'times_rewatched' => '1',
|
|
|
|
'rewatch_value' => '3',
|
|
|
|
'date_start' => '01152015',
|
|
|
|
'date_finish' => '10232016',
|
|
|
|
'priority' => '2',
|
|
|
|
'enable_discussion' => '0',
|
|
|
|
'enable_rewatching' => '1',
|
|
|
|
'comments' => 'Should you say something?',
|
|
|
|
'tags' => 'test tag, 2nd tag'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->object = new XML();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testToArray()
|
|
|
|
{
|
|
|
|
$this->assertEquals($this->array, XML::toArray($this->xml));
|
|
|
|
}
|
2017-01-27 09:43:42 -05:00
|
|
|
|
|
|
|
public function testMALExport()
|
|
|
|
{
|
|
|
|
$array = XML::toArray($this->malExport);
|
|
|
|
$this->assertEquals($array['myanimelist']['myinfo']['user_total_anime'], count($array['myanimelist']['anime']));
|
|
|
|
// $this->assertEquals($array, XML::toArray($this->malExport));
|
|
|
|
}
|
2017-01-11 19:35:51 -05:00
|
|
|
|
|
|
|
public function testParse()
|
|
|
|
{
|
|
|
|
$this->object->setXML($this->xml);
|
|
|
|
$this->assertEquals($this->array, $this->object->parse());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testToXML()
|
|
|
|
{
|
|
|
|
$this->assertEquals($this->expectedXml, XML::toXML($this->array));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateXML()
|
|
|
|
{
|
|
|
|
$this->object->setData($this->array);
|
|
|
|
$this->assertEquals($this->expectedXml, $this->object->createXML());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testToString()
|
|
|
|
{
|
|
|
|
$this->object->setData($this->array);
|
|
|
|
$this->assertEquals($this->expectedXml, $this->object->__toString());
|
|
|
|
$this->assertEquals($this->expectedXml, (string) $this->object);
|
|
|
|
}
|
|
|
|
}
|