blob: 9c3c22f3e7d48b16af37ef97e4cf985bff73f2b4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
<?php
/**
* tests for methods under PhpMyAdmin\UserPreferencesHeader class
*
* @package PhpMyAdmin-test
*/
declare(strict_types=1);
namespace PhpMyAdmin\Tests;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Template;
use PhpMyAdmin\Tests\PmaTestCase;
use PhpMyAdmin\UserPreferencesHeader;
use Throwable;
use Twig_Error_Loader;
use Twig_Error_Runtime;
use Twig_Error_Syntax;
/**
* tests for methods under PhpMyAdmin\UserPreferencesHeader class
*
* @package PhpMyAdmin-test
*/
class UserPreferencesHeaderTest extends PmaTestCase
{
/**
* Setup various pre conditions
*
* @return void
*/
protected function setUp(): void
{
$GLOBALS['server'] = 0;
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
}
/**
* Test for getContent with selected tab
*
* @return void
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
*/
public function testGetContentWithSelectedTab(): void
{
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
$_GET['route'] = '/preferences/forms';
$_GET['form'] = 'Features';
$template = new Template();
$content = UserPreferencesHeader::getContent($template, new Relation($dbi, $template));
$this->assertStringContainsString(
'<li class="active">',
$content
);
$this->assertStringContainsString(
'<a href="index.php?route=/preferences/forms&form=Features&server=0&lang=en" class="tabactive">',
$content
);
$this->assertStringContainsString(
'<img src="themes/dot.gif" title="Features" alt="Features" class="icon ic_b_tblops"> Features',
$content
);
}
/**
* Test for getContent with "saved" get parameter
*
* @return void
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
*/
public function testGetContentAfterSave(): void
{
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
$_GET['saved'] = true;
$template = new Template();
$this->assertStringContainsString(
'Configuration has been saved.',
UserPreferencesHeader::getContent($template, new Relation($dbi, $template))
);
}
/**
* Test for getContent with session storage
*
* @return void
* @throws Throwable
* @throws Twig_Error_Loader
* @throws Twig_Error_Runtime
* @throws Twig_Error_Syntax
*/
public function testGetContentWithSessionStorage(): void
{
$dbi = $this->getMockBuilder(DatabaseInterface::class)
->disableOriginalConstructor()
->getMock();
$GLOBALS['dbi'] = $dbi;
$template = new Template();
$this->assertStringContainsString(
'Your preferences will be saved for current session only. Storing them permanently requires',
UserPreferencesHeader::getContent($template, new Relation($dbi, $template))
);
}
}
|