1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Decline\TransformatBundle\Tests\Services; |
4
|
|
|
|
5
|
|
|
use Decline\TransformatBundle\Services\ValidatorService; |
6
|
|
|
use Decline\TransformatBundle\Tests\ContainerTestCase; |
7
|
|
|
use Decline\TransformatBundle\Tests\Services\Interfaces\ServiceTestInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class ValidatorServiceTest |
11
|
|
|
* @package Decline\TransformatBundle\Tests\Services |
12
|
|
|
*/ |
13
|
|
|
class ValidatorServiceTest extends ContainerTestCase implements ServiceTestInterface |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Tests the validation of the translation files |
18
|
|
|
*/ |
19
|
|
|
public function testValidate() |
20
|
|
|
{ |
21
|
|
|
$validXliff = $this->getValidXliff(); |
22
|
|
|
$invalidXliff = $this->getInvalidXliff(); |
23
|
|
|
|
24
|
|
|
$validator = $this->getValidator(ValidatorService::MODE_DISABLED); |
25
|
|
|
$strictValidator = $this->getValidator(ValidatorService::MODE_STRICT); |
26
|
|
|
$transitionalValidator = $this->getValidator(ValidatorService::MODE_TRANSITIONAL); |
27
|
|
|
|
28
|
|
|
$this->assertCount(0, $validator->validate($validXliff)); |
29
|
|
|
$this->assertCount(0, $validator->validate($invalidXliff)); |
30
|
|
|
|
31
|
|
|
$this->assertCount(0, $strictValidator->validate($validXliff)); |
32
|
|
|
$this->assertCount(1, $strictValidator->validate($invalidXliff)); |
33
|
|
|
|
34
|
|
|
$this->assertCount(0, $transitionalValidator->validate($validXliff)); |
35
|
|
|
$this->assertCount(1, $transitionalValidator->validate($invalidXliff)); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Gets the validator for the given validation mode |
40
|
|
|
* |
41
|
|
|
* @param string $mode |
42
|
|
|
* |
43
|
|
|
* @return ValidatorService |
44
|
|
|
*/ |
45
|
|
|
private function getValidator($mode) |
46
|
|
|
{ |
47
|
|
|
return new ValidatorService(['xliff' => ['validation' => $mode]]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Returns the content of a valid xliff file |
52
|
|
|
* @return string |
53
|
|
|
*/ |
54
|
|
|
private function getValidXliff() |
55
|
|
|
{ |
56
|
|
|
return (string) file_get_contents(static::RESOURCES_DIR . '/' . static::TRANSLATION_VALID); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns the content of an invalid xliff file |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
private function getInvalidXliff() |
64
|
|
|
{ |
65
|
|
|
return (string) file_get_contents(static::RESOURCES_DIR . '/' . static::TRANSLATION_INVALID); |
66
|
|
|
} |
67
|
|
|
} |