ChatControlTest::testMessagesPerPage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 0
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
{
17
    use \Testbench\TComponent;
18
    use \Testbench\TCompiledContainer;
19
20
    protected ExampleChatControl $control;
21
22
    public function setUp(): void
23
    {
24
        static $control = null;
25
        if ($control === null) {
26
            /** @var IExampleChatControlFactory $factory */
27
            $factory = $this->getService(IExampleChatControlFactory::class);
28
            $control = $factory->create();
29
        }
30
        $this->control = $control;
31
        $this->attachToPresenter($this->control);
32
    }
33
34
    public function testMessagesPerPage(): void
35
    {
36
        $originalValue = $this->control->messagesPerPage;
37
        Assert::type("int", $originalValue);
38
        $this->control->messagesPerPage = 1;
39
        Assert::same(1, $this->control->messagesPerPage);
40
        $this->control->messagesPerPage = -1;
41
        Assert::same(0, $this->control->messagesPerPage);
42
        $this->control->messagesPerPage = $originalValue;
43
    }
44
45
    public function testCharacterProfileLink(): void
46
    {
47
        $originalValue = $this->control->characterProfileLink;
48
        Assert::type("string", $originalValue);
49
        $this->control->characterProfileLink = "abc";
50
        Assert::same("abc", $this->control->characterProfileLink);
51
        $this->control->characterProfileLink = $originalValue;
52
    }
53
54
    public function testTranslator(): void
55
    {
56
        /** @var Translator $translator */
57
        $translator = $this->getService(Translator::class);
58
        Assert::same("en", $translator->lang);
59
        $result = $translator->translate("chat.peopleInRoom");
60
        Assert::type("string", $result);
61
        Assert::same("People in this room:", $result);
62
        $translator->lang = "cs";
63
        $result = $translator->translate("chat.peopleInRoom");
64
        Assert::type("string", $result);
65
        Assert::same("Lidé v této místnosti:", $result);
66
        $translator->lang = "en";
67
    }
68
69
    public function testRender(): void
70
    {
71
        $this->control->characterProfileLink = "Profile:default";
72
        $this->checkRenderOutput($this->control, __DIR__ . "/chatExpected.latte");
73
    }
74
}
75
76
$test = new ChatControlTest();
77
$test->run();
78