Fixed: Not selecting a datalabel used to issue a notice(undefined offset)
[phpmyadmin/ammaryasirr.git] / test / classes / PMA_Config_test.php
blob334095781034099b23a16cfa7af7309d3108f9b1
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Test for PMA_Config class
7 * @package phpMyAdmin-test
8 * @group current
9 */
12 * Include to test.
14 require_once 'libraries/Config.class.php';
15 require_once 'libraries/relation.lib.php';
17 class PMA_ConfigTest extends PHPUnit_Framework_TestCase
19 /**
20 * Turn off backup globals
22 protected $backupGlobals = FALSE;
24 /**
25 * @var PMA_Config
27 protected $object;
29 /**
30 * Sets up the fixture, for example, opens a network connection.
31 * This method is called before a test is executed.
33 protected function setUp()
35 $this->object = new PMA_Config;
38 /**
39 * Tears down the fixture, for example, closes a network connection.
40 * This method is called after a test is executed.
42 protected function tearDown()
46 public function testCheckSystem()
48 $this->object->checkSystem();
50 $this->assertNotNull($this->object->get('PMA_VERSION'));
51 $this->assertNotEmpty($this->object->get('PMA_THEME_VERSION'));
52 $this->assertNotEmpty($this->object->get('PMA_THEME_GENERATION'));
55 public function testCheckOutputCompression()
58 $this->object->set('OBGzip', 'auto');
60 $this->object->set('PMA_USR_BROWSER_AGENT', 'IE');
61 $this->object->set('PMA_USR_BROWSER_VER', 6);
62 $this->object->checkOutputCompression();
63 $this->assertFalse($this->object->get("OBGzip"));
65 $this->object->set('OBGzip', 'auto');
66 $this->object->set('PMA_USR_BROWSER_AGENT', 'MOZILLA');
67 $this->object->set('PMA_USR_BROWSER_VER', 5);
68 $this->object->checkOutputCompression();
69 $this->assertEquals('auto',$this->object->get("OBGzip"));
71 ini_set('zlib.output_compression', 'Off');
72 $this->object->checkOutputCompression();
73 $this->assertFalse($this->object->get("OBGzip"));
75 ini_set('zlib.output_compression', 'On');
78 public function testCheckClient()
80 $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.80 (X11; Linux x86_64; U; pl) Presto/2.7.62 Version/11.00';
81 $this->object->checkClient();
82 $this->assertEquals("Linux", $this->object->get('PMA_USR_OS'), "User OS expected to be Linux");
83 $this->assertEquals("OPERA", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Opera");
84 $this->assertEquals("9.80", $this->object->get('PMA_USR_BROWSER_VER'), "Browser ver expected to be 9.80");
86 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US) AppleWebKit/528.16 OmniWeb/622.8.0.112941';
87 $this->object->checkClient();
88 $this->assertEquals("Mac", $this->object->get('PMA_USR_OS'), "User OS expected to be Mac");
89 $this->assertEquals("OMNIWEB", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be OmniWeb");
91 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)';
92 $this->object->checkClient();
93 $this->assertEquals("Win", $this->object->get('PMA_USR_OS'), "User OS expected to be Windows");
94 $this->assertEquals("IE", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be IE");
96 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Unknown; U; Unix BSD/SYSV system; C -) AppleWebKit/527+ (KHTML, like Gecko, Safari/419.3) Arora/0.10.2';
97 $this->object->checkClient();
98 $this->assertEquals("Unix", $this->object->get('PMA_USR_OS'), "User OS expected to be Unix");
100 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/4.0 (compatible; OS/2 Webexplorer)';
101 $this->object->checkClient();
102 $this->assertEquals("OS/2", $this->object->get('PMA_USR_OS'), "User OS expected to be OS/2");
104 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Win95; en-US; rv:1.9b) Gecko/20031208';
105 $this->object->checkClient();
106 $this->assertEquals("GECKO", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Gecko");
108 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; Konqueror/4.5; NetBSD 5.0.2; X11; amd64; en_US) KHTML/4.5.4 (like Gecko)';
109 $this->object->checkClient();
110 $this->assertEquals("KONQUEROR", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Konqueror");
112 $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20100101 Firefox/5.0';
113 $this->object->checkClient();
114 $this->assertEquals("MOZILLA", $this->object->get('PMA_USR_BROWSER_AGENT'), "Browser expected to be Mozilla");
115 $this->assertEquals("Linux", $this->object->get('PMA_USR_OS'), "User OS expected to be Linux");
119 public function testCheckGd2()
121 $prevIsGb2Val = $this->object->get('PMA_IS_GD2');
123 $this->object->set('GD2Available','yes');
124 $this->object->checkGd2();
125 $this->assertEquals(1, $this->object->get('PMA_IS_GD2'));
127 $this->object->set('GD2Available','no');
128 $this->object->checkGd2();
129 $this->assertEquals(0, $this->object->get('PMA_IS_GD2'));
131 $this->object->set('GD2Available',$prevIsGb2Val);
133 if (!@function_exists('imagecreatetruecolor'))
135 $this->object->checkGd2();
136 $this->assertEquals(0, $this->object->get('PMA_IS_GD2'), 'Function imagecreatetruecolor does not exist, PMA_IS_GD2 should be 0');
139 if (@function_exists('gd_info')) {
140 $this->object->checkGd2();
141 $gd_nfo = gd_info();
142 if (strstr($gd_nfo["GD Version"], '2.')) {
143 $this->assertEquals(1, $this->object->get('PMA_IS_GD2'), 'GD Version >= 2, PMA_IS_GD2 should be 1');
144 } else {
145 $this->assertEquals(0, $this->object->get('PMA_IS_GD2'), 'GD Version < 2, PMA_IS_GD2 should be 0');
149 /* Get GD version string from phpinfo output */
150 ob_start();
151 phpinfo(INFO_MODULES); /* Only modules */
152 $a = strip_tags(ob_get_contents());
153 ob_end_clean();
155 if (preg_match('@GD Version[[:space:]]*\(.*\)@', $a, $v)) {
156 if (strstr($v, '2.')) {
157 $this->assertEquals(1, $this->object->get('PMA_IS_GD2'), 'PMA_IS_GD2 should be 1');
158 } else {
159 $this->assertEquals(0, $this->object->get('PMA_IS_GD2'), 'PMA_IS_GD2 should be 0');
164 public function testCheckWebServer()
166 $_SERVER['SERVER_SOFTWARE'] = "Microsoft-IIS 7.0";
167 $this->object->checkWebServer();
168 $this->assertEquals(1, $this->object->get('PMA_IS_IIS'));
170 $_SERVER['SERVER_SOFTWARE'] = "Apache/2.2.17";
171 $this->object->checkWebServer();
172 $this->assertEquals(0, $this->object->get('PMA_IS_IIS'));
174 unset($_SERVER['SERVER_SOFTWARE']);
177 public function testCheckWebServerOs()
179 $this->object->checkWebServerOs();
181 if (defined('PHP_OS'))
183 switch (PHP_OS)
185 case stristr(PHP_OS,'win'):
186 $this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'), 'PHP_OS equals: ' . PHP_OS . ' PMA_IS_WINDOWS should be 1');
187 break;
188 case stristr(PHP_OS, 'OS/2'):
189 $this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'), 'PHP_OS is OS/2 PMA_IS_WINDOWS should be 1 (No file permissions like Windows)');
190 break;
191 case stristr(PHP_OS, 'Linux'):
192 $this->assertEquals(0, $this->object->get('PMA_IS_WINDOWS'));
193 break;
196 else
198 $this->assertEquals(0, $this->object->get('PMA_IS_WINDOWS'), 'PMA_IS_WINDOWS Default to Unix or Equiv');
200 define('PHP_OS','Windows');
201 $this->assertEquals(1, $this->object->get('PMA_IS_WINDOWS'), 'PMA_IS_WINDOWS must be 1');
205 public function testCheckPhpVersion()
207 $this->object->checkPhpVersion();
209 $php_int_ver = 0;
210 $php_str_ver = phpversion();
212 $match = array();
213 preg_match('@([0-9]{1,2}).([0-9]{1,2}).([0-9]{1,2})@', phpversion(), $match);
214 if (isset($match) && ! empty($match[1])) {
215 if (! isset($match[2])) {
216 $match[2] = 0;
218 if (! isset($match[3])) {
219 $match[3] = 0;
221 $php_int_ver = (int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]);
222 } else {
223 $php_int_ver = 0;
226 $this->assertEquals($php_str_ver, $this->object->get('PMA_PHP_STR_VERSION'));
227 $this->assertEquals($php_int_ver, $this->object->get('PMA_PHP_INT_VERSION'));
230 public function testLoadDefaults()
232 $prevDefaultSource = $this->object->default_source;
234 $this->object->default_source = 'unexisted.file.php';
235 $this->assertFalse($this->object->loadDefaults());
237 $this->object->default_source = $prevDefaultSource;
239 include $this->object->default_source;
241 $loadedConf = $cfg;
242 unset($cfg);
244 $this->assertTrue($this->object->loadDefaults());
246 $this->assertEquals($this->object->default_source_mtime, filemtime($prevDefaultSource));
247 $this->assertEquals($loadedConf['Servers'][1], $this->object->default_server);
249 unset($loadedConf['Servers']);
251 $this->assertEquals($loadedConf, $this->object->default);
253 $expectedSettings = PMA_array_merge_recursive($this->object->settings, $loadedConf);
255 $this->assertEquals($expectedSettings, $this->object->settings,'Settings loaded wrong');
257 $this->assertFalse($this->object->error_config_default_file);
260 public function testCheckConfigSource()
262 $this->object->setSource('unexisted.config.php');
263 $this->assertFalse($this->object->checkConfigSource());
264 $this->assertEquals(0, $this->object->source_mtime);
266 // if(! is_readable($this->object->getSource()))
267 // $this->markTestSkipped('Configuration file is read only');
269 $this->object->setSource('libraries/config.default.php');
271 $this->assertNotEmpty($this->object->getSource());
272 $this->assertTrue($this->object->checkConfigSource());
276 * @covers PMA_Config::get
277 * @covers PMA_Config::set
278 * @return void
280 public function testGetAndSet()
282 $this->assertNull($this->object->get("unresisting_setting"));
284 $this->object->set('test_setting', 'test_value');
286 $this->assertEquals('test_value', $this->object->get('test_setting'));
290 * @covers PMA_Config::getSource
291 * @covers PMA_Config::setSource
293 public function testGetSetSource()
295 echo $this->object->getSource();
297 $this->assertEmpty($this->object->getSource(), "Source is null by default");
299 $this->object->setSource("config.sample.inc.php");
301 $this->assertEquals("config.sample.inc.php", $this->object->getSource(), "Cant set new source");
304 public function testCheckPmaAbsoluteUriEmpty()
306 $this->object->set('PmaAbsoluteUri','');
307 $this->assertFalse($this->object->checkPmaAbsoluteUri(), 'PmaAbsoluteUri is not set and should be error');
308 $this->assertTrue($this->object->error_pma_uri, 'PmaAbsoluteUri is not set and should be error');
312 * @depends testCheckPmaAbsoluteUriEmpty
314 public function testCheckPmaAbsoluteUriNormal()
316 $this->object->set('PmaAbsoluteUri','http://localhost/phpmyadmin/');
317 $this->object->checkPmaAbsoluteUri();
318 $this->assertEquals("http://localhost/phpmyadmin/", $this->object->get('PmaAbsoluteUri'));
320 $this->object->set('PmaAbsoluteUri','http://localhost/phpmyadmin');
321 $this->object->checkPmaAbsoluteUri();
322 $this->assertEquals("http://localhost/phpmyadmin/", $this->object->get('PmaAbsoluteUri'), 'Expected trailing slash at the end of the phpMyAdmin uri');
327 * @depends testCheckPmaAbsoluteUriNormal
329 public function testCheckPmaAbsoluteUriScheme()
331 $_SERVER['HTTP_HOST'] = 'localhost';
332 $_SERVER['HTTP_SCHEME'] = 'http';
333 $_SERVER['HTTPS'] = 'off';
334 $GLOBALS['PMA_PHP_SELF'] = 'index.php';
336 $this->object->set('PmaAbsoluteUri','');
338 $this->object->checkPmaAbsoluteUri();
339 $this->assertEquals("http://localhost/", $this->object->get('PmaAbsoluteUri'));
343 * @depends testCheckPmaAbsoluteUriScheme
345 public function testCheckPmaAbsoluteUriUser()
347 $this->object->set('PmaAbsoluteUri','http://user:pwd@localhost/phpmyadmin/index.php');
349 $this->object->checkPmaAbsoluteUri();
350 $this->assertEquals("http://user:pwd@localhost/phpmyadmin/index.php/", $this->object->get('PmaAbsoluteUri'));
352 $this->object->set('PmaAbsoluteUri','https://user:pwd@localhost/phpmyadmin/index.php');
354 $this->object->checkPmaAbsoluteUri();
355 $this->assertEquals("https://user:pwd@localhost/phpmyadmin/index.php/", $this->object->get('PmaAbsoluteUri'));
358 public function testCheckCollationConnection()
360 $_REQUEST['collation_connection'] = 'utf-8';
361 $this->object->checkCollationConnection();
363 $this->assertEquals($_REQUEST['collation_connection'], $this->object->get('collation_connection'));
366 public function testIsHttps()
368 $this->object->set('PmaAbsoluteUri', 'http://some_host.com/phpMyAdmin');
369 $this->assertFalse($this->object->isHttps());
371 $this->object->set('PmaAbsoluteUri', 'https://some_host.com/phpMyAdmin');
372 $this->assertFalse($this->object->isHttps());
375 public function testDetectHttps()
377 unset($_SERVER['REQUEST_URI']);
378 unset($_SERVER['HTTP_SCHEME']);
379 unset($_SERVER['HTTPS']);
381 $this->assertFalse($this->object->detectHttps());
383 $_SERVER['REQUEST_URI'] = '/url:\this_is_not_url';
384 $this->assertFalse($this->object->detectHttps());
386 $_SERVER['REQUEST_URI'] = 'file://localhost/phpmyadmin/index.php';
387 $this->assertFalse($this->object->detectHttps());
389 $_ENV['REQUEST_URI'] = 'http://localhost/phpmyadmin/index.php';
390 $this->assertFalse($this->object->detectHttps());
392 $_SERVER['REQUEST_URI'] = 'https://localhost/phpmyadmin/index.php';
393 $this->assertTrue($this->object->detectHttps());
395 $_SERVER['REQUEST_URI'] = 'localhost/phpmyadmin/index.php';
396 $_SERVER['HTTP_SCHEME'] = 'https';
397 $_SERVER['HTTPS'] = 'on';
398 $this->assertTrue($this->object->detectHttps());
402 * @depends testDetectHttps
404 public function testCheckCookiePath()
406 $this->object->checkCookiePath();
407 echo $this->object->get('cookie_path');
408 $this->assertEquals('',$this->object->get('cookie_path'));
412 * @depends testCheckSystem
413 * @depends testCheckWebServer
414 * @depends testLoadDefaults
415 * @depends testLoad
417 public function testEnableBc()
419 $this->object->enableBc();
421 $defines = array(
422 'PMA_VERSION',
423 'PMA_THEME_VERSION',
424 'PMA_THEME_GENERATION',
425 'PMA_PHP_STR_VERSION',
426 'PMA_PHP_INT_VERSION',
427 'PMA_IS_WINDOWS',
428 'PMA_IS_IIS',
429 'PMA_IS_GD2',
430 'PMA_USR_OS',
431 'PMA_USR_BROWSER_VER',
432 'PMA_USR_BROWSER_AGENT'
435 foreach ($defines as $define)
437 $this->assertTrue(defined($define));
438 $this->assertEquals(constant($define), $this->object->get($define));
443 * @todo Implement testSave().
445 public function testSave()
447 // Remove the following lines when you implement this test.
448 $this->markTestIncomplete(
449 'This test has not been implemented yet.'
454 * @todo Implement testGetFontsizeForm().
456 public function testGetFontsizeForm()
458 // Remove the following lines when you implement this test.
459 $this->markTestIncomplete(
460 'This test has not been implemented yet.'
465 * @todo Implement testRemoveCookie().
467 public function testRemoveCookie()
469 // Remove the following lines when you implement this test.
470 $this->markTestIncomplete(
471 'This test has not been implemented yet.'
475 * @todo Implement testCheckFontsize().
477 public function testCheckFontsize()
479 // Remove the following lines when you implement this test.
480 $this->markTestIncomplete(
481 'This test has not been implemented yet.'
486 * @todo Implement testCheckUpload().
488 public function testCheckUpload()
490 // Remove the following lines when you implement this test.
491 $this->markTestIncomplete(
492 'This test has not been implemented yet.'
497 * @todo Implement testCheckUploadSize().
499 public function testCheckUploadSize()
501 // Remove the following lines when you implement this test.
502 $this->markTestIncomplete(
503 'This test has not been implemented yet.'
508 * @todo Implement testCheckIsHttps().
510 public function testCheckIsHttps()
512 // Remove the following lines when you implement this test.
513 $this->markTestIncomplete(
514 'This test has not been implemented yet.'
519 * @todo Implement testGetCookiePath().
521 public function testGetCookiePath()
523 // Remove the following lines when you implement this test.
524 $this->markTestIncomplete(
525 'This test has not been implemented yet.'
530 * @todo finish implementing test + dependencies
532 public function testLoad()
534 $this->assertFalse($this->object->load());
536 $this->assertTrue($this->object->load('./libraries/config.default.php'));
540 * @todo Implement testLoadUserPreferences().
542 public function testLoadUserPreferences()
544 $this->assertNull($this->object->loadUserPreferences());
546 // echo $GLOBALS['cfg']['ServerDefault'];
550 * @todo Implement testSetUserValue().
552 public function testSetUserValue()
554 $this->object->setUserValue(null, 'lang', $GLOBALS['lang'], 'en');
555 $this->object->setUserValue("TEST_COOKIE_USER_VAL",'','cfg_val_1');
557 // Remove the following lines when you implement this test.
558 // $this->markTestIncomplete(
559 // 'This test has not been implemented yet.'
560 // );
564 * @todo Implement testGetUserValue().
566 public function testGetUserValue()
568 // Remove the following lines when you implement this test.
569 $this->markTestIncomplete(
570 'This test has not been implemented yet.'
575 * @todo Implement testGetThemeUniqueValue().
577 public function testGetThemeUniqueValue()
579 // Remove the following lines when you implement this test.
580 $this->markTestIncomplete(
581 'This test has not been implemented yet.'
586 * @todo Implement testCheckPermissions().
588 public function testCheckPermissions()
590 // Remove the following lines when you implement this test.
591 $this->markTestIncomplete(
592 'This test has not been implemented yet.'
598 * @todo Implement testSetCookie().
600 public function testSetCookie()
602 $this->assertFalse($this->object->setCookie('TEST_DEF_COOKIE', 'test_def_123', 'test_def_123'));
604 $this->assertTrue($this->object->setCookie('TEST_CONFIG_COOKIE', 'test_val_123', null, 3600));
606 $this->assertTrue($this->object->setCookie('TEST_CONFIG_COOKIE', '', 'default_val'));
608 $_COOKIE['TEST_MANUAL_COOKIE'] = 'some_test_val';
609 $this->assertTrue($this->object->setCookie('TEST_MANUAL_COOKIE', 'other', 'other'));