-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f52d7c3
commit badbf19
Showing
1 changed file
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
/** | ||
* (c) Kitodo. Key to digital objects e.V. <[email protected]> | ||
* | ||
* This file is part of the Kitodo and TYPO3 projects. | ||
* | ||
* @license GNU General Public License version 3 or later. | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Kitodo\Dlf\Tests\Unit\Common; | ||
|
||
use Kitodo\Dlf\Validation\DocumentValidator; | ||
use SimpleXMLElement; | ||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; | ||
|
||
class DocumentValidatorTest extends UnitTestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->resetSingletonInstances = true; | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function passesHasAllMandatoryMetadataFields() | ||
{ | ||
$metadata = [ | ||
'record_id' => [ | ||
'xyz' | ||
] | ||
]; | ||
$documentValidator = new DocumentValidator($metadata, $this->getRequiredMetadataFields()); | ||
self::assertTrue($documentValidator->hasAllMandatoryMetadataFields()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function notPassesHasAllMandatoryMetadataFields() | ||
{ | ||
$metadata = [ | ||
'document_format' => [ | ||
'METS' | ||
] | ||
]; | ||
$documentValidator = new DocumentValidator($metadata, $this->getRequiredMetadataFields()); | ||
self::assertFalse($documentValidator->hasAllMandatoryMetadataFields()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function passesHasCorrectLogicalStructure() | ||
{ | ||
$xml = $this->getXml('av_beispiel.xml'); | ||
|
||
$documentValidator = new DocumentValidator([], [], $xml); | ||
self::assertTrue($documentValidator->hasCorrectLogicalStructure('advertisement')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function notPassesHasCorrectLogicalStructure() | ||
{ | ||
$xml = $this->getXml('av_beispiel.xml'); | ||
|
||
$documentValidator = new DocumentValidator([], [], $xml); | ||
self::assertFalse($documentValidator->hasCorrectLogicalStructure('newspaper')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function passesHasCorrectPhysicalStructure() | ||
{ | ||
$xml = $this->getXml('av_beispiel.xml'); | ||
|
||
$documentValidator = new DocumentValidator([], [], $xml); | ||
self::assertTrue($documentValidator->hasCorrectPhysicalStructure()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function notPassesHasCorrectPhysicalStructure() | ||
{ | ||
$xml = $this->getXml('two_dmdsec.xml'); | ||
|
||
$documentValidator = new DocumentValidator([], [], $xml); | ||
self::assertFalse($documentValidator->hasCorrectPhysicalStructure()); | ||
} | ||
|
||
private function getRequiredMetadataFields(): array | ||
{ | ||
return [ | ||
'record_id' | ||
]; | ||
} | ||
|
||
private function getXml(string $file): SimpleXMLElement | ||
{ | ||
$xml = simplexml_load_file(__DIR__ . '/../../Fixtures/MetsDocument/' . $file); | ||
self::assertNotFalse($xml); | ||
return $xml; | ||
} | ||
} |