Passed
Push — master ( a7be49...5129e4 )
by Maurício
08:55
created

  A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\Tests\Controllers;
6
7
use PhpMyAdmin\Controllers\JavaScriptMessagesController;
8
use PHPUnit\Framework\TestCase;
9
use function json_decode;
10
use function ob_end_clean;
11
use function ob_get_contents;
12
use function ob_start;
13
use function strlen;
14
use function substr;
15
16
class JavaScriptMessagesControllerTest extends TestCase
17
{
18
    public function testIndex(): void
19
    {
20
        global $cfg, $PMA_Theme;
21
22
        $cfg['GridEditing'] = 'double-click';
23
        $PMA_Theme = new class {
24
            public function getImgPath(string $img): string
25
            {
26
                return $img;
27
            }
28
        };
29
30
        $controller = new JavaScriptMessagesController();
31
32
        ob_start();
33
        $controller->index();
34
        $actual = ob_get_contents();
35
        ob_end_clean();
36
37
        $this->assertIsString($actual);
38
        $this->assertStringStartsWith('var Messages = {', $actual);
39
        $this->assertStringEndsWith('};', $actual);
40
41
        $json = substr($actual, strlen('var Messages = '), -1);
42
        $array = json_decode($json, true);
43
44
        $this->assertIsArray($array);
45
        $this->assertArrayHasKey('strConfirm', $array);
46
        $this->assertEquals(__('Confirm'), $array['strConfirm']);
47
    }
48
}
49