-
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
2722296
commit 4367dda
Showing
3 changed files
with
59 additions
and
6 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
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
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 |
---|---|---|
@@ -1,10 +1,65 @@ | ||
<?php | ||
|
||
namespace Kitodo\Dlf\Validation; | ||
declare(strict_types=1); | ||
|
||
use PHPUnit\Framework\TestCase; | ||
/** | ||
* (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. | ||
*/ | ||
|
||
class XmlSchemesValidatorTest extends TestCase | ||
|
||
namespace Kitodo\Dlf\Tests\Unit\Validation; | ||
|
||
use Kitodo\Dlf\Validation\XmlSchemesValidator; | ||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; | ||
|
||
/** | ||
* Testing the XmlSchemesValidator class. | ||
* | ||
* @package TYPO3 | ||
* @subpackage dlf | ||
* | ||
* @access public | ||
*/ | ||
class XmlSchemesValidatorTest extends UnitTestCase | ||
{ | ||
const METS = '<mets:mets xmlns:mets="http://www.loc.gov/METS/" xmlns:mods="http://www.loc.gov/mods/v3" ><mets:metsHdr></mets:metsHdr><mets:amdSec></mets:amdSec><mets:fileSec><mets:fileGrp></mets:fileGrp></mets:fileSec><mets:structMap><mets:div></mets:div></mets:structMap></mets:mets>'; | ||
|
||
const METS_MODS = '<mets:mets xmlns:mets="http://www.loc.gov/METS/" xmlns:mods="http://www.loc.gov/mods/v3" ><mets:metsHdr></mets:metsHdr><mets:dmdSec ID="DMD1"><mets:mdWrap MDTYPE="MODS"><mets:xmlData><mods:mods><mods:titleInfo></mods:titleInfo></mods:mods></mets:xmlData></mets:mdWrap></mets:dmdSec><mets:amdSec></mets:amdSec><mets:fileSec><mets:fileGrp></mets:fileGrp></mets:fileSec><mets:structMap><mets:div></mets:div></mets:structMap></mets:mets>'; | ||
|
||
public function testValidation(): void | ||
{ | ||
$mets = ["namespace" => "http://www.loc.gov/METS/", "schemaLocation" => "http://www.loc.gov/standards/mets/mets.xsd"]; | ||
$mods = ["namespace" => "http://www.loc.gov/mods/v3", "schemaLocation" => "http://www.loc.gov/standards/mods/mods.xsd"]; | ||
$xmlSchemesValidator = new XmlSchemesValidator([$mets, $mods]); | ||
|
||
$domDocument = new \DOMDocument(); | ||
// Test with empty document | ||
$result = $xmlSchemesValidator->validate($domDocument); | ||
self::assertCount(1, $result->getErrors()); | ||
|
||
$domDocument->loadXML(self::METS); | ||
$result = $xmlSchemesValidator->validate($domDocument); | ||
self::assertFalse($result->hasErrors()); | ||
|
||
$domDocument->loadXML(self::METS_MODS); | ||
$result = $xmlSchemesValidator->validate($domDocument); | ||
self::assertFalse($result->hasErrors()); | ||
|
||
// Test with wrong mets element | ||
$domDocument->loadXML(str_replace("mets:metsHdr", "mets:Hdr", self::METS)); | ||
$result = $xmlSchemesValidator->validate($domDocument); | ||
self::assertTrue($result->hasErrors()); | ||
|
||
// Test with wrong mods element | ||
$domDocument->loadXML(str_replace("mods:titleInfo", "mods:title", self::METS_MODS)); | ||
|
||
$result = $xmlSchemesValidator->validate($domDocument); | ||
self::assertTrue($result->hasErrors()); | ||
} | ||
} |