This commit is contained in:
Marc Delisle
2009-12-31 13:11:19 +00:00
parent f3833884e4
commit 526dce65cb
894 changed files with 287313 additions and 0 deletions

39
test/AllSeleniumTests.php Normal file
View File

@@ -0,0 +1,39 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* runs all defined Selenium tests
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
require_once './PmaSeleniumTestCase.php';
require_once './PmaSeleniumLoginTest.php';
require_once './PmaSeleniumXssTest.php';
require_once './PmaSeleniumPrivilegesTest.php';
class AllSeleniumTests
{
public static function main()
{
$parameters = array();
PHPUnit_TextUI_TestRunner::run(self::suite(), $parameters);
}
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('phpMyAdmin');
$suite->addTestSuite('PmaSeleniumLoginTest');
$suite->addTestSuite('PmaSeleniumXssTest');
$suite->addTestSuite('PmaSeleniumPrivilegesTest');
return $suite;
}
}
?>

97
test/AllTests.php Normal file
View File

@@ -0,0 +1,97 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* runs all defined tests
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
if (! defined('PMA_MAIN_METHOD')) {
define('PMA_MAIN_METHOD', 'AllTests::main');
chdir('..');
}
// required to not die() in some libraries
define('PHPMYADMIN', true);
// just add $_SESSION array once, so no need to test for existance evrywhere to get rid of NOtices about this
if (empty($_SESSION)) {
$_SESSION = array();
}
/**
*
*/
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
//require_once 'PHPUnit/Util/TestDox/ResultPrinter.php.';
require_once './test/FailTest.php';
require_once './test/PMA_get_real_size_test.php';
require_once './test/PMA_sanitize_test.php';
require_once './test/PMA_pow_test.php';
require_once './test/Environment_test.php';
require_once './test/PMA_escapeJsString_test.php';
require_once './test/PMA_isValid_test.php';
require_once './test/PMA_transformation_getOptions_test.php';
require_once './test/PMA_STR_sub_test.php';
require_once './test/PMA_generateCommonUrl_test.php';
require_once './test/PMA_blowfish_test.php';
require_once './test/PMA_escapeMySqlWildcards_test.php';
require_once './test/PMA_showHint_test.php';
require_once './test/PMA_formatNumberByteDown_test.php';
require_once './test/PMA_localisedDateTimespan_test.php';
require_once './test/PMA_cache_test.php';
require_once './test/PMA_quoting_slashing_test.php';
require_once './test/PMA_stringOperations_test.php';
require_once './test/PMA_printableBitValue_test.php';
require_once './test/PMA_foreignKeySupported_test.php';
require_once './test/PMA_headerLocation_test.php';
require_once './test/PMA_Message_test.php';
require_once './test/PMA_whichCrlf_test.php';
class AllTests
{
public static function main()
{
$parameters = array();
//$parameters['testdoxHTMLFile'] = true;
//$parameters['printer'] = PHPUnit_Util_TestDox_ResultPrinter::factory('HTML');
//$parameters['printer'] = PHPUnit_Util_TestDox_ResultPrinter::factory('Text');
PHPUnit_TextUI_TestRunner::run(self::suite(), $parameters);
}
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('phpMyAdmin');
//$suite->addTestSuite('FailTest');
$suite->addTestSuite('Environment_test');
$suite->addTestSuite('PMA_get_real_size_test');
$suite->addTestSuite('PMA_sanitize_test');
$suite->addTestSuite('PMA_pow_test');
$suite->addTestSuite('PMA_escapeJsString_test');
$suite->addTestSuite('PMA_isValid_test');
$suite->addTestSuite('PMA_transformation_getOptions_test');
$suite->addTestSuite('PMA_STR_sub_test');
$suite->addTestSuite('PMA_generate_common_url_test');
$suite->addTestSuite('PMA_blowfish_test');
$suite->addTestSuite('PMA_escapeMySqlWildcards_test');
$suite->addTestSuite('PMA_showHint_test');
$suite->addTestSuite('PMA_formatNumberByteDown_test');
$suite->addTestSuite('PMA_localisedDateTimespan_test');
$suite->addTestSuite('PMA_cache_test');
$suite->addTestSuite('PMA_quoting_slashing_test');
$suite->addTestSuite('PMA_stringOperations_test');
$suite->addTestSuite('PMA_printableBitValue_test');
$suite->addTestSuite('PMA_foreignKeySupported_test');
$suite->addTestSuite('PMA_headerLocation_test');
$suite->addTestSuite('PMA_Message_test');
$suite->addTestSuite('PMA_whichCrlf_test');
return $suite;
}
}
?>

36
test/Environment_test.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for environment like OS, PHP, modules, ...
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'PHPUnit/Framework.php';
/**
* @package phpMyAdmin-test
*/
class Environment_test extends PHPUnit_Framework_TestCase
{
public function testPhpVersion()
{
$this->assertTrue(version_compare('5.2', phpversion(), '<='),
'phpMyAdmin requires PHP 5.2 or above');
}
public function testMySQL()
{
$this->markTestIncomplete();
}
public function testSession()
{
$this->markTestIncomplete();
}
}
?>

25
test/FailTest.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA_get_real_size()
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'PHPUnit/Framework.php';
/**
* @package phpMyAdmin-test
*/
class FailTest extends PHPUnit_Framework_TestCase
{
public function testFail()
{
$this->assertEquals(0, 1);
}
}
?>

410
test/PMA_Message_test.php Normal file
View File

