|
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 DOMDocument; |
|
18
|
|
|
use InvalidArgumentException; |
|
19
|
|
|
use Kitodo\Dlf\Validation\DOMDocumentValidationStack; |
|
20
|
|
|
use Kitodo\Dlf\Validation\XmlSchemesValidator; |
|
21
|
|
|
use TYPO3\CMS\Extbase\Validation\Validator\UrlValidator; |
|
22
|
|
|
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Testing AbstractDlfValidatorStack with implementation of DOMDocumentValidationStack. |
|
26
|
|
|
* |
|
27
|
|
|
* @package TYPO3 |
|
28
|
|
|
* @subpackage dlf |
|
29
|
|
|
* |
|
30
|
|
|
* @access public |
|
31
|
|
|
*/ |
|
32
|
|
|
class DOMDocumentValidationStackTest extends UnitTestCase |
|
33
|
|
|
{ |
|
34
|
|
|
public function setUp(): void |
|
35
|
|
|
{ |
|
36
|
|
|
parent::setUp(); |
|
37
|
|
|
$this->resetSingletonInstances = true; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testValueTypeException(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$domDocumentValidationStack = new DOMDocumentValidationStack([]); |
|
43
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
44
|
|
|
$this->expectExceptionMessage("Type of value is not valid."); |
|
45
|
|
|
$domDocumentValidationStack->validate(""); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testEmptyValidationStack(): void |
|
49
|
|
|
{ |
|
50
|
|
|
$domDocumentValidationStack = new DOMDocumentValidationStack([]); |
|
51
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
52
|
|
|
$this->expectExceptionMessage("The validation stack has no validator."); |
|
53
|
|
|
$domDocumentValidationStack->validate(new DOMDocument()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testValidatorClassNotExists(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
59
|
|
|
$this->expectExceptionMessage("Unable to load validator class."); |
|
60
|
|
|
new DOMDocumentValidationStack([["className" => "Kitodo\Tests\TestValidator"]]); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testValidatorDerivation(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
66
|
|
|
$this->expectExceptionMessage("Class must be an instance of AbstractDlfValidator."); |
|
67
|
|
|
new DOMDocumentValidationStack([["className" => UrlValidator::class]]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testBreakOnError(): void |
|
71
|
|
|
{ |
|
72
|
|
|
$xmlSchemesValidatorConfig = ["className" => XmlSchemesValidator::class, "configuration" => [["namespace" => "http://www.openarchives.org/OAI/2.0/", "schemaLocation" => "https://www.openarchives.org/OAI/2.0/OAI-PMH.xsd"]]]; |
|
73
|
|
|
$domDocumentValidationStack = new DOMDocumentValidationStack([$xmlSchemesValidatorConfig, $xmlSchemesValidatorConfig]); |
|
74
|
|
|
$result = $domDocumentValidationStack->validate(new DOMDocument()); |
|
75
|
|
|
self::assertCount(1, $result->getErrors()); |
|
76
|
|
|
|
|
77
|
|
|
// disable breaking on error |
|
78
|
|
|
$xmlSchemesValidatorConfig["breakOnError"] = "false"; |
|
79
|
|
|
$domDocumentValidationStack = new DOMDocumentValidationStack([$xmlSchemesValidatorConfig, $xmlSchemesValidatorConfig]); |
|
80
|
|
|
$result = $domDocumentValidationStack->validate(new DOMDocument()); |
|
81
|
|
|
self::assertCount(2, $result->getErrors()); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|