|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
9
|
|
|
* |
|
10
|
|
|
* @license GNU General Public License version 3 or later. |
|
11
|
|
|
* For the full copyright and license information, please read the |
|
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Kitodo\Dlf\Tests\Unit\Validation; |
|
16
|
|
|
|
|
17
|
|
|
use DOMDocument; |
|
18
|
|
|
use Kitodo\Dlf\Validation\XmlSchemesValidator; |
|
19
|
|
|
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Testing the XmlSchemesValidator class. |
|
23
|
|
|
* |
|
24
|
|
|
* @package TYPO3 |
|
25
|
|
|
* @subpackage dlf |
|
26
|
|
|
* |
|
27
|
|
|
* @access public |
|
28
|
|
|
*/ |
|
29
|
|
|
class XmlSchemesValidatorTest extends UnitTestCase |
|
30
|
|
|
{ |
|
31
|
|
|
const METS = <<<METS |
|
32
|
|
|
<mets:mets |
|
33
|
|
|
xmlns:mets="http://www.loc.gov/METS/" |
|
34
|
|
|
xmlns:mods="http://www.loc.gov/mods/v3" > |
|
35
|
|
|
<mets:metsHdr></mets:metsHdr> |
|
36
|
|
|
<mets:amdSec></mets:amdSec> |
|
37
|
|
|
<mets:fileSec> |
|
38
|
|
|
<mets:fileGrp></mets:fileGrp> |
|
39
|
|
|
</mets:fileSec> |
|
40
|
|
|
<mets:structMap> |
|
41
|
|
|
<mets:div></mets:div> |
|
42
|
|
|
</mets:structMap> |
|
43
|
|
|
</mets:mets> |
|
44
|
|
|
METS; |
|
45
|
|
|
|
|
46
|
|
|
const METS_MODS = <<<METS_MODS |
|
47
|
|
|
<mets:mets |
|
48
|
|
|
xmlns:mets="http://www.loc.gov/METS/" |
|
49
|
|
|
xmlns:mods="http://www.loc.gov/mods/v3" > |
|
50
|
|
|
<mets:metsHdr></mets:metsHdr> |
|
51
|
|
|
<mets:dmdSec ID="DMD1"> |
|
52
|
|
|
<mets:mdWrap MDTYPE="MODS"> |
|
53
|
|
|
<mets:xmlData> |
|
54
|
|
|
<mods:mods> |
|
55
|
|
|
<mods:titleInfo></mods:titleInfo> |
|
56
|
|
|
</mods:mods> |
|
57
|
|
|
</mets:xmlData> |
|
58
|
|
|
</mets:mdWrap> |
|
59
|
|
|
</mets:dmdSec> |
|
60
|
|
|
<mets:amdSec></mets:amdSec> |
|
61
|
|
|
<mets:fileSec> |
|
62
|
|
|
<mets:fileGrp></mets:fileGrp> |
|
63
|
|
|
</mets:fileSec> |
|
64
|
|
|
<mets:structMap> |
|
65
|
|
|
<mets:div></mets:div> |
|
66
|
|
|
</mets:structMap> |
|
67
|
|
|
</mets:mets> |
|
68
|
|
|
METS_MODS; |
|
69
|
|
|
|
|
70
|
|
|
public function setUp(): void |
|
71
|
|
|
{ |
|
72
|
|
|
parent::setUp(); |
|
73
|
|
|
$this->resetSingletonInstances = true; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function testValidation(): void |
|
77
|
|
|
{ |
|
78
|
|
|
$xmlSchemesValidator = new XmlSchemesValidator( |
|
79
|
|
|
[["namespace" => "http://www.loc.gov/METS/", "schemaLocation" => "http://www.loc.gov/standards/mets/mets.xsd"], ["namespace" => "http://www.loc.gov/mods/v3", "schemaLocation" => "http://www.loc.gov/standards/mods/mods.xsd"]] |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
$domDocument = new DOMDocument(); |
|
83
|
|
|
// Test with empty document |
|
84
|
|
|
$result = $xmlSchemesValidator->validate($domDocument); |
|
85
|
|
|
self::assertCount(1, $result->getErrors()); |
|
86
|
|
|
|
|
87
|
|
|
$domDocument->loadXML(self::METS); |
|
88
|
|
|
$result = $xmlSchemesValidator->validate($domDocument); |
|
89
|
|
|
self::assertFalse($result->hasErrors()); |
|
90
|
|
|
|
|
91
|
|
|
$domDocument->loadXML(self::METS_MODS); |
|
92
|
|
|
$result = $xmlSchemesValidator->validate($domDocument); |
|
93
|
|
|
self::assertFalse($result->hasErrors()); |
|
94
|
|
|
|
|
95
|
|
|
// Test with wrong mets element |
|
96
|
|
|
$domDocument->loadXML(str_replace("mets:metsHdr", "mets:Hdr", self::METS)); |
|
97
|
|
|
$result = $xmlSchemesValidator->validate($domDocument); |
|
98
|
|
|
self::assertTrue($result->hasErrors()); |
|
99
|
|
|
|
|
100
|
|
|
// Test with wrong mods element |
|
101
|
|
|
$domDocument->loadXML(str_replace("mods:titleInfo", "mods:title", self::METS_MODS)); |
|
102
|
|
|
|
|
103
|
|
|
$result = $xmlSchemesValidator->validate($domDocument); |
|
104
|
|
|
self::assertTrue($result->hasErrors()); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|