ion/tests/XMLTest.php

88 lines
2.0 KiB
PHP
Raw Normal View History

2019-03-12 09:51:38 -04:00
<?php declare(strict_types=1);
/**
2019-12-05 15:39:02 -05:00
* Ion
2019-03-12 09:51:38 -04:00
*
2019-12-05 15:39:02 -05:00
* Building blocks for web development
2019-03-12 09:51:38 -04:00
*
2019-12-05 15:39:02 -05:00
* PHP version 7.2
2019-03-12 09:51:38 -04:00
*
2019-12-05 15:39:02 -05:00
* @package Ion
2019-03-12 09:51:38 -04:00
* @author Timothy J. Warren <tim@timshomepage.net>
2019-12-05 15:39:02 -05:00
* @copyright 2015 - 2019 Timothy J. Warren
2019-03-12 09:51:38 -04:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2019-12-05 15:39:02 -05:00
* @version 3.0.0
* @link https://git.timshomepage.net/aviat/ion
2019-03-12 09:51:38 -04:00
*/
namespace Aviat\Ion\Tests;
use Aviat\Ion\XML;
use PHPUnit\Framework\TestCase;
class XMLTest extends TestCase {
protected $xml;
protected $expectedXml;
protected $object;
protected $array;
2019-12-05 15:25:47 -05:00
public function setUp(): void {
2019-03-12 09:51:38 -04:00
$this->xml = file_get_contents(__DIR__ . '/test_data/XML/xmlTestFile.xml');
$this->expectedXml = file_get_contents(__DIR__ . '/test_data/XML/minifiedXmlTestFile.xml');
$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));
}
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);
}
}