|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the PHP Translation package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) PHP Translation team <[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 Translation\Bundle\Tests\Functional\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
15
|
|
|
use Translation\Bundle\EditInPlace\Activator; |
|
16
|
|
|
use Translation\Bundle\Tests\Functional\BaseTestCase; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @author Damien Alexandre <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class EditInPlaceTest extends BaseTestCase |
|
22
|
|
|
{ |
|
23
|
|
|
public function testActivatedTest(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$this->bootKernel(); |
|
26
|
|
|
$request = Request::create('/foobar'); |
|
27
|
|
|
|
|
28
|
|
|
// Activate the feature |
|
29
|
|
|
$this->getContainer()->get(Activator::class)->activate(); |
|
30
|
|
|
|
|
31
|
|
|
$response = $this->kernel->handle($request); |
|
32
|
|
|
|
|
33
|
|
|
self::assertSame(200, $response->getStatusCode()); |
|
34
|
|
|
self::assertStringContainsString('<!-- TranslationBundle -->', $response->getContent()); |
|
35
|
|
|
|
|
36
|
|
|
$dom = new \DOMDocument('1.0', 'utf-8'); |
|
37
|
|
|
@$dom->loadHTML(\mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); |
|
|
|
|
|
|
38
|
|
|
$xpath = new \DomXpath($dom); |
|
39
|
|
|
|
|
40
|
|
|
// Check number of x-trans tags |
|
41
|
|
|
$xtrans = $xpath->query('//x-trans'); |
|
42
|
|
|
self::assertEquals(6, $xtrans->length); |
|
43
|
|
|
|
|
44
|
|
|
// Check attribute with prefix (href="mailto:...") |
|
45
|
|
|
$emailTag = $dom->getElementById('email'); |
|
46
|
|
|
self::assertEquals('mailto:'.'🚫 Can\'t be translated here. 🚫', $emailTag->getAttribute('href')); |
|
47
|
|
|
self::assertEquals('localized.email', $emailTag->textContent); |
|
48
|
|
|
|
|
49
|
|
|
// Check attribute |
|
50
|
|
|
$attributeDiv = $dom->getElementById('attribute-div'); |
|
51
|
|
|
self::assertEquals('🚫 Can\'t be translated here. 🚫', $attributeDiv->getAttribute('data-value')); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testIfUntranslatableLabelGetsDisabled(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->kernel->addConfigFile(__DIR__.'/../app/config/disabled_label.yaml'); |
|
57
|
|
|
$request = Request::create('/foobar'); |
|
58
|
|
|
|
|
59
|
|
|
// Activate the feature |
|
60
|
|
|
$this->bootKernel(); |
|
61
|
|
|
$this->getContainer()->get(Activator::class)->activate(); |
|
62
|
|
|
|
|
63
|
|
|
$response = $this->kernel->handle($request); |
|
64
|
|
|
|
|
65
|
|
|
self::assertSame(200, $response->getStatusCode()); |
|
66
|
|
|
self::assertStringContainsString('<!-- TranslationBundle -->', $response->getContent()); |
|
67
|
|
|
|
|
68
|
|
|
$dom = new \DOMDocument('1.0', 'utf-8'); |
|
69
|
|
|
@$dom->loadHTML(\mb_convert_encoding($response->getContent(), 'HTML-ENTITIES', 'UTF-8')); |
|
|
|
|
|
|
70
|
|
|
$xpath = new \DomXpath($dom); |
|
71
|
|
|
|
|
72
|
|
|
// Check number of x-trans tags |
|
73
|
|
|
$xtrans = $xpath->query('//x-trans'); |
|
74
|
|
|
self::assertEquals(6, $xtrans->length); |
|
75
|
|
|
|
|
76
|
|
|
// Check attribute with prefix (href="mailto:...") |
|
77
|
|
|
$emailTag = $dom->getElementById('email'); |
|
78
|
|
|
self::assertEquals('localized.email', $emailTag->getAttribute('href')); |
|
79
|
|
|
self::assertEquals('localized.email', $emailTag->textContent); |
|
80
|
|
|
|
|
81
|
|
|
// Check attribute |
|
82
|
|
|
$attributeDiv = $dom->getElementById('attribute-div'); |
|
83
|
|
|
self::assertEquals('translated.attribute', $attributeDiv->getAttribute('data-value')); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function testDeactivatedTest(): void |
|
87
|
|
|
{ |
|
88
|
|
|
$this->bootKernel(); |
|
89
|
|
|
$request = Request::create('/foobar'); |
|
90
|
|
|
$response = $this->kernel->handle($request); |
|
91
|
|
|
|
|
92
|
|
|
self::assertSame(200, $response->getStatusCode()); |
|
93
|
|
|
self::assertStringNotContainsString('x-trans', $response->getContent()); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: