|
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 InvalidArgumentException; |
|
18
|
|
|
use Kitodo\Dlf\Validation\SaxonXslToSvrlValidator; |
|
19
|
|
|
use ReflectionClass; |
|
20
|
|
|
use TYPO3\CMS\Core\Core\Environment; |
|
21
|
|
|
use TYPO3\CMS\Extbase\Error\Result; |
|
22
|
|
|
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Testing the SaxonXslToSvrlValidator class. |
|
26
|
|
|
* |
|
27
|
|
|
* @package TYPO3 |
|
28
|
|
|
* @subpackage dlf |
|
29
|
|
|
* |
|
30
|
|
|
* @access public |
|
31
|
|
|
*/ |
|
32
|
|
|
class SaxonXslToSvrlValidatorTest extends UnitTestCase |
|
33
|
|
|
{ |
|
34
|
|
|
const SVRL = <<<SVRL |
|
35
|
|
|
<svrl:schematron-output |
|
36
|
|
|
xmlns:svrl="http://purl.oclc.org/dsdl/schematron"> |
|
37
|
|
|
<svrl:failed-assert |
|
38
|
|
|
test="year > 1900" |
|
39
|
|
|
location="book.xml"> |
|
40
|
|
|
<svrl:text>The year must be greater than 1900.</svrl:text> |
|
41
|
|
|
</svrl:failed-assert> |
|
42
|
|
|
</svrl:schematron-output> |
|
43
|
|
|
SVRL; |
|
44
|
|
|
|
|
45
|
|
|
private string $dlfExtensionPath; |
|
46
|
|
|
|
|
47
|
|
|
public function setUp(): void |
|
48
|
|
|
{ |
|
49
|
|
|
parent::setUp(); |
|
50
|
|
|
$this->resetSingletonInstances = true; |
|
51
|
|
|
$this->dlfExtensionPath = Environment::getExtensionsPath() . 'dlf'; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testJarFileNotFound(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
57
|
|
|
$this->expectExceptionMessage("Saxon JAR file not found."); |
|
58
|
|
|
new SaxonXslToSvrlValidator([]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testXslFileNotFound(): void |
|
62
|
|
|
{ |
|
63
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
64
|
|
|
$this->expectExceptionMessage("XSL Schematron file not found."); |
|
65
|
|
|
// It only checks if a file exists at the specified path, so we can use one of the test files. |
|
66
|
|
|
new SaxonXslToSvrlValidator(["jar" => $this->dlfExtensionPath . '/Tests/Fixtures/Format/alto.xml']); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testValidation(): void |
|
70
|
|
|
{ |
|
71
|
|
|
$saxonXslToSvrlValidator = new SaxonXslToSvrlValidator(["jar" => $this->dlfExtensionPath . '/Tests/Fixtures/Format/alto.xml', "xsl" => $this->dlfExtensionPath . '/Tests/Fixtures/Format/alto.xml']); |
|
72
|
|
|
$reflection = new ReflectionClass($saxonXslToSvrlValidator); |
|
73
|
|
|
|
|
74
|
|
|
$result = $reflection->getProperty("result"); |
|
75
|
|
|
$result->setAccessible(true); |
|
76
|
|
|
$result->setValue($saxonXslToSvrlValidator, new Result()); |
|
77
|
|
|
|
|
78
|
|
|
$method = $reflection->getMethod("addErrorsOfSvrl"); |
|
79
|
|
|
$method->setAccessible(true); |
|
80
|
|
|
$method->invoke($saxonXslToSvrlValidator, self::SVRL); |
|
81
|
|
|
|
|
82
|
|
|
self::assertTrue($result->getValue($saxonXslToSvrlValidator)->hasErrors()); |
|
83
|
|
|
self::assertEquals("The year must be greater than 1900.", $result->getValue($saxonXslToSvrlValidator)->getErrors()[0]->getMessage()); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|