|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU General Public License version 3 or later. |
|
9
|
|
|
* For the full copyright and license information, please read the |
|
10
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Kitodo\Dlf\Tests\Unit\Common; |
|
14
|
|
|
|
|
15
|
|
|
use Kitodo\Dlf\Common\Helper; |
|
16
|
|
|
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; |
|
17
|
|
|
|
|
18
|
|
|
class HelperTest extends UnitTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function assertInvalidXml($xml) |
|
21
|
|
|
{ |
|
22
|
|
|
$result = Helper::getXmlFileAsString($xml); |
|
23
|
|
|
self::assertEquals(false, $result); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @test |
|
28
|
|
|
* @group getXmlFileAsString |
|
29
|
|
|
*/ |
|
30
|
|
|
public function invalidXmlYieldsFalse(): void |
|
31
|
|
|
{ |
|
32
|
|
|
self::assertInvalidXml(false); |
|
|
|
|
|
|
33
|
|
|
self::assertInvalidXml(null); |
|
34
|
|
|
self::assertInvalidXml(1); |
|
35
|
|
|
self::assertInvalidXml([]); |
|
36
|
|
|
self::assertInvalidXml(new \stdClass()); |
|
37
|
|
|
self::assertInvalidXml(''); |
|
38
|
|
|
self::assertInvalidXml('not xml'); |
|
39
|
|
|
self::assertInvalidXml('<tag-not-closed>'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @test |
|
44
|
|
|
* @group getXmlFileAsString |
|
45
|
|
|
*/ |
|
46
|
|
|
public function validXmlIsAccepted(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$xml = <<<XML |
|
49
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
50
|
|
|
<root> |
|
51
|
|
|
<single /> |
|
52
|
|
|
</root> |
|
53
|
|
|
XML; |
|
54
|
|
|
$node = Helper::getXmlFileAsString($xml); |
|
55
|
|
|
self::assertIsObject($node); |
|
56
|
|
|
self::assertEquals('root', $node->getName()); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|