@@ -0,0 +1,410 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA_Message class
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @version $Id$
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Extensions/OutputTestCase.php';
/**
* Include to test.
*/
require_once './libraries/Message.class.php';
/**
* Test class PMA_Message.
*
* @package phpMyAdmin-test
*/
class PMA_Message_test extends PHPUnit_Extensions_OutputTestCase
{
/**
* @var PMA_Message
* @access protected
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp()
{
$this->object = new PMA_Message;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
*/
protected function tearDown()
{
}
/**
* to String casting test
*/
public function test__toString()
{
$this->object->setMessage('test<&>', true);
$this->assertEquals('test&lt;&amp;&gt;', (string)$this->object);
}
/**
* test success method
*/
public function testSuccess()
{
$this->object = new PMA_Message('test<&>', PMA_Message::SUCCESS);
$this->assertEquals($this->object, PMA_Message::success('test<&>'));
$this->assertEquals('strSuccess', PMA_Message::success()->getString());
}
/**
* test error method
*/
public function testError()
{
$this->object = new PMA_Message('test<&>', PMA_Message::ERROR);
$this->assertEquals($this->object, PMA_Message::error('test<&>'));
$this->assertEquals('strError', PMA_Message::error()->getString());
}
/**
* test warning method
*/
public function testWarning()
{
$this->object = new PMA_Message('test<&>', PMA_Message::WARNING);
$this->assertEquals($this->object, PMA_Message::warning('test<&>'));
}
/**
* test notice method
*/
public function testNotice()
{
$this->object = new PMA_Message('test<&>', PMA_Message::NOTICE);
$this->assertEquals($this->object, PMA_Message::notice('test<&>'));
}
/**
* test rawError method
*/
public function testRawError()
{
$this->object = new PMA_Message('', PMA_Message::ERROR);
$this->object->setMessage('test<&>');
$this->assertEquals($this->object, PMA_Message::rawError('test<&>'));
}
/**
* test rawWarning method
*/
public function testRawWarning()
{
$this->object = new PMA_Message('', PMA_Message::WARNING);
$this->object->setMessage('test<&>');
$this->assertEquals($this->object, PMA_Message::rawWarning('test<&>'));
}
/**
* test rawNotice method
*/
public function testRawNotice()
{
$this->object = new PMA_Message('', PMA_Message::NOTICE);
$this->object->setMessage('test<&>');
$this->assertEquals($this->object, PMA_Message::rawNotice('test<&>'));
}
/**
* test rawSuccess method
*/
public function testRawSuccess()
{
$this->object = new PMA_Message('', PMA_Message::SUCCESS);
$this->object->setMessage('test<&>');
$this->assertEquals($this->object, PMA_Message::rawSuccess('test<&>'));
}
/**
* testing isSuccess method
*/
public function testIsSuccess()
{
$this->assertFalse($this->object->isSuccess());
$this->assertTrue($this->object->isSuccess(true));
}
/**
* testing isNotice method
*/
public function testIsNotice()
{
$this->assertTrue($this->object->isNotice());
$this->object->isWarning(true);
$this->assertFalse($this->object->isNotice());
$this->assertTrue($this->object->isNotice(true));
}
/**
* testing isWarning method
*/
public function testIsWarning()
{
$this->assertFalse($this->object->isWarning());
$this->assertTrue($this->object->isWarning(true));
}
/**
* testing isError method
*/
public function testIsError()
{
$this->assertFalse($this->object->isError());
$this->assertTrue($this->object->isError(true));
}
/**
* testign setter of message
*/
public function testSetMessage()
{
$this->object->setMessage('test&<>', false);
$this->assertEquals('test&<>', $this->object->getMessage());
$this->object->setMessage('test&<>', true);
$this->assertEquals('test&amp;&lt;&gt;', $this->object->getMessage());
}
/**
* testing setter of string
*/
public function testSetString()
{
$this->object->setString('test&<>', false);
$this->assertEquals('test&<>', $this->object->getString());
$this->object->setString('test&<>', true);
$this->assertEquals('test&amp;&lt;&gt;', $this->object->getString());
}
/**
* testing add param method
*/
public function testAddParam()
{
$this->object->addParam(PMA_Message::notice('test'));
$this->assertEquals(array(PMA_Message::notice('test')), $this->object->getParams());
$this->object->addParam('test', true);
$this->assertEquals(array(PMA_Message::notice('test'), 'test'), $this->object->getParams());
$this->object->addParam('test', false);
$this->assertEquals(array(PMA_Message::notice('test'), 'test', PMA_Message::notice('test')), $this->object->getParams());
}
/**
* testing add string method
*/
public function testAddString()
{
$this->object->addString('test', '*');
$this->assertEquals(array('*', PMA_Message::notice('test')), $this->object->getAddedMessages());
$this->object->addString('test', '');
$this->assertEquals(array('*', PMA_Message::notice('test'), '', PMA_Message::notice('test')), $this->object->getAddedMessages());
}
/**
* testing add messages method
*/
public function testAddMessages()
{
$this->object->addMessages(array('test', PMA_Message::rawWarning('test')), '&');
$this->assertEquals(array('&', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
}
/**
* testing add message method
*/
public function testAddMessage()
{
$this->object->addMessage('test', '');
$this->assertEquals(array(PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
$this->object->addMessage('test');
$this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test')), $this->object->getAddedMessages());
$this->object->addMessage(PMA_Message::rawWarning('test'), '&');
$this->assertEquals(array(PMA_Message::rawNotice('test'), ' ', PMA_Message::rawNotice('test'), '&', PMA_Message::rawWarning('test')), $this->object->getAddedMessages());
}
/**
* testing setter of params
*/
public function testSetParams()
{
$this->object->setParams('test&<>');
$this->assertEquals('test&<>', $this->object->getParams());
$this->object->setParams('test&<>', true);
$this->assertEquals('test&amp;&lt;&gt;', $this->object->getParams());
}
/**
* testing sanitize method
*/
public function testSanitize()
{
$this->object->setString('test&string<>', false);
$this->assertEquals('test&amp;string&lt;&gt;', PMA_Message::sanitize($this->object));
$this->assertEquals(array('test&amp;string&lt;&gt;', 'test&amp;string&lt;&gt;'), PMA_Message::sanitize(array($this->object, $this->object)));
}
public function decodeBBDataProvider()
{
return array(
array('[i]test[/i][i]aa[i/][em]test[/em]', '<em>test</em><em>aa[i/]<em>test</em>'),
array('[b]test[/b][strong]test[/strong]', '<strong>test</strong><strong>test</strong>'),
array('[tt]test[/tt][code]test[/code]', '<code>test</code><code>test</code>'),
array('[kbd]test[/kbd][br][sup]test[/sup]', '<kbd>test</kbd><br /><sup>test</sup>')
);
}
/**
* testing decodeBB method
* @dataProvider decodeBBDataProvider
*/
public function testDecodeBB($actual, $expected)
{
$this->assertEquals($expected, PMA_Message::decodeBB($actual));
}
/**
* testing format method
*/
public function testFormat()
{
$this->assertEquals('test string', PMA_Message::format('test string'));
$this->assertEquals('test string', PMA_Message::format('test string', 'a'));
$this->assertEquals('test string', PMA_Message::format('test string', array()));
$this->assertEquals('test string', PMA_Message::format('%s string', array('test')));
}
/**
* testing getHash method
*/
public function testGetHash()
{
$this->object->setString('<&>test', false);
$this->object->setMessage('<&>test', false);
$this->assertEquals(md5(PMA_Message::NOTICE . '<&>test<&>test'), $this->object->getHash());
}
/**
* getMessage test - with empty message and with non-empty string - not key in globals
* additional params are defined
*/
public function testGetMessageWithoutMessageWithStringWithParams()
{
$this->object->setMessage('');
$this->object->setString('test string %s %s');
$this->object->addParam('test param 1');
$this->object->addParam('test param 2');
$this->assertEquals('test string test param 1 test param 2', $this->object->getMessage());
}
/**
* getMessage test - with empty message and with empty string
*/
public function testGetMessageWithoutMessageWithEmptyString()
{
$this->object->setMessage('');
$this->object->setString('');
$this->assertEquals('', $this->object->getMessage());
}
/**
* getMessage test - with empty message and with string, which is key to GLOBALS
* additional messages are defined
*/
public function testGetMessageWithoutMessageWithGlobalStringWithAddMessages()
{
$GLOBALS['key'] = 'test message';
$this->object->setMessage('');
$this->object->setString('key');
$this->object->addMessage('test message 2', ' - ');
$this->object->addMessage('test message 3', '&');
$this->assertEquals('test message - test message 2&test message 3', $this->object->getMessage());
unset($GLOBALS['key']);
}
/**
* getMessage test - message is defined
* message with BBCode defined
*/
public function testGetMessageWithMessageWithBBCode()
{
$this->object->setMessage('[kbd]test[/kbd] [a@./Documentation.html#cfg_Example@_blank]test[/a]');
$this->assertEquals('<kbd>test</kbd> <a href="./Documentation.html#cfg_Example" target="_blank">test</a>', $this->object->getMessage());
}
/**
* getLevel test
*/
public function testGetLevel()
{
$this->assertEquals('notice', $this->object->getLevel());
$this->object->setNumber(PMA_Message::SUCCESS);
$this->assertEquals('success', $this->object->getLevel());
$this->object->setNumber(PMA_Message::ERROR);
$this->assertEquals('error', $this->object->getLevel());
$this->object->setNumber(PMA_Message::WARNING);
$this->assertEquals('warning', $this->object->getLevel());
}
/**
* testing display method (output string and _is_displayed varible)
*/
public function testDisplay()
{
$this->assertFalse($this->object->isDisplayed());
$this->object->setMessage('Test Message');
$this->expectOutputString('<div class="notice">Test Message</div>');
$this->object->display();
$this->assertTrue($this->object->isDisplayed());
}
/**
* getDisplay test
*/
public function testGetDisplay()
{
$this->object->setMessage('Test Message');
$this->assertEquals('<div class="notice">Test Message</div>', $this->object->getDisplay());
}
/**
* isDisplayed test
*/
public function testIsDisplayed()
{
$this->assertFalse($this->object->isDisplayed(false));
$this->assertTrue($this->object->isDisplayed(true));
$this->assertTrue($this->object->isDisplayed(false));
}
}
?>

52
test/PMA_STR_sub_test.php Normal file
View File

@@ -0,0 +1,52 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA_pow()
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'PHPUnit/Framework.php';
$match = array();
preg_match('@^([0-9]{1,2})(?:.([0-9]{1,2})(?:.([0-9]{1,2}))?)?@',
phpversion(), $match);
if (isset($match) && ! empty($match[1])) {
if (! isset($match[2])) {
$match[2] = 0;
}
if (! isset($match[3])) {
$match[3] = 0;
}
/**
* @ignore
*/
define('PMA_PHP_INT_VERSION',
(int) sprintf('%d%02d%02d', $match[1], $match[2], $match[3]));
} else {
/**
* @ignore
*/
define('PMA_PHP_INT_VERSION', 0);
}
$GLOBALS['charset'] = 'UTF-8';
require_once './libraries/string.lib.php';
/**
* @package phpMyAdmin-test
*/
class PMA_STR_sub_test extends PHPUnit_Framework_TestCase
{
public function testMultiByte()
{
$this->assertEquals('čšě',
PMA_substr('čšěčščěš', 0, 3));
}
}
?>

View File

@@ -0,0 +1,60 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for blowfish encryption.
*
* @package phpMyAdmin-test
* @version $Id$
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/blowfish.php';
/**
* Test java script escaping.
*
* @package phpMyAdmin-test
*/
class PMA_blowfish_test extends PHPUnit_Framework_TestCase
{
public function testEncryptDecryptNumbers()
{
$secret = '$%ÄüfuDFRR';
$string = '12345678';
$this->assertEquals($string,
PMA_blowfish_decrypt(PMA_blowfish_encrypt($string, $secret), $secret));
}
public function testEncryptDecryptChars()
{
$secret = '$%ÄüfuDFRR';
$string = 'abcDEF012!"§$%&/()=?`´"\',.;:-_#+*~öäüÖÄÜ^°²³';
$this->assertEquals($string,
PMA_blowfish_decrypt(PMA_blowfish_encrypt($string, $secret), $secret));
}
public function testEncrypt()
{
$secret = '$%ÄüfuDFRR';
$decrypted = '12345678';
$encrypted = 'kO/kc4j/nyk=';
$this->assertEquals($encrypted, PMA_blowfish_encrypt($decrypted, $secret));
}
public function testDecrypt()
{
$secret = '$%ÄüfuDFRR';
$encrypted = 'kO/kc4j/nyk=';
$decrypted = '12345678';
$this->assertEquals($decrypted, PMA_blowfish_decrypt($encrypted, $secret));
}
}
?>

104
test/PMA_cache_test.php Normal file
View File

@@ -0,0 +1,104 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for caching data in session
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @package phpMyAdmin-test
* @version $Id: PMA_cache_test.php
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/common.lib.php';
/**
* Test cache.
*
*/
class PMA_cache_test extends PHPUnit_Framework_TestCase
{
/**
* @var array temporary variable for globals array
*/
protected $tmpGlobals;
/**
* @var array temporary variable for session array
*/
protected $tmpSession;
/**
* storing globals and session
*/
public function setUp()
{
$this->tmpGlobals = $GLOBALS;
$this->tmpSession = $_SESSION;
}
/**
* Test if cached data is available after set
*/
public function testCacheExists()
{
$GLOBALS['server'] = 'server';
PMA_cacheSet('test_data', 5, true);
PMA_cacheSet('test_data_2', 5, true);
$this->assertTrue(PMA_cacheExists('test_data', true));
$this->assertTrue(PMA_cacheExists('test_data_2', 'server'));
$this->assertFalse(PMA_cacheExists('fake_data_2', true));
}
/**
* Test if cacheGet does not return data for non existing caache entries
*/
public function testCacheGet()
{
$GLOBALS['server'] = 'server';
PMA_cacheSet('test_data', 5, true);
PMA_cacheSet('test_data_2', 5, true);
$this->assertNotNull(PMA_cacheGet('test_data', true));
$this->assertNotNull(PMA_cacheGet('test_data_2', 'server'));
$this->assertNull(PMA_cacheGet('fake_data_2', true));
}
/**
* Test retrieval of cached data
*/
public function testCacheSetGet()
{
$GLOBALS['server'] = 'server';
PMA_cacheSet('test_data', 25, true);
PMA_cacheSet('test_data', 5, true);
$this->assertEquals(5, $_SESSION['cache']['server_server']['test_data']);
PMA_cacheSet('test_data_3', 3, true);
$this->assertEquals(3, $_SESSION['cache']['server_server']['test_data_3']);
}
/**
* Test clearing cached values
*/
public function testCacheUnSet()
{
$GLOBALS['server'] = 'server';
PMA_cacheSet('test_data', 25, true);
PMA_cacheSet('test_data_2', 25, true);
PMA_cacheUnset('test_data', true);
$this->assertArrayNotHasKey('test_data', $_SESSION['cache']['server_server']);
PMA_cacheUnset('test_data_2', true);
$this->assertArrayNotHasKey('test_data_2', $_SESSION['cache']['server_server']);
}
}
?>

View File

@@ -0,0 +1,59 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for javascript escaping.
*
* @author Michal Čihař <michal@cihar.com>
* @package phpMyAdmin-test
* @version $Id$
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/js_escape.lib.php';
/**
* Test java script escaping.
*
* @package phpMyAdmin-test
*/
class PMA_escapeJsString_test extends PHPUnit_Framework_TestCase
{
public function testEscape_1()
{
$this->assertEquals('\\\';', PMA_escapeJsString('\';'));
}
public function testEscape_2()
{
$this->assertEquals('\r\n\\\'<scrIpt></\' + \'script>', PMA_escapeJsString("\r\n'<scrIpt></sCRIPT>"));
}
public function testEscape_3()
{
$this->assertEquals('\\\';[XSS]', PMA_escapeJsString('\';[XSS]'));
}
public function testEscape_4()
{
$this->assertEquals('</\' + \'script></head><body>[HTML]', PMA_escapeJsString('</SCRIPT></head><body>[HTML]'));
}
public function testEscape_5()
{
$this->assertEquals('"\\\'\\\\\\\'"', PMA_escapeJsString('"\'\\\'"'));
}
public function testEscape_6()
{
$this->assertEquals("\\\\\'\'\'\'\'\'\'\'\'\'\'\'\\\\", PMA_escapeJsString("\\''''''''''''\\"));
}
}
?>

View File

@@ -0,0 +1,61 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for MySQL Wildcards escaping/unescaping
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @package phpMyAdmin-test
* @version $Id$
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/common.lib.php';
/**
* Test MySQL escaping.
*
*/
class PMA_escapeMySqlWildcards_test extends PHPUnit_Framework_TestCase
{
public function escapeDataProvider() {
return array(
array('\_test', '_test'),
array('\_\\', '_\\'),
array('\\_\%', '_%'),
array('\\\_', '\_'),
array('\\\_\\\%', '\_\%'),
array('\_\\%\_\_\%', '_%__%'),
array('\%\_', '%_'),
array('\\\%\\\_', '\%\_')
);
}
/**
* PMA_escape_mysql_wildcards tests
* @dataProvider escapeDataProvider
*/
public function testEscape($a, $b)
{
$this->assertEquals($a, PMA_escape_mysql_wildcards($b));
}
/**
* PMA_unescape_mysql_wildcards tests
* @dataProvider escapeDataProvider
*/
public function testUnEscape($a, $b)
{
$this->assertEquals($b, PMA_unescape_mysql_wildcards($a));
}
}
?>

View File

@@ -0,0 +1,48 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for supporting foreign key
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @package phpMyAdmin-test
* @version $Id$
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/common.lib.php';
/**
* Test supported foreign key.
*
*/
class PMA_foreignKeySupported_test extends PHPUnit_Framework_TestCase
{
/**
* data provider for foreign key supported test
*/
public function foreignkeySupportedDataProvider() {
return array(
array('MyISAM', false),
array('innodb', true),
array('pBxT', true)
);
}
/**
* foreign key supported test
* @dataProvider foreignkeySupportedDataProvider
*/
public function testForeignkeySupported($a, $e) {
$this->assertEquals($e, PMA_foreignkey_supported($a));
}
}
?>

View File

@@ -0,0 +1,121 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for format number and byte
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @package phpMyAdmin-test
* @version $Id: PMA_formatNumberByteDown_test.php
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/common.lib.php';
/**
* Test formating number and byte.
*
*/
class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase
{
/**
* temporary variable for globals array
*/
protected $tmpGlobals;
/**
* temporary variable for session array
*/
protected $tmpSession;
/**
* storing globals and session
*/
public function setUp() {
$this->tmpGlobals = $GLOBALS;
$this->tmpSession = $_SESSION;
}
/**
* recovering globals and session
*/
public function tearDown() {
$GLOBALS = $this->tmpGlobals;
$_SESSION = $this->tmpSession;
}
/**
* format number data provider
*/
public function formatNumberDataProvider() {
return array(
array(10, 2, 2, '10,00 '),
array(100, 2, 0, '100 '),
array(100, 2, 2, '0,10 k'),
array(-1000.454, 4, 2, '-1 000,45 '),
array(0.00003, 3, 2, '0,03 m'),
array(0.003, 3, 3, '0,003 '),
array(-0.003, 6, 0, '-3 m'),
array(100.98, 0, 2, '100,98')
);
}
/**
* format number test, globals are defined
* @dataProvider formatNumberDataProvider
*/
public function testFormatNumber($a, $b, $c, $e) {
$GLOBALS['number_thousands_separator'] = ' ';
$GLOBALS['number_decimal_separator'] = ',';
$this->assertEquals($e, (string)PMA_formatNumber($a, $b, $c, false));
}
/**
* format byte down data provider
*/
public function formatByteDownDataProvider() {
return array(
array(10, 2, 2, array('10', 'B')),
array(100, 2, 0, array('0', 'KB')),
array(100, 3, 0, array('100', 'B')),
array(100, 2, 2, array('0,10', 'KB')),
array(1034, 3, 2, array('1,01', 'KB')),
array(100233, 3, 3, array('97,884', 'KB')),
array(2206451, 1, 2, array('2,10', 'MB'))
);
}
/**
* format byte test, globals are defined
* @dataProvider formatByteDownDataProvider
*/
public function testFormatByteDown($a, $b, $c, $e) {
$GLOBALS['byteUnits'] = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB');
$GLOBALS['number_thousands_separator'] = ' ';
$GLOBALS['number_decimal_separator'] = ',';
$result = PMA_formatByteDown($a, $b, $c);
$result[0] = trim($result[0]);
$this->assertEquals($e, $result);
}
}
?>

View File

@@ -0,0 +1,159 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA_generate_common_url()
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'PHPUnit/Framework.php';
require_once './libraries/core.lib.php';
require_once './libraries/url_generating.lib.php';
/**
* @package phpMyAdmin-test
*/
class PMA_generate_common_url_test extends PHPUnit_Framework_TestCase
{
public function setUp()
{
unset($_COOKIE['pma_lang'], $_COOKIE['pma_charset'], $_COOKIE['pma_collation_connection']);
}
public function testOldStyle()
{
$GLOBALS['server'] = 'x';
$GLOBALS['lang'] = 'x';
$GLOBALS['convcharset'] = 'x';
$GLOBALS['collation_connection'] = 'x';
$_SESSION[' PMA_token '] = 'x';
$GLOBALS['cfg']['ServerDefault'] = 'y';
$separator = PMA_get_arg_separator();
$expected = 'server=x' . htmlentities($separator)
. 'lang=x' . htmlentities($separator)
. 'convcharset=x' . htmlentities($separator)
. 'collation_connection=x' . htmlentities($separator)
. 'token=x'
;
$expected = 'db=db'
. htmlentities($separator) . 'table=table'
. htmlentities($separator) . $expected;
$this->assertEquals($expected, PMA_generate_common_url('db', 'table'));
}
public function testOldStyleDbOnly()
{
$GLOBALS['server'] = 'x';
$GLOBALS['lang'] = 'x';
$GLOBALS['convcharset'] = 'x';
$GLOBALS['collation_connection'] = 'x';
$_SESSION[' PMA_token '] = 'x';
$GLOBALS['cfg']['ServerDefault'] = 'y';
$separator = PMA_get_arg_separator();
$expected = 'server=x' . htmlentities($separator)
. 'lang=x' . htmlentities($separator)
. 'convcharset=x' . htmlentities($separator)
. 'collation_connection=x' . htmlentities($separator)
. 'token=x'
;
$expected = 'db=db'
. htmlentities($separator) . $expected;
$this->assertEquals($expected, PMA_generate_common_url('db'));
}
public function testNewStyle()
{
$GLOBALS['server'] = 'x';
$GLOBALS['lang'] = 'x';
$GLOBALS['convcharset'] = 'x';
$GLOBALS['collation_connection'] = 'x';
$_SESSION[' PMA_token '] = 'x';
$GLOBALS['cfg']['ServerDefault'] = 'y';
$separator = PMA_get_arg_separator();
$expected = 'server=x' . htmlentities($separator)
. 'lang=x' . htmlentities($separator)
. 'convcharset=x' . htmlentities($separator)
. 'collation_connection=x' . htmlentities($separator)
. 'token=x'
;
$expected = '?db=db'
. htmlentities($separator) . 'table=table'
. htmlentities($separator) . $expected;
$params = array('db' => 'db', 'table' => 'table');
$this->assertEquals($expected, PMA_generate_common_url($params));
}
public function testOldStyleWithAlternateSeparator()
{
$GLOBALS['server'] = 'x';
$GLOBALS['lang'] = 'x';
$GLOBALS['convcharset'] = 'x';
$GLOBALS['collation_connection'] = 'x';
$_SESSION[' PMA_token '] = 'x';
$GLOBALS['cfg']['ServerDefault'] = 'y';
$separator = PMA_get_arg_separator();
$expected = 'server=x' . $separator
. 'lang=x' . $separator
. 'convcharset=x' . $separator
. 'collation_connection=x' . $separator
. 'token=x'
;
$expected = 'db=db' . $separator . 'table=table' . $separator . $expected;
$this->assertEquals($expected, PMA_generate_common_url('db', 'table', '&'));
}
public function testOldStyleWithAlternateSeparatorDbOnly()
{
$GLOBALS['server'] = 'x';
$GLOBALS['lang'] = 'x';
$GLOBALS['convcharset'] = 'x';
$GLOBALS['collation_connection'] = 'x';
$_SESSION[' PMA_token '] = 'x';
$GLOBALS['cfg']['ServerDefault'] = 'y';
$separator = PMA_get_arg_separator();
$expected = 'server=x' . $separator
. 'lang=x' . $separator
. 'convcharset=x' . $separator
. 'collation_connection=x' . $separator
. 'token=x'
;
$expected = 'db=db' . $separator . $expected;
$this->assertEquals($expected, PMA_generate_common_url('db', '', '&'));
}
public function testDefault()
{
$GLOBALS['server'] = 'x';
$GLOBALS['lang'] = 'x';
$GLOBALS['convcharset'] = 'x';
$GLOBALS['collation_connection'] = 'x';
$_SESSION[' PMA_token '] = 'x';
$GLOBALS['cfg']['ServerDefault'] = 'y';
$separator = PMA_get_arg_separator();
$expected = 'server=x' . htmlentities($separator)
. 'lang=x' . htmlentities($separator)
. 'convcharset=x' . htmlentities($separator)
. 'collation_connection=x' . htmlentities($separator)
. 'token=x'
;
$this->assertEquals($expected, PMA_generate_common_url());
}
}
?>

View File

@@ -0,0 +1,46 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA_get_real_size()
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'PHPUnit/Framework.php';
require_once './libraries/core.lib.php';
/**
* @package phpMyAdmin-test
*/
class PMA_get_real_size_test extends PHPUnit_Framework_TestCase
{
public function testNull()
{
$this->assertEquals(0, PMA_get_real_size('0'));
}
public function testKilobyte()
{
$this->assertEquals(1024, PMA_get_real_size('1kb'));
}
public function testKilobyte2()
{
$this->assertEquals(1024 * 1024, PMA_get_real_size('1024k'));
}
public function testMegabyte()
{
$this->assertEquals(8 * 1024 * 1024, PMA_get_real_size('8m'));
}
public function testGigabyte()
{
$this->assertEquals(12 * 1024 * 1024 * 1024, PMA_get_real_size('12gb'));
}
}
?>

View File

@@ -0,0 +1,305 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for PMA_sendHeaderLocation
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @version $Id$
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Extensions/OutputTestCase.php';
/**
* Include to test.
*/
require_once './libraries/common.lib.php';
require_once './libraries/url_generating.lib.php';
require_once './libraries/core.lib.php';
/**
* Test function sending headers.
* Warning - these tests set constants, so it can interfere with other tests
* If you have runkit extension, then it is possible to back changes made on constants
* rest of options can be tested only with apd, when functions header and headers_sent are redefined
* rename_function() of header and headers_sent may cause CLI error report in Windows XP (but tests are done correctly)
* additional functions which were created during tests must be stored to coverage test e.g.
*
* <code>rename_function('headers_sent', 'headers_sent'.str_replace(array('.', ' '),array('', ''),microtime()));</code>
*
* @package phpMyAdmin-test
*/
class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
{
protected $oldIISvalue;
protected $oldSIDvalue;
protected $runkitExt;
protected $apdExt;
public function __construct()
{
parent::__construct();
$this->runkitExt = false;
if (function_exists("runkit_constant_redefine"))
$this->runkitExt = true;
$this->apdExt = false;
if (function_exists("rename_function"))
$this->apdExt = true;
if ($this->apdExt && !$GLOBALS['test_header']) {
// using apd extension to overriding header and headers_sent functions for test purposes
$GLOBALS['test_header'] = 1;
// rename_function() of header and headers_sent may cause CLI error report in Windows XP
rename_function('header', 'test_header');
rename_function('headers_sent', 'test_headers_sent');
// solution from: http://unixwars.com/2008/11/29/override_function-in-php/ to overriding more than one function
$substs = array(
'header' => 'if (isset($GLOBALS["header"])) $GLOBALS["header"] .= $a; else $GLOBALS["header"] = $a;',
'headers_sent' => 'return false;'
);
$args = array(
'header' => '$a',
'headers_sent' => ''
);
foreach ($substs as $func => $ren_func) {
if (function_exists("__overridden__"))
rename_function("__overridden__", str_replace(array('.', ' '),array('', ''),microtime()));
override_function($func, $args[$func], $substs[$func]);
rename_function("__overridden__", str_replace(array('.', ' '),array('', ''),microtime()));
}
}
}
public function __destruct()
{
// rename_function may causes CLI error report in Windows XP, but nothing more happen
if ($this->apdExt && $GLOBALS['test_header']) {
$GLOBALS['test_header'] = 0;
rename_function('header', 'header'.str_replace(array('.', ' '),array('', ''),microtime()));
rename_function('headers_sent', 'headers_sent'.str_replace(array('.', ' '),array('', ''),microtime()));
rename_function('test_header', 'header');
rename_function('test_headers_sent', 'headers_sent');
}
}
public function setUp()
{
// cleaning constants
if ($this->runkitExt) {
$this->oldIISvalue = 'non-defined';
if (defined('PMA_IS_IIS')) {
$this->oldIISvalue = PMA_IS_IIS;
runkit_constant_redefine('PMA_IS_IIS', NULL);
}
else {
runkit_constant_add('PMA_IS_IIS', NULL);
}
$this->oldSIDvalue = 'non-defined';
if (defined('SID')) {
$this->oldSIDvalue = SID;
runkit_constant_redefine('SID', NULL);
}
else {
runkit_constant_add('SID', NULL);
}
}
}
public function tearDown()
{
// cleaning constants
if ($this->runkitExt) {
if ($this->oldIISvalue != 'non-defined')
runkit_constant_redefine('PMA_IS_IIS', $this->oldIISvalue);
elseif (defined('PMA_IS_IIS')) {
runkit_constant_remove('PMA_IS_IIS');
}
if ($this->oldSIDvalue != 'non-defined')
runkit_constant_redefine('SID', $this->oldSIDvalue);
elseif (defined('SID')) {
runkit_constant_remove('SID');
}
}
if ($this->apdExt)
unset($GLOBALS['header']);
}
public function testSendHeaderLocationWithSidUrlWithQuestionMark()
{
if ($this->runkitExt && $this->apdExt) {
runkit_constant_redefine('SID', md5('test_hash'));
$testUri = 'http://testurl.com/test.php?test=test';
$separator = PMA_get_arg_separator();
$header = 'Location: ' . $testUri . $separator . SID;
PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
$this->assertEquals($header, $GLOBALS['header']);
} else {
$this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
}
}
public function testSendHeaderLocationWithSidUrlWithoutQuestionMark()
{
if ($this->runkitExt && $this->apdExt) {
runkit_constant_redefine('SID', md5('test_hash'));
$testUri = 'http://testurl.com/test.php';
$separator = PMA_get_arg_separator();
$header = 'Location: ' . $testUri . '?' . SID;
PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
$this->assertEquals($header, $GLOBALS['header']);
} else {
$this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
}
}
public function testSendHeaderLocationWithoutSidWithIis()
{
if ($this->runkitExt && $this->apdExt) {
runkit_constant_redefine('PMA_IS_IIS', true);
runkit_constant_add('PMA_COMING_FROM_COOKIE_LOGIN', true);
$testUri = 'http://testurl.com/test.php';
$separator = PMA_get_arg_separator();
$header = 'Refresh: 0; ' . $testUri;
PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
// cleaning constant
runkit_constant_remove('PMA_COMING_FROM_COOKIE_LOGIN');
$this->assertEquals($header, $GLOBALS['header']);
} else {
$this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
}
}
public function testSendHeaderLocationWithoutSidWithoutIis()
{
if ($this->apdExt) {
$testUri = 'http://testurl.com/test.php';
$header = 'Location: ' . $testUri;
PMA_sendHeaderLocation($testUri); // sets $GLOBALS['header']
$this->assertEquals($header, $GLOBALS['header']);
} else {
$this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
}
}
public function testSendHeaderLocationIisLongUri()
{
if (defined('PMA_IS_IIS') && $this->runkitExt)
runkit_constant_redefine('PMA_IS_IIS', true);
elseif (!defined('PMA_IS_IIS'))
define('PMA_IS_IIS', true);
else
$this->markTestSkipped('Cannot redefine constant/function - missing APD or/and runkit extension');
// over 600 chars
$testUri = 'http://testurl.com/test.php?testlonguri=over600chars&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test&test=test';
$GLOBALS['strGo'] = 'test link';
$header = "<html><head><title>- - -</title>\n" .
"<meta http-equiv=\"expires\" content=\"0\">\n" .
"<meta http-equiv=\"Pragma\" content=\"no-cache\">\n" .
"<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\n" .
"<meta http-equiv=\"Refresh\" content=\"0;url=" . $testUri . "\">\n" .
"<script type=\"text/javascript\">\n".
"//<![CDATA[\n" .
"setTimeout(\"window.location = unescape('\"" . $testUri . "\"')\", 2000);\n" .
"//]]>\n" .
"</script>\n" .
"</head>\n" .
"<body>\n" .
"<script type=\"text/javascript\">\n" .
"//<![CDATA[\n" .
"document.write('<p><a href=\"" . $testUri . "\">" . $GLOBALS['strGo'] . "</a></p>');\n" .
"//]]>\n" .
"</script></body></html>\n";
$this->expectOutputString($header);
PMA_sendHeaderLocation($testUri);
}
/**
* other output tests
*/
public function testWriteReloadNavigation()
{
$GLOBALS['reload'] = true;
$GLOBALS['db'] = 'test_db';
$url = './navigation.php?db='.$GLOBALS['db'];
$write = PHP_EOL . '<script type="text/javascript">' . PHP_EOL .
'//<![CDATA[' . PHP_EOL .
'if (typeof(window.parent) != \'undefined\'' . PHP_EOL .
' && typeof(window.parent.frame_navigation) != \'undefined\'' . PHP_EOL .
' && window.parent.goTo) {' . PHP_EOL .
' window.parent.goTo(\'' . $url . '\');' . PHP_EOL .
'}' . PHP_EOL .
'//]]>' . PHP_EOL .
'</script>' . PHP_EOL;
$this->expectOutputString($write);
PMA_reloadNavigation();
$this->assertFalse(isset($GLOBALS['reload']));
unset($GLOBALS['db']);
}
}
?>

50
test/PMA_ifSetOr_test.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA_ifSetOr()
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'PHPUnit/Framework.php';
require_once './libraries/core.lib.php';
/**
* @package phpMyAdmin-test
*/
class PMA_ifSetOr_test extends PHPUnit_Framework_TestCase
{
public function testVarSet()
{
$default = 'foo';
$in = 'bar';
$out = PMA_ifSetOr($in, $default);
$this->assertEquals($in, $out);
}
public function testVarSetWrongType()
{
$default = 'foo';
$in = 'bar';
$out = PMA_ifSetOr($in, $default, 'boolean');
$this->assertEquals($out, $default);
}
public function testVarNotSet()
{
$default = 'foo';
// $in is not set!
$out = PMA_ifSetOr($in, $default);
$this->assertEquals($out, $default);
}
public function testVarNotSetNoDefault()
{
// $in is not set!
$out = PMA_ifSetOr($in);
$this->assertEquals($out, null);
}
}
?>

115
test/PMA_isValid_test.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA_pow()
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'PHPUnit/Framework.php';
require_once './libraries/core.lib.php';
/**
* @package phpMyAdmin-test
*/
class PMA_isValid_test extends PHPUnit_Framework_TestCase
{
public function testVarNotSetAfterTest()
{
PMA_isValid($var);
$this->assertFalse(isset($var));
}
public function testNotSet()
{
$this->assertFalse(PMA_isValid($var));
}
public function testEmptyString()
{
$var = '';
$this->assertFalse(PMA_isValid($var));
}
public function testNotEmptyString()
{
$var = '0';
$this->assertTrue(PMA_isValid($var));
}
public function testZero()
{
$var = 0;
$this->assertTrue(PMA_isValid($var));
}
public function testNullFail()
{
$var = null;
$this->assertFalse(PMA_isValid($var));
}
public function testNotSetArray()
{
$this->assertFalse(PMA_isValid($array['x']));
}
public function testScalarString()
{
$var = 'string';
$this->assertTrue(PMA_isValid($var, 'scalar'));
}
public function testScalarInt()
{
$var = 1;
$this->assertTrue(PMA_isValid($var, 'scalar'));
}
public function testScalarFloat()
{
$var = 1.1;
$this->assertTrue(PMA_isValid($var, 'scalar'));
}
public function testScalarBool()
{
$var = true;
$this->assertTrue(PMA_isValid($var, 'scalar'));
}
public function testNotScalarArray()
{
$var = array('test');
$this->assertFalse(PMA_isValid($var, 'scalar'));
}
public function testNotScalarNull()
{
$var = null;
$this->assertFalse(PMA_isValid($var, 'scalar'));
}
public function testNumericInt()
{
$var = 1;
$this->assertTrue(PMA_isValid($var, 'numeric'));
}
public function testNumericFloat()
{
$var = 1.1;
$this->assertTrue(PMA_isValid($var, 'numeric'));
}
public function testNumericZero()
{
$var = 0;
$this->assertTrue(PMA_isValid($var, 'numeric'));
}
public function testNumericString()
{
$var = '+0.1';
$this->assertTrue(PMA_isValid($var, 'numeric'));
}
public function testValueInArray()
{
$var = 'a';
$this->assertTrue(PMA_isValid($var, array('a', 'b', )));
}
public function testValueNotInArray()
{
$var = 'c';
$this->assertFalse(PMA_isValid($var, array('a', 'b', )));
}
}
?>

View File

@@ -0,0 +1,114 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for generating localised date or timespan expression
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @package phpMyAdmin-test
* @version $Id: PMA_localisedDateTimespan_test.php
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/common.lib.php';
/**
* Test localised date or timespan expression.
*
*/
class PMA_localisedDateTimespan_test extends PHPUnit_Framework_TestCase
{
/**
* temporary variable for globals array
*/
protected $tmpGlobals;
/**
* temporary variable for session array
*/
protected $tmpSession;
/**
* temporary variable for timezone info
*/
protected $tmpTimezone;
/**
* storing globals and session
*/
public function setUp() {
$this->tmpGlobals = $GLOBALS;
$this->tmpSession = $_SESSION;
$this->tmpTimezone = date_default_timezone_get();
date_default_timezone_set('Europe/London');
}
/**
* recovering globals and session
*/
public function tearDown() {
$GLOBALS = $this->tmpGlobals;
$_SESSION = $this->tmpSession;
date_default_timezone_set($this->tmpTimezone);
}
/**
* data provider for localised date test
*/
public function localisedDateDataProvider() {
return array(
array(1227455558, '', 'Nov 23, 2008 at 03:52 PM'),
array(1227455558, '%Y-%m-%d %H:%M:%S %a', '2008-11-23 15:52:38 Sun')
);
}
/**
* localised date test, globals are defined
* @dataProvider localisedDateDataProvider
*/
public function testLocalisedDate($a, $b, $e) {
$GLOBALS['day_of_week'] = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
$GLOBALS['month'] = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
$GLOBALS['datefmt'] = '%B %d, %Y at %I:%M %p';
$this->assertEquals($e, PMA_localisedDate($a, $b));
}
/**
* data provider for localised timestamp test
*/
public function timespanFormatDataProvider() {
return array(
array(1258, '0 days, 0 hours, 20 minutes and 58 seconds'),
array(821958, '9 days, 12 hours, 19 minutes and 18 seconds')
);
}
/**
* localised timestamp test, globals are defined
* @dataProvider timespanFormatDataProvider
*/
public function testTimespanFormat($a, $e) {
$GLOBALS['timespanfmt'] = '%s days, %s hours, %s minutes and %s seconds';
$this->assertEquals($e, PMA_timespanFormat($a));
}
}
?>

83
test/PMA_pow_test.php Normal file
View File

@@ -0,0 +1,83 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA_pow()
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'PHPUnit/Framework.php';
require_once './libraries/common.lib.php';
/**
* @package phpMyAdmin-test
*/
class PMA_pow_test extends PHPUnit_Framework_TestCase
{
public function testIntOverflow()
{
$this->assertEquals('1267650600228229401496703205376',
PMA_pow(2, 100));
}
public function testBcpow()
{
if (function_exists('bcpow')) {
$this->assertEquals('1267650600228229401496703205376',
PMA_pow(2, 100, 'bcpow'));
} else {
$this->markTestSkipped('function bcpow() does not exist');
}
}
public function testGmppow()
{
if (function_exists('gmp_pow')) {
$this->assertEquals('1267650600228229401496703205376',
PMA_pow(2, 100, 'gmp_pow'));
} else {
$this->markTestSkipped('function gmp_pow() does not exist');
}
}
public function _testNegativeExp()
{
$this->assertEquals(0.25,
PMA_pow(2, -2));
}
public function _testNegativeExpPow()
{
if (function_exists('pow')) {
$this->assertEquals(0.25,
PMA_pow(2, -2, 'pow'));
} else {
$this->markTestSkipped('function pow() does not exist');
}
}
public function _testNegativeExpBcpow()
{
if (function_exists('bcpow')) {
$this->assertEquals(0.25,
PMA_pow(2, -2, 'bcpow'));
} else {
$this->markTestSkipped('function bcpow() does not exist');
}
}
public function _testNegativeExpGmppow()
{
if (function_exists('gmp_pow')) {
$this->assertEquals(0.25,
PMA_pow(2, -2, 'gmp_pow'));
} else {
$this->markTestSkipped('function gmp_pow() does not exist');
}
}
}
?>

View File

@@ -0,0 +1,48 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test printableBitValue function
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @package phpMyAdmin-test
* @version $Id: PMA_printableBitValue_test.php
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/common.lib.php';
/**
* Test printableBitValue function.
*
*/
class PMA_printableBitValue_test extends PHPUnit_Framework_TestCase
{
/**
* data provider for printable bit value test
*/
public function printableBitValueDataProvider() {
return array(
array('testtest', 64, '0111010001100101011100110111010001110100011001010111001101110100'),
array('test', 32, '01110100011001010111001101110100')
);
}
/**
* test for generating string contains printable bit value of selected data
* @dataProvider printableBitValueDataProvider
*/
public function testPrintableBitValue($a, $b, $e) {
$this->assertEquals($e, PMA_printable_bit_value($a, $b));
}
}
?>

View File

@@ -0,0 +1,112 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for quoting, slashing/backslashing
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @package phpMyAdmin-test
* @version $Id: PMA_quoting_slashing_test.php
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/common.lib.php';
/**
* Test quoting, slashing, backslashing.
*
*/
class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
{
/**
* sqlAddslashes test
*/
public function testAddSlashes() {
$string = "\'test''\''\'\r\t\n";
$this->assertEquals("\\\\\\\\\'test\'\'\\\\\\\\\'\'\\\\\\\\\'\\r\\t\\n", PMA_sqlAddslashes($string, true, true, true));
$this->assertEquals("\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\\r\\t\\n", PMA_sqlAddslashes($string, true, true, false));
$this->assertEquals("\\\\\\\\\'test\'\'\\\\\\\\\'\'\\\\\\\\\'\r\t\n", PMA_sqlAddslashes($string, true, false, true));
$this->assertEquals("\\\\\\\\''test''''\\\\\\\\''''\\\\\\\\''\r\t\n", PMA_sqlAddslashes($string, true, false, false));
$this->assertEquals("\\\\\'test\'\'\\\\\'\'\\\\\'\\r\\t\\n", PMA_sqlAddslashes($string, false, true, true));
$this->assertEquals("\\\\''test''''\\\\''''\\\\''\\r\\t\\n", PMA_sqlAddslashes($string, false, true, false));
$this->assertEquals("\\\\\'test\'\'\\\\\'\'\\\\\'\r\t\n", PMA_sqlAddslashes($string, false, false, true));
$this->assertEquals("\\\\''test''''\\\\''''\\\\''\r\t\n", PMA_sqlAddslashes($string, false, false, false));
}
/**
* data provider for unQuote test
*/
public function unQuoteProvider() {
return array(
array('"test\'"', "test'"),
array("'test''", "test'"),
array("`test'`", "test'"),
array("'test'test", "'test'test")
);
}
/**
* unQuote test
* @dataProvider unQuoteProvider
*/
public function testUnQuote($param, $expected) {
$this->assertEquals($expected, PMA_unQuote($param));
}
/**
* data provider for unQuote test with chosen quote
*/
public function unQuoteSelectedProvider() {
return array(
array('"test\'"', "test'"),
array("'test''", "'test''"),
array("`test'`", "`test'`"),
array("'test'test", "'test'test")
);
}
/**
* unQuote test with chosen quote
* @dataProvider unQuoteSelectedProvider
*/
public function testUnQuoteSelectedChar($param, $expected) {
$this->assertEquals($expected, PMA_unQuote($param, '"'));
}
/**
* data provider for backquote test
*/
public function backquoteDataProvider() {
return array(
array('0', '`0`'),
array('test', '`test`'),
array('te`st', '`te``st`'),
array(array('test', 'te`st', '', '*'), array('`test`', '`te``st`', '', '*'))
);
}
/**
* backquote test with different param $do_it (true, false)
* @dataProvider backquoteDataProvider
*/
public function testBackquote($a, $b) {
$this->assertEquals($a, PMA_backquote($a, false));
$this->assertEquals($b, PMA_backquote($a));
}
}
?>

View File

@@ -0,0 +1,45 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA_sanitize()
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'PHPUnit/Framework.php';
require_once './libraries/sanitizing.lib.php';
/**
* @package phpMyAdmin-test
*/
class PMA_sanitize_test extends PHPUnit_Framework_TestCase
{
public function testXssInHref()
{
$this->assertEquals('[a@javascript:alert(\'XSS\');@target]link</a>',
PMA_sanitize('[a@javascript:alert(\'XSS\');@target]link[/a]'));
}
public function testLink()
{
$this->assertEquals('<a href="http://www.phpmyadmin.net/" target="target">link</a>',
PMA_sanitize('[a@http://www.phpmyadmin.net/@target]link[/a]'));
}
public function testHtmlTags()
{
$this->assertEquals('&lt;div onclick=""&gt;',
PMA_sanitize('<div onclick="">'));
}
public function testBbcoe()
{
$this->assertEquals('<strong>strong</strong>',
PMA_sanitize('[b]strong[/b]'));
}
}
?>

177
test/PMA_showHint_test.php Normal file
View File

@@ -0,0 +1,177 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for showHint function
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @package phpMyAdmin-test
* @version $Id: PMA_showHint_test.php
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/common.lib.php';
/**
* Test showHint function.
*
*/
class PMA_showHint_test extends PHPUnit_Framework_TestCase
{
/**
* @var array temporary variable for globals array
*/
protected $tmpGlobals;
/**
* @var array temporary variable for session array
*/
protected $tmpSession;
/**
* storing globals and session
*/
public function setUp()
{
$this->tmpGlobals = $GLOBALS;
$this->tmpSession = $_SESSION;
}
/**
* recovering globals and session
*/
public function tearDown()
{
$GLOBALS = $this->tmpGlobals;
$_SESSION = $this->tmpSession;
}
/**
* PMA_showHint with defined GLOBALS
*/
public function testShowHintReturnValue()
{
$key = md5('test');
$nr = 1234;
$instance = 1;
$GLOBALS['footnotes'][$key]['nr'] = $nr;
$GLOBALS['footnotes'][$key]['instance'] = $instance;
$this->assertEquals(sprintf('<sup class="footnotemarker" id="footnote_sup_%d_%d">%d</sup>',
$nr, $instance + 1, $nr), PMA_showHint('test'));
}
/**
* PMA_showHint with defined GLOBALS formatted as BB
*/
public function testShowHintReturnValueBbFormat()
{
$key = md5('test');
$nr = 1234;
$instance = 1;
$GLOBALS['footnotes'][$key]['nr'] = $nr;
$GLOBALS['footnotes'][$key]['instance'] = $instance;
$this->assertEquals(sprintf('[sup]%d[/sup]', $nr),
PMA_showHint('test', true));
}
/**
* PMA_showHint with not defined GLOBALS
*/
public function testShowHintSetting()
{
$key = md5('test');
$nr = 1;
$instance = 1;
$this->assertEquals(sprintf('<sup class="footnotemarker" id="footnote_sup_%d_%d">%d</sup>', $nr, $instance, $nr), PMA_showHint('test', false, 'notice'));
$expArray = array(
'note' => 'test',
'type' => 'notice',
'nr' => count($GLOBALS['footnotes']),
'instance' => 1,
);
$this->assertEquals($expArray, $GLOBALS['footnotes'][$key]);
}
/**
* PMA_showHint with not defined GLOBALS formatted as BB
*/
public function testShowHintSettingBbFormat()
{
$key = md5('test');
$nr = 1;
$instance = 1;
$this->assertEquals(sprintf('[sup]%d[/sup]', $nr), PMA_showHint('test', true, 'notice'));
$expArray = array(
'note' => 'test',
'type' => 'notice',
'nr' => count($GLOBALS['footnotes']),
'instance' => 1,
);
$this->assertEquals($expArray, $GLOBALS['footnotes'][$key]);
}
/**
* PMA_showHint with defined GLOBALS using PMA_Message object
*/
public function testShowHintPmaMessageReturnValue()
{
$nr = 1;
$instance = 1;
$oMock = $this->getMock('PMA_Message',
array('setMessage', 'setNumber', 'getHash', 'getLevel'));
$oMock->setMessage('test');
$oMock->setNumber($nr);
$key = $oMock->getHash();
$GLOBALS['footnotes'][$key]['nr'] = $nr;
$GLOBALS['footnotes'][$key]['instance'] = $instance;
$this->assertEquals(sprintf('<sup class="footnotemarker" id="footnote_sup_%d_%d">%d</sup>',
$nr, $instance + 1, $nr), PMA_showHint($oMock));
}
/**
* PMA_showHint with not defined GLOBALS using PMA_Message object
*/
public function testShowHintPmaMessageSetting()
{
$nr = 1;
$instance = 1;
$oMock = $this->getMock('PMA_Message',
array('setMessage', 'setNumber', 'getHash', 'getLevel', 'getNumber'));
$oMock->setMessage('test');
$oMock->setNumber($nr);
$this->assertEquals(sprintf('<sup class="footnotemarker" id="footnote_sup_%d_%d">%d</sup>', $nr, $instance, $nr), PMA_showHint($oMock, false));
$key = $oMock->getHash();
$expArray = array(
'note' => $oMock,
'type' => $oMock->getLevel(),
'nr' => count($GLOBALS['footnotes']),
'instance' => 1,
);
$this->assertEquals($expArray, $GLOBALS['footnotes'][$key]);
}
}
?>

View File

@@ -0,0 +1,135 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test for several string operations
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @version $Id: PMA_stringOperations_test.php
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/common.lib.php';
/**
* Test string operations.
* @package phpMyAdmin-test
*/
class PMA_stringOperations_test extends PHPUnit_Framework_TestCase
{
/**
* temporary variable for globals array
*/
protected $tmpGlobals;
/**
* temporary variable for session array
*/
protected $tmpSession;
/**
* storing globals and session
*/
public function setUp() {
$this->tmpGlobals = $GLOBALS;
$this->tmpSession = $_SESSION;
}
/**
* data provider for flipstring test
*/
public function flipStringDataProvider() {
return array(
array('test', "t<br />\ne<br />\ns<br />\nt"),
array('te&nbsp;;st', "t<br />\ne<br />\n&nbsp;<br />\n;<br />\ns<br />\nt")
);
}
/**
* test of changing string from horizontal to vertical orientation
* @dataProvider flipStringDataProvider
*/
public function testFlipString($a, $e) {
$this->assertEquals($e, PMA_flipstring($a));
}
/**
* data provider for userDir test
*/
public function userDirDataProvider() {
return array(
array('/var/pma_tmp/%u/', "/var/pma_tmp/root/"),
array('/home/%u/pma', "/home/root/pma/")
);
}
/**
* test of generating user dir, globals are defined
* @dataProvider userDirDataProvider
*/
public function testUserDirString($a, $e) {
$GLOBALS['cfg']['Server']['user'] = 'root';
$this->assertEquals($e, PMA_userDir($a));
}
/**
* data provider for replace binary content test
*/
public function replaceBinaryContentsDataProvider() {
return array(
array("\x000", '\00'),
array("\x08\x0a\x0d\x1atest", '\b\n\r\Ztest'),
array("\ntest", '\ntest')
);
}
/**
* replace binary contents test
* @dataProvider replaceBinaryContentsDataProvider
*/
public function testReplaceBinaryContents($a, $e) {
$this->assertEquals($e, PMA_replace_binary_contents($a));
}
/**
* data provider for duplicate first newline test
*/
public function duplicateFirstNewlineDataProvider() {
return array(
array('test', 'test'),
array("\r\ntest", "\n\r\ntest"),
array("\ntest", "\ntest"),
array("\n\r\ntest", "\n\r\ntest")
);
}
/**
* duplicate first newline test
* @dataProvider duplicateFirstNewlineDataProvider
*/
public function testDuplicateFirstNewline($a, $e) {
$this->assertEquals($e, PMA_duplicateFirstNewline($a));
}
}
?>

View File

@@ -0,0 +1,51 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* tests for PMA_sanitize()
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'PHPUnit/Framework.php';
require_once './libraries/transformations.lib.php';
/**
* @package phpMyAdmin-test
*/
class PMA_transformation_getOptions_test extends PHPUnit_Framework_TestCase
{
public function testDefault()
{
$this->assertEquals(array('option1 ', ' option2 '),
PMA_transformation_getOptions("option1 , option2 "));
}
public function testQuoted()
{
$this->assertEquals(array('option1', ' option2'),
PMA_transformation_getOptions("'option1' ,' option2' "));
}
public function testComma()
{
$this->assertEquals(array('2,3', ' ,, option ,,'),
PMA_transformation_getOptions("'2,3' ,' ,, option ,,' "));
}
public function testEmptyOptions()
{
$this->assertEquals(array('', '', ''),
PMA_transformation_getOptions("'',,"));
}
public function testEmpty()
{
$this->assertEquals(array(),
PMA_transformation_getOptions(''));
}
}
?>

View File

@@ -0,0 +1,72 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Test whichCrlf function
*
* @author Michal Biniek <michal@bystrzyca.pl>
* @package phpMyAdmin-test
* @version $Id: PMA_whichCrlf_test.php
*/
/**
* Tests core.
*/
require_once 'PHPUnit/Framework.php';
/**
* Include to test.
*/
require_once './libraries/common.lib.php';
/**
* Test whichCrlf function.
*
*/
class PMA_whichCrlf_test extends PHPUnit_Framework_TestCase
{
/**
* @using runkit pecl extension
* if not define PMA_USR_OS, then define it as Win
* if installed runkit, then constant will not change
*/
public function testWhichCrlf()
{
$runkit = function_exists('runkit_constant_redefine');
if ($runkit && defined('PMA_USR_OS'))
$pma_usr_os = PMA_USR_OS;
if (defined('PMA_USR_OS') && !$runkit) {
if (PMA_USR_OS == 'Win')
$this->assertEquals("\r\n", PMA_whichCrlf());
else
$this->assertEquals("\n", PMA_whichCrlf());
$this->markTestIncomplete('Cannot redefine constant');
} else {
if ($runkit)
define('PMA_USR_OS', 'Linux');
$this->assertEquals("\n", PMA_whichCrlf());
if ($runkit)
runkit_constant_redefine('PMA_USR_OS', 'Win');
else
define('PMA_USR_OS', 'Win');
$this->assertEquals("\r\n", PMA_whichCrlf());
}
if ($runkit) {
if (isset($pma_usr_os))
runkit_constant_redefine('PMA_USR_OS', 'Win');
else
runkit_constant_remove('PMA_USR_OS');
}
}
}
?>

View File

@@ -0,0 +1,21 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Selenium TestCase for login related tests
*
* @version $Id$
* @package phpMyAdmin-test
*/
require_once('PmaSeleniumTestCase.php');
class PmaSeleniumLoginTest extends PmaSeleniumTestCase
{
public function testLogin()
{
$this->doLogin();
$this->assertRegExp("/phpMyAdmin .*-dev/", $this->getTitle());
}
}
?>

View File

@@ -0,0 +1,48 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Selenium TestCase for privilege related tests
*
* @version $Id$
* @package phpMyAdmin-test
*/
require_once('PmaSeleniumTestCase.php');
class PmaSeleniumPrivilegesTest extends PmaSeleniumTestCase
{
public function testChangePassword()
{
$this->doLogin();
$this->selectFrame("frame_content");
$this->click("link=Change password");
$this->waitForPageToLoad("30000");
try {
$this->assertEquals("", $this->getValue("text_pma_pw"));
} catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
try {
$this->assertEquals("", $this->getValue("text_pma_pw2"));
} catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
try {
$this->assertEquals("", $this->getValue("generated_pw"));
} catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
$this->click("button_generate_password");
$this->assertNotEquals("", $this->getValue("text_pma_pw"));
$this->assertNotEquals("", $this->getValue("text_pma_pw2"));
$this->assertNotEquals("", $this->getValue("generated_pw"));
$this->type("text_pma_pw", $this->cfg['Test']['testuser']['password']);
$this->type("text_pma_pw2", $this->cfg['Test']['testuser']['password']);
$this->click("change_pw");
$this->waitForPageToLoad("30000");
$this->assertTrue($this->isTextPresent(""));
$this->assertTrue($this->isTextPresent(""));
}
}
?>

View File

@@ -0,0 +1,101 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Selenium parent class for TestCases
*
* @version $Id$
* @package phpMyAdmin-test
*/
// Optionally add the php-client-driver to your include path
set_include_path(get_include_path() . PATH_SEPARATOR . '/opt/selenium-remote-control-1.0.1/selenium-php-client-driver-1.0.1/PEAR/');
require_once 'PHPUnit/Framework/TestCase.php';
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
require_once 'Testing/Selenium.php';
// Include the main phpMyAdmin user config
// currently only $cfg['Test'] is used
require_once '../config.inc.php';
class PmaSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase
{
protected $selenium;
protected $cfg;
// TODO: find a way to get this from config.inc.php???
// PHPUnit also has a way to use XML configuration... maybe we should use that
public static $browsers = array(
array(
'name' => 'Firefox on Windows XP',
'browser' => '*firefox',
'host' => 'my.windowsxp.box',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'Internet Explorer on Windows XP',
'browser' => '*iexplore',
'host' => 'my.windowsxp.box',
'port' => 4444,
'timeout' => 30000,
),
);
public function setUp()
{
global $cfg;
$this->cfg =& $cfg;
//PHPUnit_Extensions_SeleniumTestCase::$browsers = $this->cfg['Test']['broswers'];
// Check if the test configuration is available
if ( empty($cfg['Test']['pma_host'])
|| empty($cfg['Test']['pma_url'])
//|| empty($cfg['Test']['browsers'])
) {
$this->fail("Missing Selenium configuration in config.inc.php"); // TODO add doc ref?
}
$this->setBrowserUrl($cfg['Test']['pma_host'] . $cfg['Test']['pma_url']);
$this->start();
}
public function tearDown()
{
$this->stop();
}
/**
* perform a login
*/
public function doLogin()
{
$this->open($this->cfg['Test']['pma_url']);
// Somehow selenium does not like the language selection on the cookie login page, forced English in the config for now.
//$this->select("lang", "label=English");
$this->waitForPageToLoad("30000");
$this->type("input_username", $this->cfg['Test']['testuser']['username']);
$this->type("input_password", $this->cfg['Test']['testuser']['password']);
$this->click("input_go");
$this->waitForPageToLoad("30001");
}
/*
* Just a dummy to show some example statements
*
public function mockTest()
{
// Slow down the testing speed, ideal for debugging
//$this->setSpeed(4000);
}
*/
}
?>

View File

@@ -0,0 +1,25 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Selenium TestCase for XSS related tests
*
* @version $Id$
* @package phpMyAdmin-test
*/
require_once('PmaSeleniumTestCase.php');
class PmaSeleniumXSSTest extends PmaSeleniumTestCase
{
public function testXssQueryTab()
{
$this->doLogin();
$this->selectFrame("frame_content");
$this->click("link=SQL");
$this->waitForPageToLoad("30000");
$this->type("sqlquery", "'\"><script>alert(123);</script>");
$this->click("SQL");
// If an alert pops up the test fails, since we don't handle an alert.
}
}
?>

325
test/theme.php Normal file
View File

@@ -0,0 +1,325 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* theme test
*
* @uses libraries/common.inc.php global fnctions
* @package phpMyAdmin-test
* @version $Id$
*/
chdir('..');
/**
* Gets core libraries and defines some variables
*/
require_once './libraries/common.inc.php';
$lang_iso_code = $GLOBALS['available_languages'][$GLOBALS['lang']][2];
// start output
header('Content-Type: text/html; charset=' . $GLOBALS['charset']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="<?php echo $lang_iso_code; ?>"
lang="<?php echo $lang_iso_code; ?>"
dir="<?php echo $GLOBALS['text_dir']; ?>">
<head>
<title>phpMyAdmin <?php echo PMA_VERSION; ?> -
<?php echo htmlspecialchars($HTTP_HOST); ?> - Theme Test</title>
<meta http-equiv="Content-Type"
content="text/html; charset=<?php echo $GLOBALS['charset']; ?>" />
<link rel="stylesheet" type="text/css"
href="../phpmyadmin.css.php?<?php echo PMA_generate_common_url(); ?>&amp;js_frame=right&amp;nocache=<?php echo $_SESSION['PMA_Config']->getThemeUniqueValue(); ?>" />
<link rel="stylesheet" type="text/css" media="print"
href="../print.css" />
<script src="../js/functions.js" type="text/javascript"></script>
</head>
<body>
<?php
$separator = '<span class="separator">'
.'<img class="icon" src=../"' . $GLOBALS['pmaThemeImage'] . 'item_ltr.png"'
.' width="5" height="9" alt="-" /></span>' . "\n";
$item = '<a href="%1$s?%2$s" class="item">'
.' <img class="icon" src="../' . $GLOBALS['pmaThemeImage'] . '%5$s"'
.' width="16" height="16" alt="" /> ' . "\n"
.'%4$s: %3$s</a>' . "\n";
echo '<div id="serverinfo">' . "\n";
printf($item,
$GLOBALS['cfg']['DefaultTabServer'],
PMA_generate_common_url(),
'Server',
$GLOBALS['strServer'],
's_host.png');
echo $separator;
printf($item,
$GLOBALS['cfg']['DefaultTabDatabase'],
'',
'Database',
$GLOBALS['strDatabase'],
's_db.png');
echo $separator;
printf($item,
$GLOBALS['cfg']['DefaultTabTable'],
'',
'Table',
(isset($GLOBALS['tbl_is_view']) && $GLOBALS['tbl_is_view']
? $GLOBALS['strView']
: $GLOBALS['strTable']),
(isset($GLOBALS['tbl_is_view']) && $GLOBALS['tbl_is_view']
? 'b_views'
: 's_tbl') . '.png');
echo '<span class="table_comment" id="span_table_comment">'
.'&quot;Table comment&quot</span>' . "\n";
echo '</div>';
/**
* Displays tab links
*/
$tabs = array();
$tabs['databases']['icon'] = '../../../../' . $pmaThemeImage . 's_db.png';
$tabs['databases']['link'] = 'server_databases.php';
$tabs['databases']['text'] = $strDatabases;
$tabs['sql']['icon'] = '../../../../' . $pmaThemeImage . 'b_sql.png';
$tabs['sql']['link'] = 'server_sql.php';
$tabs['sql']['text'] = $strSQL;
$tabs['status']['icon'] = '../../../../' . $pmaThemeImage . 's_status.png';
$tabs['status']['link'] = 'server_status.php';
$tabs['status']['text'] = $strStatus;
$tabs['vars']['icon'] = '../../../../' . $pmaThemeImage . 's_vars.png';
$tabs['vars']['link'] = 'server_variables.php';
$tabs['vars']['text'] = $strServerTabVariables;
$tabs['charset']['icon'] = '../../../../' . $pmaThemeImage . 's_asci.png';
$tabs['charset']['link'] = 'server_collations.php';
$tabs['charset']['text'] = $strCharsets;
$tabs['engine']['icon'] = '../../../../' . $pmaThemeImage . 'b_engine.png';
$tabs['engine']['link'] = 'server_engines.php';
$tabs['engine']['text'] = $strEngines;
$tabs['rights']['icon'] = '../../../../' . $pmaThemeImage . 's_rights.png';
$tabs['rights']['link'] = 'server_privileges.php';
$tabs['rights']['text'] = $strPrivileges;
$tabs['binlog']['icon'] = '../../../../' . $pmaThemeImage . 's_tbl.png';
$tabs['binlog']['link'] = 'server_binlog.php';
$tabs['binlog']['text'] = $strBinaryLog;
$tabs['process']['icon'] = '../../../../' . $pmaThemeImage . 's_process.png';
$tabs['process']['link'] = 'server_processlist.php';
$tabs['process']['text'] = 'caution';
$tabs['process']['class'] = 'caution';
$tabs['export']['icon'] = '../../../../' . $pmaThemeImage . 'b_export.png';
$tabs['export']['text'] = 'disabled';
$tabs['export2']['icon'] = '../../../../' . $pmaThemeImage . 'b_export.png';
$tabs['export2']['text'] = 'disabled caution';
$tabs['export2']['class'] = 'caution';
$tabs['import']['icon'] = '../../../../' . $pmaThemeImage . 'b_import.png';
$tabs['import']['link'] = 'server_import.php';
$tabs['import']['text'] = 'active';
$tabs['import']['class'] = 'active';
echo PMA_generate_html_tabs($tabs, array());
unset($tabs);
if (@file_exists($pmaThemeImage . 'logo_right.png')) {
?>
<img id="pmalogoright" src="../<?php echo $pmaThemeImage; ?>logo_right.png"
alt="phpMyAdmin" />
<?php
}
?>
<h1>
<?php
echo sprintf($strWelcome,
'<bdo dir="ltr" xml:lang="en">phpMyAdmin ' . PMA_VERSION . '</bdo>');
?>
</h1>
<hr class="clearfloat" />
<form method="post" action="theme.php" target="_parent">
<fieldset>
<legend><?php echo $strTheme; ?></legend>
<?php
echo $_SESSION['PMA_Theme_Manager']->getHtmlSelectBox(false);
?>
<noscript><input type="submit" value="Go" style="vertical-align: middle" /></noscript>
</fieldset>
</form>
<hr />
<h1>H1 Header</h1>
<h2>H2 Header</h2>
<h3>H3 Header</h3>
<h4>H4 Header</h4>
<div class="success">
success message box content!
</div>
<div class="success">
<h1>Auccess message box header!</h1>
success message box content!
</div>
<div class="notice">
notice message box content!
</div>
<div class="notice">
<h1>Notice message box header!</h1>
notice message box content!
</div>
<div class="warning">
warning message box content!
</div>
<div class="warning">
<h1>Warning message box header!</h1>
warning message box content!
</div>
<div class="error">
error message box content!
</div>
<div class="error">
<h1>Error message box header!</h1>
error message box content!
</div>
<fieldset class="confirmation">
<legend>Confirmation fieldset</legend>
<tt>QUERY TO EXECUTE;</tt>
</fieldset>
<fieldset class="tblFooters">
<input type="submit" name="yes" value="YES" />
<input type="submit" name="no" value="NO" />
</fieldset>
<hr />
<div class="success">
success message box content!
</div>
<code class="sql">
<span class="syntax">
<span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span> <span class="syntax_punct">*</span> <br />
<span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_quote syntax_quote_backtick">`test`</span> <span class="syntax_white syntax_white_newline"></span><br />
<span class="syntax_alpha syntax_alpha_reservedWord">LIMIT</span> <span class="syntax_digit syntax_digit_integer">0</span><span class="syntax_punct syntax_punct_listsep">,</span> <span class="syntax_digit syntax_digit_integer">30</span>;<br />
<span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span> <span class="syntax_punct">*</span> <br />
<span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_quote syntax_quote_backtick">`test`</span> <span class="syntax_white syntax_white_newline"></span><br />
<span class="syntax_alpha syntax_alpha_reservedWord">LIMIT</span> <span class="syntax_digit syntax_digit_integer">0</span><span class="syntax_punct syntax_punct_listsep">,</span> <span class="syntax_digit syntax_digit_integer">30</span>;<br />
<span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span> <span class="syntax_punct">*</span> <br />
<span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_quote syntax_quote_backtick">`test`</span> <span class="syntax_white syntax_white_newline"></span><br />
<span class="syntax_alpha syntax_alpha_reservedWord">LIMIT</span> <span class="syntax_digit syntax_digit_integer">0</span><span class="syntax_punct syntax_punct_listsep">,</span> <span class="syntax_digit syntax_digit_integer">30</span>;<br />
<span class="syntax_alpha syntax_alpha_reservedWord">SELECT</span> <span class="syntax_punct">*</span> <br />
<span class="syntax_alpha syntax_alpha_reservedWord">FROM</span> <span class="syntax_quote syntax_quote_backtick">`test`</span> <span class="syntax_white syntax_white_newline"></span><br />
<span class="syntax_alpha syntax_alpha_reservedWord">LIMIT</span> <span class="syntax_digit syntax_digit_integer">0</span><span class="syntax_punct syntax_punct_listsep">,</span> <span class="syntax_digit syntax_digit_integer">30</span>;<br />
</span>
</code>
<div class="tools">
[
<a href="tbl_sql.php?db=test;table=test;sql_query=SELECT+%2A+FROM+%60test%60;show_query=1;token=266edabf70fa6368498d89b4054d01bf#querybox" onclick="window.parent.focus_querywindow('SELECT * FROM `test`'); return false;">Bearbeiten</a>
] [
<a href="import.php?db=test;table=test;sql_query=EXPLAIN+SELECT+%2A+FROM+%60test%60;token=266edabf70fa6368498d89b4054d01bf" >SQL erklären</a>
] [
<a href="import.php?db=test;table=test;sql_query=SELECT+%2A+FROM+%60test%60;show_query=1;show_as_php=1;token=266edabf70fa6368498d89b4054d01bf" >PHP-Code erzeugen</a>
] [
<a href="import.php?db=test;table=test;sql_query=SELECT+%2A+FROM+%60test%60;show_query=1;token=266edabf70fa6368498d89b4054d01bf" >Aktualisieren</a>
]</div>
<hr />
<table class="data">
<caption>table.data caption</caption>
<thead>
<tr><th></th>
<th>table.data thead tr th</th>
<th>table.data thead tr th</th>
<th colspan="3">action</th>
<th>table.data thead tr th</th>
</tr>
</thead>
<tfoot>
<tr><th></th>
<th>table.data tfoot tr th</th>
<th class="value">table.data tfoot tr th</th>
<th colspan="3">action</th>
<th>table.data tfoot tr th</th>
</tr>
</tfoot>
<tbody>
<tr class="odd">
<td><input type="checkbox" id="checkbox_1" name="checkbox_1"
value="1" /></td>
<th><label for="checkbox_1">th label</label></th>
<td class="value">td.value</td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td>table.data tbody tr.odd td</td>
</tr>
<tr class="even">
<td><input type="checkbox" id="checkbox_2" name="checkbox_2"
value="1" /></td>
<th><label for="checkbox_2">th label</label></th>
<td class="value">td.value</td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td>table.data tbody tr.even td</td>
</tr>
<tr class="odd">
<td><input type="checkbox" id="checkbox_3" name="checkbox_3"
value="1" /></td>
<th><label for="checkbox_3">th label</label></th>
<td class="value">td.value</td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td>table.data tbody tr.odd td</td>
</tr>
<tr class="even">
<td><input type="checkbox" id="checkbox_4" name="checkbox_4"
value="1" /></td>
<th><label for="checkbox_4">th label</label></th>
<td class="value">td.value</td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath']; ?>/original/img/bd_drop.png"
width="16" height="16" alt="drop" /></td>
<td>table.data tbody tr.even td</td>
</tr>
</tbody>
</table>
</body>
</html>

19
test/wui.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* runs all defined tests
*
* @version $Id$
* @package phpMyAdmin-test
*/
/**
*
*/
require_once 'AllTests.php';
echo '<pre>';
AllTests::main();
echo '</pre>';
?>