1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace HeroesofAbenez\Chat; |
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 ChatControlTest extends \Tester\TestCase { |
16
|
|
|
use \Testbench\TComponent; |
17
|
|
|
use \Testbench\TCompiledContainer; |
18
|
|
|
|
19
|
|
|
protected ExampleChatControl $control; |
20
|
|
|
|
21
|
|
|
public function setUp(): void { |
22
|
|
|
static $control = null; |
23
|
|
|
if($control === null) { |
24
|
|
|
/** @var IExampleChatControlFactory $factory */ |
25
|
|
|
$factory = $this->getService(IExampleChatControlFactory::class); |
26
|
|
|
$control = $factory->create(); |
27
|
|
|
} |
28
|
|
|
$this->control = $control; |
29
|
|
|
$this->attachToPresenter($this->control); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testMessagesPerPage(): void { |
33
|
|
|
$originalValue = $this->control->messagesPerPage; |
34
|
|
|
Assert::type("int", $originalValue); |
35
|
|
|
$this->control->messagesPerPage = 1; |
36
|
|
|
Assert::same(1, $this->control->messagesPerPage); |
37
|
|
|
$this->control->messagesPerPage = -1; |
38
|
|
|
Assert::same(0, $this->control->messagesPerPage); |
39
|
|
|
$this->control->messagesPerPage = $originalValue; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testCharacterProfileLink(): void { |
43
|
|
|
$originalValue = $this->control->characterProfileLink; |
44
|
|
|
Assert::type("string", $originalValue); |
45
|
|
|
$this->control->characterProfileLink = "abc"; |
46
|
|
|
Assert::same("abc", $this->control->characterProfileLink); |
47
|
|
|
$this->control->characterProfileLink = $originalValue; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testTranslator(): void { |
51
|
|
|
/** @var Translator $translator */ |
52
|
|
|
$translator = $this->getService(Translator::class); |
53
|
|
|
Assert::same("en", $translator->lang); |
54
|
|
|
$result = $translator->translate("chat.peopleInRoom"); |
55
|
|
|
Assert::type("string", $result); |
56
|
|
|
Assert::same("People in this room:", $result); |
57
|
|
|
$translator->lang = "cs"; |
58
|
|
|
$result = $translator->translate("chat.peopleInRoom"); |
59
|
|
|
Assert::type("string", $result); |
60
|
|
|
Assert::same("Lidé v této místnosti:", $result); |
61
|
|
|
$translator->lang = "en"; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testRender(): void { |
65
|
|
|
$this->control->characterProfileLink = "Profile:default"; |
66
|
|
|
$this->checkRenderOutput($this->control, __DIR__ . "/chatExpected.latte"); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$test = new ChatControlTest(); |
71
|
|
|
$test->run(); |
72
|
|
|
?> |