Skip to content

Commit

Permalink
Add tests for DocumentValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
beatrycze-volk committed May 28, 2024
1 parent f52d7c3 commit badbf19
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions Tests/Unit/Validation/DocumentValidatorTest.php
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;
}
}

0 comments on commit badbf19

Please sign in to comment.