|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) Kitodo. Key to digital objects e.V. <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the Kitodo and TYPO3 projects. |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU General Public License version 3 or later. |
|
8
|
|
|
* For the full copyright and license information, please read the |
|
9
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Kitodo\Dlf\Tests\Unit\Common; |
|
13
|
|
|
|
|
14
|
|
|
use Kitodo\Dlf\Validation\DocumentValidator; |
|
15
|
|
|
use SimpleXMLElement; |
|
16
|
|
|
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; |
|
17
|
|
|
|
|
18
|
|
|
class DocumentValidatorTest extends UnitTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
public function setUp(): void |
|
21
|
|
|
{ |
|
22
|
|
|
parent::setUp(); |
|
23
|
|
|
|
|
24
|
|
|
$this->resetSingletonInstances = true; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @test |
|
29
|
|
|
*/ |
|
30
|
|
|
public function passesHasAllMandatoryMetadataFields() |
|
31
|
|
|
{ |
|
32
|
|
|
$metadata = [ |
|
33
|
|
|
'record_id' => [ |
|
34
|
|
|
'xyz' |
|
35
|
|
|
] |
|
36
|
|
|
]; |
|
37
|
|
|
$documentValidator = new DocumentValidator($metadata, $this->getRequiredMetadataFields()); |
|
38
|
|
|
self::assertTrue($documentValidator->hasAllMandatoryMetadataFields()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @test |
|
43
|
|
|
*/ |
|
44
|
|
|
public function notPassesHasAllMandatoryMetadataFields() |
|
45
|
|
|
{ |
|
46
|
|
|
$metadata = [ |
|
47
|
|
|
'document_format' => [ |
|
48
|
|
|
'METS' |
|
49
|
|
|
] |
|
50
|
|
|
]; |
|
51
|
|
|
$documentValidator = new DocumentValidator($metadata, $this->getRequiredMetadataFields()); |
|
52
|
|
|
self::assertFalse($documentValidator->hasAllMandatoryMetadataFields()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @test |
|
57
|
|
|
*/ |
|
58
|
|
|
public function passesHasCorrectLogicalStructure() |
|
59
|
|
|
{ |
|
60
|
|
|
$xml = $this->getXml('av_beispiel.xml'); |
|
61
|
|
|
|
|
62
|
|
|
$documentValidator = new DocumentValidator([], [], $xml); |
|
63
|
|
|
self::assertTrue($documentValidator->hasCorrectLogicalStructure('advertisement')); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @test |
|
68
|
|
|
*/ |
|
69
|
|
|
public function notPassesHasCorrectLogicalStructure() |
|
70
|
|
|
{ |
|
71
|
|
|
$xml = $this->getXml('av_beispiel.xml'); |
|
72
|
|
|
|
|
73
|
|
|
$documentValidator = new DocumentValidator([], [], $xml); |
|
74
|
|
|
self::assertFalse($documentValidator->hasCorrectLogicalStructure('newspaper')); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @test |
|
79
|
|
|
*/ |
|
80
|
|
|
public function passesHasCorrectPhysicalStructure() |
|
81
|
|
|
{ |
|
82
|
|
|
$xml = $this->getXml('av_beispiel.xml'); |
|
83
|
|
|
|
|
84
|
|
|
$documentValidator = new DocumentValidator([], [], $xml); |
|
85
|
|
|
self::assertTrue($documentValidator->hasCorrectPhysicalStructure()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @test |
|
90
|
|
|
*/ |
|
91
|
|
|
public function notPassesHasCorrectPhysicalStructure() |
|
92
|
|
|
{ |
|
93
|
|
|
$xml = $this->getXml('two_dmdsec.xml'); |
|
94
|
|
|
|
|
95
|
|
|
$documentValidator = new DocumentValidator([], [], $xml); |
|
96
|
|
|
self::assertFalse($documentValidator->hasCorrectPhysicalStructure()); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
private function getRequiredMetadataFields(): array |
|
100
|
|
|
{ |
|
101
|
|
|
return [ |
|
102
|
|
|
'record_id' |
|
103
|
|
|
]; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
private function getXml(string $file): SimpleXMLElement |
|
107
|
|
|
{ |
|
108
|
|
|
$xml = simplexml_load_file(__DIR__ . '/../../Fixtures/MetsDocument/' . $file); |
|
109
|
|
|
self::assertNotFalse($xml); |
|
110
|
|
|
return $xml; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|