1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Nexendrie\Translation\Bridges\Tracy; |
5
|
|
|
|
6
|
|
|
use Tester\Assert; |
7
|
|
|
use Nexendrie\Translation\Translator; |
8
|
|
|
|
9
|
|
|
require __DIR__ . "/../../../../bootstrap.php"; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Jakub Konečný |
13
|
|
|
* @testCase |
14
|
|
|
*/ |
15
|
|
|
final class TranslationPanelTest extends \Tester\TestCase { |
16
|
|
|
use \Testbench\TCompiledContainer; |
17
|
|
|
|
18
|
|
|
protected TranslationPanel $panel; |
19
|
|
|
|
20
|
|
|
protected function setUp(): void { |
21
|
|
|
$this->panel = $this->getService(TranslationPanel::class); // @phpstan-ignore assign.propertyType |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testGetTab(): void { |
25
|
|
|
$result = $this->panel->getTab(); |
26
|
|
|
Assert::type("string", $result); |
27
|
|
|
$r = new \SimpleXMLElement($result); |
28
|
|
|
Assert::same("Translation", (string) $r["title"]); |
29
|
|
|
Assert::contains("en", (string) $r); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGetPanel(): void { |
33
|
|
|
$result = $this->panel->getPanel(); |
34
|
|
|
Assert::type("string", $result); |
35
|
|
|
$r = new \SimpleXMLElement("<root>$result</root>"); |
36
|
|
|
Assert::same(2, $r->count()); |
37
|
|
|
$text = (string) $r->p; |
38
|
|
|
Assert::same("Untranslated messages: 0, loaded resources 0", $text); |
39
|
|
|
Assert::same("Resolved language", (string) $r->div->div->h1); |
40
|
|
|
foreach($r->div->div->table->tr->children() as $i => $td) { |
41
|
|
|
if($i === 0) { |
42
|
|
|
Assert::same("ManualLocaleResolver", (string) $td); |
43
|
|
|
} elseif($i === 1) { |
44
|
|
|
Assert::same("en", (string) $td); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
foreach($r->children() as $i1 => $div) { |
48
|
|
|
if($i1 === 1) { |
49
|
|
|
Assert::same("Loaded resources", (string) $div->h1); |
50
|
|
|
foreach($div->table->th as $i2 => $td) { |
51
|
|
|
if($i2 === 0) { |
52
|
|
|
Assert::same("Domain", (string) $td); |
53
|
|
|
} elseif($i2 === 1) { |
54
|
|
|
Assert::same("Filename", (string) $td); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
} elseif($i1 === 2) { |
58
|
|
|
Assert::count(0, $div->children()); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testGetPanelResources(): void { |
64
|
|
|
/** @var Translator $translator */ |
65
|
|
|
$translator = $this->getService(Translator::class); |
66
|
|
|
$translator->translate("xyz"); |
67
|
|
|
$result = $this->panel->getPanel(); |
68
|
|
|
Assert::type("string", $result); |
69
|
|
|
$r = new \SimpleXMLElement("<root>$result</root>"); |
70
|
|
|
$text = (string) $r->p; |
71
|
|
|
Assert::same("Untranslated messages: 0, loaded resources 2", $text); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testGetPanelWithMessages(): void { |
75
|
|
|
/** @var Translator $translator */ |
76
|
|
|
$translator = $this->getService(Translator::class); |
77
|
|
|
$translator->translate("abcd"); |
78
|
|
|
$result = $this->panel->getPanel(); |
79
|
|
|
Assert::type("string", $result); |
80
|
|
|
$r = new \SimpleXMLElement("<root>$result</root>"); |
81
|
|
|
$text = (string) $r->p; |
82
|
|
|
Assert::same("Untranslated messages: 1, loaded resources 2", $text); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$test = new TranslationPanelTest(); |
87
|
|
|
$test->run(); |
88
|
|
|
?> |