1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\API\Repository\Tests\PHPUnitConstraint; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* PHPUnit constraint checking that the given ValidationError message occurs in asserted ContentFieldValidationException. |
13
|
|
|
* |
14
|
|
|
* @see \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException |
15
|
|
|
* @see \eZ\Publish\SPI\FieldType\ValidationError |
16
|
|
|
*/ |
17
|
|
|
class ValidationErrorOccurs extends \PHPUnit_Framework_Constraint |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $expectedValidationErrorMessage; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param string $expectedValidationErrorMessage |
26
|
|
|
*/ |
27
|
|
|
public function __construct($expectedValidationErrorMessage) |
28
|
|
|
{ |
29
|
|
|
parent::__construct(); |
30
|
|
|
|
31
|
|
|
$this->expectedValidationErrorMessage = $expectedValidationErrorMessage; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $other |
36
|
|
|
* |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
protected function matches($other) |
40
|
|
|
{ |
41
|
|
|
foreach ($other->getFieldErrors() as $fieldId => $errors) { |
42
|
|
|
foreach ($errors as $languageCode => $fieldErrors) { |
43
|
|
|
foreach ($fieldErrors as $fieldError) { |
44
|
|
|
/** @var \eZ\Publish\Core\FieldType\ValidationError $fieldError */ |
45
|
|
|
if ($fieldError->getTranslatableMessage()->message === $this->expectedValidationErrorMessage) { |
46
|
|
|
return true; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $other |
57
|
|
|
* |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
protected function failureDescription($other) |
61
|
|
|
{ |
62
|
|
|
return sprintf( |
63
|
|
|
'%s::getFieldErrors = %s %s', |
64
|
|
|
get_class($other), |
65
|
|
|
var_export($other->getFieldErrors(), true), |
66
|
|
|
$this->toString() |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns a string representation of the object. |
72
|
|
|
* |
73
|
|
|
* @return string |
74
|
|
|
*/ |
75
|
|
|
public function toString() |
76
|
|
|
{ |
77
|
|
|
return "contains a ValidationError with the message '{$this->expectedValidationErrorMessage}'"; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|