API client for Kitsu.io, with optional Anime collection, and optional Anilist syncing.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XMLTest.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php declare(strict_types=1);
  2. /**
  3. * Hummingbird Anime List Client
  4. *
  5. * An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
  6. *
  7. * PHP version 7
  8. *
  9. * @package HummingbirdAnimeClient
  10. * @author Timothy J. Warren <tim@timshomepage.net>
  11. * @copyright 2015 - 2018 Timothy J. Warren
  12. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  13. * @version 4.0
  14. * @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
  15. */
  16. namespace Aviat\AnimeClient\Tests\API;
  17. use Aviat\AnimeClient\API\XML;
  18. use PHPUnit\Framework\TestCase;
  19. class XMLTest extends TestCase {
  20. protected $malExport;
  21. protected $xml;
  22. protected $expectedXml;
  23. protected $object;
  24. protected $array;
  25. public function setUp()
  26. {
  27. $this->malExport = file_get_contents(__DIR__ . '/../test_data/XML/MALExport.xml');
  28. $this->xml = file_get_contents(__DIR__ . '/../test_data/XML/xmlTestFile.xml');
  29. $this->expectedXml = file_get_contents(__DIR__ . '/../test_data/XML/minifiedXmlTestFile.xml');
  30. $this->array = [
  31. 'entry' => [
  32. 'foo' => [
  33. 'bar' => [
  34. 'baz' => 42
  35. ]
  36. ],
  37. 'episode' => '11',
  38. 'status' => 'watching',
  39. 'score' => '7',
  40. 'storage_type' => '1',
  41. 'storage_value' => '2.5',
  42. 'times_rewatched' => '1',
  43. 'rewatch_value' => '3',
  44. 'date_start' => '01152015',
  45. 'date_finish' => '10232016',
  46. 'priority' => '2',
  47. 'enable_discussion' => '0',
  48. 'enable_rewatching' => '1',
  49. 'comments' => 'Should you say something?',
  50. 'tags' => 'test tag, 2nd tag'
  51. ]
  52. ];
  53. $this->object = new XML();
  54. }
  55. public function testToArray()
  56. {
  57. $this->assertEquals($this->array, XML::toArray($this->xml));
  58. }
  59. public function testMALExport()
  60. {
  61. $array = XML::toArray($this->malExport);
  62. $this->assertEquals($array['myanimelist']['myinfo']['user_total_anime'], count($array['myanimelist']['anime']));
  63. // $this->assertEquals($array, XML::toArray($this->malExport));
  64. }
  65. public function testParse()
  66. {
  67. $this->object->setXML($this->xml);
  68. $this->assertEquals($this->array, $this->object->parse());
  69. }
  70. public function testToXML()
  71. {
  72. $this->assertEquals($this->expectedXml, XML::toXML($this->array));
  73. }
  74. public function testCreateXML()
  75. {
  76. $this->object->setData($this->array);
  77. $this->assertEquals($this->expectedXml, $this->object->createXML());
  78. }
  79. public function testToString()
  80. {
  81. $this->object->setData($this->array);
  82. $this->assertEquals($this->expectedXml, $this->object->__toString());
  83. $this->assertEquals($this->expectedXml, (string) $this->object);
  84. }
  85. }