1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\Tests; |
6
|
|
|
|
7
|
|
|
use ArrayIterator; |
8
|
|
|
use PhpMyAdmin\ErrorHandler; |
|
|
|
|
9
|
|
|
use PhpMyAdmin\Footer; |
10
|
|
|
use PhpMyAdmin\Template; |
11
|
|
|
use ReflectionProperty; |
12
|
|
|
|
13
|
|
|
use function json_encode; |
14
|
|
|
|
15
|
|
|
/** @covers \PhpMyAdmin\Footer */ |
16
|
|
|
class FooterTest extends AbstractTestCase |
17
|
|
|
{ |
18
|
|
|
/** @var mixed[] store private attributes of PhpMyAdmin\Footer */ |
19
|
|
|
public array $privates = []; |
20
|
|
|
|
21
|
|
|
protected Footer $object; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Sets up the fixture, for example, opens a network connection. |
25
|
|
|
* This method is called before a test is executed. |
26
|
|
|
*/ |
27
|
|
|
protected function setUp(): void |
28
|
|
|
{ |
29
|
|
|
parent::setUp(); |
30
|
|
|
|
31
|
|
|
parent::setLanguage(); |
32
|
|
|
|
33
|
|
|
parent::setGlobalConfig(); |
34
|
|
|
|
35
|
|
|
parent::setTheme(); |
36
|
|
|
|
37
|
|
|
$GLOBALS['dbi'] = $this->createDatabaseInterface(); |
38
|
|
|
$_SERVER['SCRIPT_NAME'] = 'index.php'; |
39
|
|
|
$GLOBALS['db'] = ''; |
40
|
|
|
$GLOBALS['table'] = ''; |
41
|
|
|
$GLOBALS['text_dir'] = 'ltr'; |
42
|
|
|
$GLOBALS['cfg']['Server']['DisableIS'] = false; |
43
|
|
|
$GLOBALS['cfg']['Server']['verbose'] = 'verbose host'; |
44
|
|
|
$GLOBALS['server'] = '1'; |
45
|
|
|
$_GET['reload_left_frame'] = '1'; |
46
|
|
|
$GLOBALS['focus_querywindow'] = 'main_pane_left'; |
47
|
|
|
$this->object = new Footer(); |
48
|
|
|
unset($GLOBALS['error_message']); |
49
|
|
|
unset($GLOBALS['sql_query']); |
50
|
|
|
$GLOBALS['errorHandler'] = new ErrorHandler(); |
51
|
|
|
$_POST = []; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Tears down the fixture, for example, closes a network connection. |
56
|
|
|
* This method is called after a test is executed. |
57
|
|
|
*/ |
58
|
|
|
protected function tearDown(): void |
59
|
|
|
{ |
60
|
|
|
parent::tearDown(); |
61
|
|
|
|
62
|
|
|
unset($this->object); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Test for getDebugMessage |
67
|
|
|
* |
68
|
|
|
* @group medium |
69
|
|
|
*/ |
70
|
|
|
public function testGetDebugMessage(): void |
71
|
|
|
{ |
72
|
|
|
$GLOBALS['cfg']['DBG']['sql'] = true; |
73
|
|
|
$_SESSION['debug']['queries'] = [ |
74
|
|
|
['count' => 1, 'time' => 0.2, 'query' => 'SELECT * FROM `pma_bookmark` WHERE 1'], |
75
|
|
|
['count' => 1, 'time' => 2.5, 'query' => 'SELECT * FROM `db` WHERE 1'], |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
$this->assertEquals( |
79
|
|
|
'{"queries":[{"count":1,"time":0.2,"query":"SELECT * FROM `pma_bookmark` WHERE 1"},' |
80
|
|
|
. '{"count":1,"time":2.5,"query":"SELECT * FROM `db` WHERE 1"}]}', |
81
|
|
|
$this->object->getDebugMessage(), |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Test for removeRecursion |
87
|
|
|
*/ |
88
|
|
|
public function testRemoveRecursion(): void |
89
|
|
|
{ |
90
|
|
|
$object = (object) []; |
91
|
|
|
$object->child = (object) []; |
92
|
|
|
$object->childIterator = new ArrayIterator(); |
93
|
|
|
$object->child->parent = $object; |
94
|
|
|
|
95
|
|
|
$this->callFunction($this->object, Footer::class, 'removeRecursion', [&$object]); |
96
|
|
|
$this->assertEquals( |
97
|
|
|
'{"child":{"parent":"***RECURSION***"},"childIterator":"***ITERATOR***"}', |
98
|
|
|
json_encode($object), |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Test for disable |
104
|
|
|
*/ |
105
|
|
|
public function testDisable(): void |
106
|
|
|
{ |
107
|
|
|
$footer = new Footer(); |
108
|
|
|
$footer->disable(); |
109
|
|
|
$this->assertEquals( |
110
|
|
|
'', |
111
|
|
|
$footer->getDisplay(), |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testGetDisplayWhenAjaxIsEnabled(): void |
116
|
|
|
{ |
117
|
|
|
$footer = new Footer(); |
118
|
|
|
$footer->setAjax(true); |
119
|
|
|
$template = new Template(); |
120
|
|
|
$this->assertEquals( |
121
|
|
|
$template->render('modals/function_confirm') . "\n" |
122
|
|
|
. $template->render('modals/add_index') . "\n" |
123
|
|
|
. $template->render('modals/page_settings') . "\n", |
124
|
|
|
$footer->getDisplay(), |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Test for footer get Scripts |
130
|
|
|
*/ |
131
|
|
|
public function testGetScripts(): void |
132
|
|
|
{ |
133
|
|
|
$footer = new Footer(); |
134
|
|
|
$this->assertStringContainsString( |
135
|
|
|
'<script data-cfasync="false" type="text/javascript">', |
136
|
|
|
$footer->getScripts()->getDisplay(), |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Test for displaying footer |
142
|
|
|
* |
143
|
|
|
* @group medium |
144
|
|
|
*/ |
145
|
|
|
public function testDisplay(): void |
146
|
|
|
{ |
147
|
|
|
$footer = new Footer(); |
148
|
|
|
$this->assertStringContainsString( |
149
|
|
|
'Open new phpMyAdmin window', |
150
|
|
|
$footer->getDisplay(), |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Test for minimal footer |
156
|
|
|
*/ |
157
|
|
|
public function testMinimal(): void |
158
|
|
|
{ |
159
|
|
|
$footer = new Footer(); |
160
|
|
|
$footer->setMinimal(); |
161
|
|
|
$template = new Template(); |
162
|
|
|
$this->assertEquals( |
163
|
|
|
$template->render('modals/function_confirm') . "\n" |
164
|
|
|
. $template->render('modals/add_index') . "\n" |
165
|
|
|
. $template->render('modals/page_settings') |
166
|
|
|
. "\n </div>\n </body>\n</html>\n", |
167
|
|
|
$footer->getDisplay(), |
168
|
|
|
); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function testSetAjax(): void |
172
|
|
|
{ |
173
|
|
|
$isAjax = new ReflectionProperty(Footer::class, 'isAjax'); |
174
|
|
|
$footer = new Footer(); |
175
|
|
|
|
176
|
|
|
$this->assertFalse($isAjax->getValue($footer)); |
177
|
|
|
$footer->setAjax(true); |
178
|
|
|
$this->assertTrue($isAjax->getValue($footer)); |
179
|
|
|
$footer->setAjax(false); |
180
|
|
|
$this->assertFalse($isAjax->getValue($footer)); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths