|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the xAPI package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Validator\Tests; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; |
|
15
|
|
|
use Symfony\Component\Validator\ValidatorInterface; |
|
16
|
|
|
use Xabbuh\XApi\Validator\Validator; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Christian Flothmann <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class ValidatorTest extends \PHPUnit_Framework_TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
public function testRegisterXApiConstraints() |
|
24
|
|
|
{ |
|
25
|
|
|
$validatorBuilder = $this->getMock('\Symfony\Component\Validator\ValidatorBuilderInterface'); |
|
26
|
|
|
$validatorBuilder->expects($this->once()) |
|
27
|
|
|
->method('addXmlMappings'); |
|
28
|
|
|
|
|
29
|
|
|
Validator::registerXApiConstraints($validatorBuilder); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testCreateValidatorBuilder() |
|
33
|
|
|
{ |
|
34
|
|
|
$builder = Validator::createValidatorBuilder(); |
|
35
|
|
|
|
|
36
|
|
|
$this->validateXApiValidator($builder->getValidator()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testCreateValidator() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->validateXApiValidator(Validator::createValidator()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
private function validateXApiValidator(ValidatorInterface $validator) |
|
45
|
|
|
{ |
|
46
|
|
|
if ($validator instanceof MetadataFactoryInterface) { |
|
47
|
|
|
$metadataFactory = $validator; |
|
48
|
|
|
} else { |
|
49
|
|
|
$metadataFactory = $validator->getMetadataFactory(); |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
$this->assertTrue( |
|
53
|
|
|
$metadataFactory->hasMetadataFor('\Xabbuh\XApi\Model\Activity') |
|
54
|
|
|
); |
|
55
|
|
|
$this->assertTrue( |
|
56
|
|
|
$metadataFactory->hasMetadataFor('\Xabbuh\XApi\Model\Agent') |
|
57
|
|
|
); |
|
58
|
|
|
$this->assertTrue( |
|
59
|
|
|
$metadataFactory->hasMetadataFor('\Xabbuh\XApi\Model\Activity') |
|
60
|
|
|
); |
|
61
|
|
|
$this->assertTrue( |
|
62
|
|
|
$metadataFactory->hasMetadataFor('\Xabbuh\XApi\Model\Activity') |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.