Translated using Weblate (Japanese)
[phpmyadmin.git] / test / libraries / PMA_SetupIndex_test.php
blobcef00df5259e40fb8b93b134d06bc8f7071a0292
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * tests for methods under setup/lib/index.lib.php
6 * @package PhpMyAdmin-test
7 */
9 /*
10 * Include to test
12 use PMA\libraries\config\ConfigFile;
13 use PMA\libraries\config\ServerConfigChecks;
15 require_once 'libraries/config/config_functions.lib.php';
16 require_once 'setup/lib/index.lib.php';
18 /**
19 * tests for methods under setup/lib/index.lib.php
21 * @package PhpMyAdmin-test
23 class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
25 /**
26 * SetUp for test cases
28 * @return void
30 public function setup()
32 $GLOBALS['cfg']['ProxyUrl'] = '';
35 /**
36 * Test for PMA_messagesBegin()
38 * @return void
40 public function testPMAmessagesBegin()
42 $_SESSION['messages'] = array(
43 array(
44 array('foo'),
45 array('bar')
49 PMA_messagesBegin();
51 $this->assertEquals(
52 array(
53 array(
54 array(
55 0 => 'foo',
56 'fresh' => false,
57 'active' => false
59 array(
60 0 => 'bar',
61 'fresh' => false,
62 'active' => false
66 $_SESSION['messages']
69 // case 2
71 unset($_SESSION['messages']);
72 PMA_messagesBegin();
73 $this->assertEquals(
74 array(
75 'error' => array(),
76 'notice' => array()
78 $_SESSION['messages']
82 /**
83 * Test for PMA_messagesSet
85 * @return void
87 public function testPMAmessagesSet()
89 PMA_messagesSet('type', '123', 'testTitle', 'msg');
91 $this->assertEquals(
92 array(
93 'fresh' => true,
94 'active' => true,
95 'title' => 'testTitle',
96 'message' => 'msg'
98 $_SESSION['messages']['type']['123']
103 * Test for PMA_messagesEnd
105 * @return void
107 public function testPMAmessagesEnd()
109 $_SESSION['messages'] = array(
110 array(
111 array('msg' => 'foo', 'active' => false),
112 array('msg' => 'bar', 'active' => true),
116 PMA_messagesEnd();
118 $this->assertEquals(
119 array(
120 array(
121 '1' => array(
122 'msg' => 'bar',
123 'active' => 1
127 $_SESSION['messages']
132 * Test for PMA_messagesShowHtml
134 * @return void
136 public function testPMAMessagesShowHTML()
138 $_SESSION['messages'] = array(
139 'type' => array(
140 array('title' => 'foo', 'message' => '123', 'fresh' => false),
141 array('title' => 'bar', 'message' => '321', 'fresh' => true),
145 ob_start();
146 PMA_messagesShowHtml();
147 $result = ob_get_clean();
149 $this->assertContains(
150 '<div class="type hiddenmessage" id="0"><h4>foo</h4>123</div>',
151 $result
154 $this->assertContains(
155 '<div class="type" id="1"><h4>bar</h4>321</div>',
156 $result
162 * Test for ServerConfigChecks::performConfigChecks
164 * @return void
165 * @group medium
167 public function testServerConfigChecksPerformConfigChecks()
170 $GLOBALS['cfg']['AvailableCharsets'] = array();
171 $GLOBALS['cfg']['ServerDefault'] = 0;
172 $GLOBALS['server'] = 0;
174 $cf = new ConfigFile();
175 $GLOBALS['ConfigFile'] = $cf;
177 $reflection = new \ReflectionProperty('PMA\libraries\config\ConfigFile', '_id');
178 $reflection->setAccessible(true);
179 $sessionID = $reflection->getValue($cf);
181 $_SESSION[$sessionID]['Servers'] = array(
182 '1' => array(
183 'host' => 'localhost',
184 'ssl' => false,
185 'extension' => 'mysql',
186 'auth_type' => 'config',
187 'user' => 'username',
188 'password' => 'password',
189 'AllowRoot' => true,
190 'AllowNoPassword' => true,
194 $_SESSION[$sessionID]['AllowArbitraryServer'] = true;
195 $_SESSION[$sessionID]['LoginCookieValidity'] = 5000;
196 $_SESSION[$sessionID]['LoginCookieStore'] = 4000;
197 $_SESSION[$sessionID]['SaveDir'] = true;
198 $_SESSION[$sessionID]['TempDir'] = true;
199 $_SESSION[$sessionID]['GZipDump'] = true;
200 $_SESSION[$sessionID]['BZipDump'] = true;
201 $_SESSION[$sessionID]['ZipDump'] = true;
203 $noticeArrayKeys = array(
204 'TempDir',
205 'SaveDir',
206 'LoginCookieValidity',
207 'AllowArbitraryServer',
208 'Servers/1/AllowNoPassword',
209 'Servers/1/auth_type',
210 'Servers/1/ssl'
213 $errorArrayKeys = array(
214 'LoginCookieValidity'
217 if (@!function_exists('gzopen') || @!function_exists('gzencode')) {
218 $errorArrayKeys[] = 'GZipDump';
221 if (@!function_exists('bzopen') || @!function_exists('bzcompress')) {
222 $errorArrayKeys[] = 'BZipDump';
225 if (!@function_exists('zip_open')) {
226 $errorArrayKeys[] = 'ZipDump_import';
229 if (!@function_exists('gzcompress')) {
230 $errorArrayKeys[] = 'ZipDump_export';
233 $configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
234 $configChecker->performConfigChecks();
236 foreach ($noticeArrayKeys as $noticeKey) {
237 $this->assertArrayHasKey(
238 $noticeKey,
239 $_SESSION['messages']['notice']
243 foreach ($errorArrayKeys as $errorKey) {
244 $this->assertArrayHasKey(
245 $errorKey,
246 $_SESSION['messages']['error']
250 // Case 2
252 unset($_SESSION['messages']);
253 unset($_SESSION[$sessionID]);
255 $_SESSION[$sessionID]['Servers'] = array(
256 '1' => array(
257 'host' => 'localhost',
258 'ssl' => true,
259 'extension' => 'mysqli',
260 'auth_type' => 'cookie',
261 'AllowRoot' => false
265 $_SESSION[$sessionID]['AllowArbitraryServer'] = false;
266 $_SESSION[$sessionID]['LoginCookieValidity'] = -1;
267 $_SESSION[$sessionID]['LoginCookieStore'] = 0;
268 $_SESSION[$sessionID]['SaveDir'] = '';
269 $_SESSION[$sessionID]['TempDir'] = '';
270 $_SESSION[$sessionID]['GZipDump'] = false;
271 $_SESSION[$sessionID]['BZipDump'] = false;
272 $_SESSION[$sessionID]['ZipDump'] = false;
274 $configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
275 $configChecker->performConfigChecks();
277 $this->assertArrayHasKey(
278 'blowfish_secret_created',
279 $_SESSION['messages']['notice']
282 foreach ($noticeArrayKeys as $noticeKey) {
283 $this->assertArrayNotHasKey(
284 $noticeKey,
285 $_SESSION['messages']['notice']
289 $this->assertArrayNotHasKey(
290 'error',
291 $_SESSION['messages']
294 // Case 3
296 $_SESSION[$sessionID]['blowfish_secret'] = 'sec';
298 $_SESSION[$sessionID]['Servers'] = array(
299 '1' => array(
300 'host' => 'localhost',
301 'auth_type' => 'cookie'
305 $configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']);
306 $configChecker->performConfigChecks();
308 $this->assertArrayHasKey(
309 'blowfish_warnings2',
310 $_SESSION['messages']['error']