Message Text<\/div>","str_val":"te\\\\x\/t\"1","int_val":10}');
+ PMA_ajaxResponse($message, true, $exra);
+ }
+
+ function testAjaxResponseMessageError()
+ {
+
+ $message = new PMA_Message("Error Message Text", 1);
+
+ // TODO: class for output div should be "error"
+ $this->expectOutputString('{"success":false,"error":"
Error Message Text<\/div>"}');
+ PMA_ajaxResponse($message, false);
+ }
+
+}
\ No newline at end of file
diff --git a/test/libraries/common/PMA_browseUploadFile_test.php b/test/libraries/common/PMA_browseUploadFile_test.php
new file mode 100644
index 0000000000..45b8407d26
--- /dev/null
+++ b/test/libraries/common/PMA_browseUploadFile_test.php
@@ -0,0 +1,48 @@
+expectOutputString('
'
+ . '
'
+ . '
'
+ . '
'
+ . "(" . __('Max: '). $res . $unit .")" . "\n"
+ . '
' . "\n");
+
+ PMA_browseUploadFile($size);
+ }
+}
\ No newline at end of file
diff --git a/test/libraries/common/PMA_buildActionTitles_test.php b/test/libraries/common/PMA_buildActionTitles_test.php
new file mode 100644
index 0000000000..130a972f99
--- /dev/null
+++ b/test/libraries/common/PMA_buildActionTitles_test.php
@@ -0,0 +1,42 @@
+assertEquals($titles, PMA_buildActionTitles());
+
+ }
+}
\ No newline at end of file
diff --git a/test/PMA_cache_test.php b/test/libraries/common/PMA_cache_test.php
similarity index 83%
rename from test/PMA_cache_test.php
rename to test/libraries/common/PMA_cache_test.php
index 34aa5f98d4..2284078c4a 100644
--- a/test/PMA_cache_test.php
+++ b/test/libraries/common/PMA_cache_test.php
@@ -5,22 +5,14 @@
*
* @package phpMyAdmin-test
* @version $Id: PMA_cache_test.php
+ * @group common.lib-tests
*/
-/**
- * Tests core.
- */
-require_once 'PHPUnit/Framework.php';
-
-/**
+/*
* Include to test.
*/
-require_once './libraries/common.lib.php';
+require_once 'libraries/common.lib.php';
-/**
- * Test cache.
- *
- */
class PMA_cache_test extends PHPUnit_Framework_TestCase
{
@@ -99,5 +91,18 @@ class PMA_cache_test extends PHPUnit_Framework_TestCase
PMA_cacheUnset('test_data_2', true);
$this->assertArrayNotHasKey('test_data_2', $_SESSION['cache']['server_server']);
}
+
+ /**
+ * Test clearing user cache
+ */
+ public function testClearUserCache()
+ {
+ $GLOBALS['server'] = 'server';
+ PMA_cacheSet('is_superuser', 'yes', true);
+ $this->assertEquals('yes', $_SESSION['cache']['server_server']['is_superuser']);
+
+ PMA_clearUserCache();
+ $this->assertArrayNotHasKey('is_superuser', $_SESSION['cache']['server_server']);
+ }
}
?>
diff --git a/test/libraries/common/PMA_checkParameters_test.php b/test/libraries/common/PMA_checkParameters_test.php
new file mode 100644
index 0000000000..f72b880ecd
--- /dev/null
+++ b/test/libraries/common/PMA_checkParameters_test.php
@@ -0,0 +1,46 @@
+getPath();
+
+ $this->expectOutputRegex("/Missing parameter: field/" );
+
+ PMA_checkParameters(array('db', 'table', 'field'), false);
+ }
+
+ function testCheckParameter()
+ {
+ $GLOBALS['PMA_PHP_SELF'] = PMA_getenv('PHP_SELF');
+ $GLOBALS['pmaThemePath'] = $_SESSION['PMA_Theme']->getPath();
+ $GLOBALS['table'] = "tblTable";
+ $GLOBALS['field'] = "test_field";
+ $GLOBALS['sql_query'] = "SELECT * FROM tblTable;";
+
+ $this->expectOutputString("");
+ PMA_checkParameters(array('db', 'table', 'field', 'sql_query'), false);
+ }
+}
\ No newline at end of file
diff --git a/test/libraries/common/PMA_contains_nonprintable_ascii_test.php b/test/libraries/common/PMA_contains_nonprintable_ascii_test.php
new file mode 100644
index 0000000000..8f4059ee5f
--- /dev/null
+++ b/test/libraries/common/PMA_contains_nonprintable_ascii_test.php
@@ -0,0 +1,37 @@
+assertEquals($res,PMA_contains_nonprintable_ascii($str));
+ }
+
+}
+
+// PMA_contains_nonprintable_ascii
\ No newline at end of file
diff --git a/test/libraries/common/PMA_convert_bit_default_value_test.php b/test/libraries/common/PMA_convert_bit_default_value_test.php
new file mode 100644
index 0000000000..d54ab2d3ce
--- /dev/null
+++ b/test/libraries/common/PMA_convert_bit_default_value_test.php
@@ -0,0 +1,33 @@
+assertEquals($val, PMA_convert_bit_default_value($bit));
+
+ }
+}
diff --git a/test/libraries/common/PMA_displayMaximumUploadSize_test.php b/test/libraries/common/PMA_displayMaximumUploadSize_test.php
new file mode 100644
index 0000000000..ad93ddb4f3
--- /dev/null
+++ b/test/libraries/common/PMA_displayMaximumUploadSize_test.php
@@ -0,0 +1,41 @@
+assertEquals("(" . __('Max: '). $res . $unit .")", PMA_displayMaximumUploadSize($size));
+
+ }
+}
\ No newline at end of file
diff --git a/test/libraries/common/PMA_display_html_checkbox_test.php b/test/libraries/common/PMA_display_html_checkbox_test.php
new file mode 100644
index 0000000000..c779d7212f
--- /dev/null
+++ b/test/libraries/common/PMA_display_html_checkbox_test.php
@@ -0,0 +1,55 @@
+expectOutputString('
');
+ PMA_display_html_checkbox($name,$label,false,false);
+ }
+
+ function testDisplayHtmlCheckboxChecked()
+ {
+ $name = "test_display_html_checkbox";
+ $label = "text_label_for_checkbox";
+
+ $this->expectOutputString('
');
+ PMA_display_html_checkbox($name,$label,true,false);
+ }
+
+ function testDisplayHtmlCheckboxOnclick()
+ {
+ $name = "test_display_html_checkbox";
+ $label = "text_label_for_checkbox";
+
+ $this->expectOutputString('
');
+ PMA_display_html_checkbox($name,$label,false,true);
+ }
+
+ function testDisplayHtmlCheckboxCheckedOnclick()
+ {
+ $name = "test_display_html_checkbox";
+ $label = "text_label_for_checkbox";
+
+ $this->expectOutputString('
');
+ PMA_display_html_checkbox($name,$label,true,true);
+ }
+}
+
+//PMA_display_html_checkbox
\ No newline at end of file
diff --git a/test/libraries/common/PMA_display_html_radio_test.php b/test/libraries/common/PMA_display_html_radio_test.php
new file mode 100644
index 0000000000..c5f2d4b898
--- /dev/null
+++ b/test/libraries/common/PMA_display_html_radio_test.php
@@ -0,0 +1,188 @@
+expectOutputString("");
+ PMA_display_html_radio($name,$choices);
+ }
+
+ function testDisplayHtmlRadio()
+ {
+ $name = "test_display_radio";
+ $choices = array('value_1'=>'choice_1', 'value_2'=>'choice_2');
+
+ $out = "";
+ foreach ($choices as $choice_value => $choice_label) {
+ $html_field_id = $name . '_' . $choice_value;
+ $out .= '
' . $choice_label . '';
+ $out .= '
';
+ $out .= "\n";
+ }
+
+ $this->expectOutputString($out);
+ PMA_display_html_radio($name,$choices);
+ }
+
+ function testDisplayHtmlRadioWithChecked()
+ {
+ $name = "test_display_radio";
+ $choices = array('value_1'=>'choice_1', 'value_2'=>'choice_2');
+ $checked_choice = "value_2";
+
+ $out = "";
+ foreach ($choices as $choice_value => $choice_label) {
+ $html_field_id = $name . '_' . $choice_value;
+ $out .= '
' . $choice_label . '';
+ $out .= '
';
+ $out .= "\n";
+ }
+
+ $this->expectOutputString($out);
+ PMA_display_html_radio($name,$choices,$checked_choice);
+ }
+
+ function testDisplayHtmlRadioWithCheckedWithClass()
+ {
+ $name = "test_display_radio";
+ $choices = array('value_1'=>'choice_1', 'value_2'=>'choice_2');
+ $checked_choice = "value_2";
+ $class = "test_class";
+
+ $out = "";
+ foreach ($choices as $choice_value => $choice_label) {
+ $html_field_id = $name . '_' . $choice_value;
+ $out .= '
';
+ $out .= '' . $choice_label . '';
+ $out .= '
';
+ $out .= '
';
+ $out .= "\n";
+ }
+
+ $this->expectOutputString($out);
+ PMA_display_html_radio($name,$choices,$checked_choice,true,false,$class);
+ }
+
+ function testDisplayHtmlRadioWithoutBR()
+ {
+ $name = "test_display_radio";
+ $choices = array('value_1'=>'choice_1', 'value&_<2>'=>'choice_2');
+ $checked_choice = "choice_2";
+
+ $out = "";
+ foreach ($choices as $choice_value => $choice_label) {
+ $html_field_id = $name . '_' . $choice_value;
+ $out .= '
' . $choice_label . '';
+ $out .= "\n";
+ }
+
+ $this->expectOutputString($out);
+ PMA_display_html_radio($name,$choices,$checked_choice,false);
+ }
+
+ function testDisplayHtmlRadioEscapeLabelEscapeLabel()
+ {
+ $name = "test_display_radio";
+ $choices = array('value_1'=>'choice_1', 'value_&2'=>'choice&_<2>');
+ $checked_choice = "value_2";
+
+ $out = "";
+ foreach ($choices as $choice_value => $choice_label) {
+ $html_field_id = $name . '_' . $choice_value;
+ $out .= '
' . htmlspecialchars($choice_label) . '';
+ $out .= '
';
+ $out .= "\n";
+ }
+
+ $this->expectOutputString($out);
+ PMA_display_html_radio($name,$choices,$checked_choice,true,true);
+ }
+
+ function testDisplayHtmlRadioEscapeLabelNotEscapeLabel()
+ {
+ $name = "test_display_radio";
+ $choices = array('value_1'=>'choice_1', 'value_&2'=>'choice&_<2>');
+ $checked_choice = "value_2";
+
+ $out = "";
+ foreach ($choices as $choice_value => $choice_label) {
+ $html_field_id = $name . '_' . $choice_value;
+ $out .= '
' . $choice_label . '';
+ $out .= '
';
+ $out .= "\n";
+ }
+
+ $this->expectOutputString($out);
+ PMA_display_html_radio($name,$choices,$checked_choice,true,false);
+ }
+
+ function testDisplayHtmlRadioEscapeLabelEscapeLabelWithClass()
+ {
+ $name = "test_display_radio";
+ $choices = array('value_1'=>'choice_1', 'value_&2'=>'choice&_<2>');
+ $checked_choice = "value_2";
+ $class = "test_class";
+
+ $out = "";
+ foreach ($choices as $choice_value => $choice_label) {
+ $html_field_id = $name . '_' . $choice_value;
+ $out .= '
';
+ $out .= '' . htmlspecialchars($choice_label) . '';
+ $out .= '
';
+ $out .= '
';
+ $out .= "\n";
+ }
+
+ $this->expectOutputString($out);
+ PMA_display_html_radio($name,$choices,$checked_choice,true,true,$class);
+ }
+}
\ No newline at end of file
diff --git a/test/PMA_escapeMySqlWildcards_test.php b/test/libraries/common/PMA_escapeMySqlWildcards_test.php
similarity index 87%
rename from test/PMA_escapeMySqlWildcards_test.php
rename to test/libraries/common/PMA_escapeMySqlWildcards_test.php
index ccdf15b972..c77a841fe7 100644
--- a/test/PMA_escapeMySqlWildcards_test.php
+++ b/test/libraries/common/PMA_escapeMySqlWildcards_test.php
@@ -4,22 +4,15 @@
* Test for MySQL Wildcards escaping/unescaping
*
* @package phpMyAdmin-test
+ * @version $Id: PMA_escapeMySqlWildcards_test.php
+ * @group common.lib-tests
*/
-/**
- * Tests core.
- */
-require_once 'PHPUnit/Framework.php';
-
-/**
+/*
* Include to test.
*/
-require_once './libraries/common.lib.php';
+require_once 'libraries/common.lib.php';
-/**
- * Test MySQL escaping.
- *
- */
class PMA_escapeMySqlWildcards_test extends PHPUnit_Framework_TestCase
{
diff --git a/test/libraries/common/PMA_extractValueFromFormattedSize_test.php b/test/libraries/common/PMA_extractValueFromFormattedSize_test.php
new file mode 100644
index 0000000000..038a36e427
--- /dev/null
+++ b/test/libraries/common/PMA_extractValueFromFormattedSize_test.php
@@ -0,0 +1,37 @@
+assertEquals(-1,PMA_extractValueFromFormattedSize(100));
+ }
+
+ function testExtractValueFromFormattedSizeGB(){
+
+ $this->assertEquals(10737418240,PMA_extractValueFromFormattedSize("10GB"));
+ }
+
+ function testExtractValueFromFormattedSizeMB(){
+
+ $this->assertEquals(15728640,PMA_extractValueFromFormattedSize("15MB"));
+ }
+
+ function testExtractValueFromFormattedSizeK(){
+
+ $this->assertEquals(262144,PMA_extractValueFromFormattedSize("256K"));
+ }
+}
diff --git a/test/PMA_foreignKeySupported_test.php b/test/libraries/common/PMA_foreignKeySupported_test.php
similarity index 82%
rename from test/PMA_foreignKeySupported_test.php
rename to test/libraries/common/PMA_foreignKeySupported_test.php
index f00afca2c4..e0ebd2e8d5 100644
--- a/test/PMA_foreignKeySupported_test.php
+++ b/test/libraries/common/PMA_foreignKeySupported_test.php
@@ -4,28 +4,20 @@
* Test for supporting foreign key
*
* @package phpMyAdmin-test
+ * @version $Id: PMA_foreignKeySupported_test.php
+ * @group common.lib-tests
*/
-/**
- * Tests core.
- */
-require_once 'PHPUnit/Framework.php';
-
-/**
+/*
* Include to test.
*/
-require_once './libraries/common.lib.php';
+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),
@@ -38,7 +30,6 @@ class PMA_foreignKeySupported_test extends PHPUnit_Framework_TestCase
* foreign key supported test
* @dataProvider foreignkeySupportedDataProvider
*/
-
public function testForeignkeySupported($a, $e) {
$this->assertEquals($e, PMA_foreignkey_supported($a));
}
diff --git a/test/PMA_formatNumberByteDown_test.php b/test/libraries/common/PMA_formatNumberByteDown_test.php
similarity index 62%
rename from test/PMA_formatNumberByteDown_test.php
rename to test/libraries/common/PMA_formatNumberByteDown_test.php
index 1bc3d063e5..f0265c6233 100644
--- a/test/PMA_formatNumberByteDown_test.php
+++ b/test/libraries/common/PMA_formatNumberByteDown_test.php
@@ -5,35 +5,24 @@
*
* @package phpMyAdmin-test
* @version $Id: PMA_formatNumberByteDown_test.php
+ * @group common.lib-tests
*/
-/**
- * Tests core.
- */
-require_once 'PHPUnit/Framework.php';
-
-/**
+/*
* Include to test.
*/
-require_once './libraries/common.lib.php';
+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;
/**
@@ -62,14 +51,14 @@ class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase
public function formatNumberDataProvider() {
return array(
- array(10, 2, 2, '10,00 '),
+ array(10, 2, 2, '10 '),
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')
+ array(100, 2, 2, '100 '),
+ array(-1000.454, 4, 2, '-1,000.45 '),
+ array(0.00003, 3, 2, '30 µ'),
+ array(0.003, 3, 3, '3 m'),
+ array(-0.003, 6, 0, '-3,000 µ'),
+ array(100.98, 0, 2, '100.98')
);
}
@@ -77,24 +66,22 @@ class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase
* format number test, globals are defined
* @dataProvider formatNumberDataProvider
*/
-
- public function testFormatNumber($a, $b, $c, $e) {
- $this->assertEquals($e, (string)PMA_formatNumber($a, $b, $c, false));
+ public function testFormatNumber($a, $b, $c, $d) {
+ $this->assertEquals($d, (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'))
+ array(10, 2, 2, array('10', __('B'))),
+ array(100, 2, 0, array('0', __('KiB'))),
+ array(100, 3, 0, array('100', __('B'))),
+ array(100, 2, 2, array('0.10', __('KiB'))),
+ array(1034, 3, 2, array('1.01', __('KiB'))),
+ array(100233, 3, 3, array('97.884', __('KiB'))),
+ array(2206451, 1, 2, array('2.10', __('MiB')))
);
}
@@ -102,7 +89,6 @@ class PMA_formatNumberByteDown_test extends PHPUnit_Framework_TestCase
* format byte test, globals are defined
* @dataProvider formatByteDownDataProvider
*/
-
public function testFormatByteDown($a, $b, $c, $e) {
$result = PMA_formatByteDown($a, $b, $c);
$result[0] = trim($result[0]);
diff --git a/test/libraries/common/PMA_formatSql_test.php b/test/libraries/common/PMA_formatSql_test.php
new file mode 100644
index 0000000000..df0ddc4f4b
--- /dev/null
+++ b/test/libraries/common/PMA_formatSql_test.php
@@ -0,0 +1,744 @@
+tmpCfg = $cfg;
+ }
+
+ /**
+ * recovering globals and session
+ */
+ public function tearDown() {
+ global $cfg;
+ $cfg = $this->tmpCfg;
+ }
+
+ function testFormatSQLNotArray(){
+ global $cfg;
+ $cfg['SQP']['fmtType'] = 'html';
+ $sql = "SELECT * FROM tTable;";
+ $this->assertEquals("
\n$sql\n
",PMA_formatSql($sql));
+ }
+
+ function testFormatSQLfmTypeHtml_1(){
+ global $cfg;
+ $cfg['SQP']['fmtType'] = 'html';
+ $cfg['MySQLManualType'] = 'viewable';
+
+ $sql = array (
+ 'raw' => 'SELECT 1;',
+ 0 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'SELECT',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ 1 =>
+ array (
+ 'type' => 'digit_integer',
+ 'data' => '1',
+ 'pos' => 8,
+ ),
+ 2 =>
+ array (
+ 'type' => 'punct_queryend',
+ 'data' => ';',
+ 'pos' => 0,
+ ),
+ 'len' => 3,
+ );
+ $unparsed = "SELECT 1;";
+ $expected = '
SELECT 1 ;
';
+
+ $this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
+ }
+
+ function testFormatSQLfmTypeHtml_2(){
+ global $cfg;
+ $cfg['SQP']['fmtType'] = 'html';
+ $cfg['MySQLManualType'] = 'viewable';
+
+ $unparsed = "SELECT * from `tTable`;";
+ $sql = array (
+ 'raw' => $unparsed,
+ 0 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'SELECT',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ 1 =>
+ array (
+ 'type' => 'punct',
+ 'data' => '*',
+ 'pos' => 0,
+ ),
+ 2 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'from',
+ 'pos' => 13,
+ 'forbidden' => true,
+ ),
+ 3 =>
+ array (
+ 'type' => 'quote_backtick',
+ 'data' => '`tTable`',
+ 'pos' => 0,
+ ),
+ 4 =>
+ array (
+ 'type' => 'punct_queryend',
+ 'data' => ';',
+ 'pos' => 0,
+ ),
+ 'len' => 5,
+ );
+ $expected = '
SELECT *
FROM `tTable` ;
';
+
+ $this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
+ }
+
+ function testFormatSQLfmTypeHtml_3(){
+ global $cfg;
+ $cfg['SQP']['fmtType'] = 'html';
+ $cfg['MySQLManualType'] = 'viewable';
+
+ $unparsed = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;';
+ $sql = array (
+ 'raw' => $unparsed,
+ 0 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'SELECT',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ 1 =>
+ array (
+ 'type' => 'punct',
+ 'data' => '*',
+ 'pos' => 0,
+ ),
+ 2 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'FROM',
+ 'pos' => 13,
+ 'forbidden' => true,
+ ),
+ 3 =>
+ array (
+ 'type' => 'quote_backtick',
+ 'data' => '`tTable_A`',
+ 'pos' => 0,
+ ),
+ 4 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'A',
+ 'pos' => 26,
+ 'forbidden' => false,
+ ),
+ 5 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'INNER',
+ 'pos' => 32,
+ 'forbidden' => true,
+ ),
+ 6 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'JOIN',
+ 'pos' => 37,
+ 'forbidden' => true,
+ ),
+ 7 =>
+ array (
+ 'type' => 'quote_backtick',
+ 'data' => '`tTable_B`',
+ 'pos' => 0,
+ ),
+ 8 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'B',
+ 'pos' => 50,
+ 'forbidden' => false,
+ ),
+ 9 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'ON',
+ 'pos' => 53,
+ 'forbidden' => true,
+ ),
+ 10 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'B',
+ 'pos' => 55,
+ 'forbidden' => false,
+ ),
+ 11 =>
+ array (
+ 'type' => 'punct_qualifier',
+ 'data' => '.',
+ 'pos' => 0,
+ ),
+ 12 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'ID',
+ 'pos' => 58,
+ 'forbidden' => false,
+ ),
+ 13 =>
+ array (
+ 'type' => 'punct',
+ 'data' => '=',
+ 'pos' => 0,
+ ),
+ 14 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'A',
+ 'pos' => 62,
+ 'forbidden' => false,
+ ),
+ 15 =>
+ array (
+ 'type' => 'punct_qualifier',
+ 'data' => '.',
+ 'pos' => 0,
+ ),
+ 16 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'ID',
+ 'pos' => 65,
+ 'forbidden' => false,
+ ),
+ 17 =>
+ array (
+ 'type' => 'punct_queryend',
+ 'data' => ';',
+ 'pos' => 0,
+ ),
+ 'len' => 18,
+ );
+
+ $expected = '
SELECT *
FROM `tTable_A` A
INNER JOIN `tTable_B` B ON B.ID = A.ID;
';
+
+ $this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
+ }
+
+ function testFormatSQLfmTypeText_1(){
+ global $cfg;
+ $cfg['SQP']['fmtType'] = 'text';
+ $cfg['MySQLManualType'] = 'viewable';
+
+ $sql = array (
+ 'raw' => 'SELECT 1;',
+ 0 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'SELECT',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ 1 =>
+ array (
+ 'type' => 'digit_integer',
+ 'data' => '1',
+ 'pos' => 8,
+ ),
+ 2 =>
+ array (
+ 'type' => 'punct_queryend',
+ 'data' => ';',
+ 'pos' => 0,
+ ),
+ 'len' => 3,
+ );
+ $unparsed = "SELECT 1;";
+ $expected = '
SELECT 1 ;
';
+
+ $this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
+ }
+
+ function testFormatSQLfmTypeText_2(){
+ global $cfg;
+ $cfg['SQP']['fmtType'] = 'text';
+ $cfg['MySQLManualType'] = 'viewable';
+
+ $unparsed = "SELECT * from `tTable`;";
+ $sql = array (
+ 'raw' => $unparsed,
+ 0 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'SELECT',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ 1 =>
+ array (
+ 'type' => 'punct',
+ 'data' => '*',
+ 'pos' => 0,
+ ),
+ 2 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'from',
+ 'pos' => 13,
+ 'forbidden' => true,
+ ),
+ 3 =>
+ array (
+ 'type' => 'quote_backtick',
+ 'data' => '`tTable`',
+ 'pos' => 0,
+ ),
+ 4 =>
+ array (
+ 'type' => 'punct_queryend',
+ 'data' => ';',
+ 'pos' => 0,
+ ),
+ 'len' => 5,
+ );
+ $expected = '
SELECT *
FROM `tTable` ;
';
+
+ $this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
+ }
+
+ function testFormatSQLfmTypeText_3(){
+ global $cfg;
+ $cfg['SQP']['fmtType'] = 'text';
+ $cfg['MySQLManualType'] = 'viewable';
+
+ $unparsed = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;';
+ $sql = array (
+ 'raw' => $unparsed,
+ 0 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'SELECT',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ 1 =>
+ array (
+ 'type' => 'punct',
+ 'data' => '*',
+ 'pos' => 0,
+ ),
+ 2 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'FROM',
+ 'pos' => 13,
+ 'forbidden' => true,
+ ),
+ 3 =>
+ array (
+ 'type' => 'quote_backtick',
+ 'data' => '`tTable_A`',
+ 'pos' => 0,
+ ),
+ 4 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'A',
+ 'pos' => 26,
+ 'forbidden' => false,
+ ),
+ 5 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'INNER',
+ 'pos' => 32,
+ 'forbidden' => true,
+ ),
+ 6 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'JOIN',
+ 'pos' => 37,
+ 'forbidden' => true,
+ ),
+ 7 =>
+ array (
+ 'type' => 'quote_backtick',
+ 'data' => '`tTable_B`',
+ 'pos' => 0,
+ ),
+ 8 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'B',
+ 'pos' => 50,
+ 'forbidden' => false,
+ ),
+ 9 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'ON',
+ 'pos' => 53,
+ 'forbidden' => true,
+ ),
+ 10 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'B',
+ 'pos' => 55,
+ 'forbidden' => false,
+ ),
+ 11 =>
+ array (
+ 'type' => 'punct_qualifier',
+ 'data' => '.',
+ 'pos' => 0,
+ ),
+ 12 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'ID',
+ 'pos' => 58,
+ 'forbidden' => false,
+ ),
+ 13 =>
+ array (
+ 'type' => 'punct',
+ 'data' => '=',
+ 'pos' => 0,
+ ),
+ 14 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'A',
+ 'pos' => 62,
+ 'forbidden' => false,
+ ),
+ 15 =>
+ array (
+ 'type' => 'punct_qualifier',
+ 'data' => '.',
+ 'pos' => 0,
+ ),
+ 16 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'ID',
+ 'pos' => 65,
+ 'forbidden' => false,
+ ),
+ 17 =>
+ array (
+ 'type' => 'punct_queryend',
+ 'data' => ';',
+ 'pos' => 0,
+ ),
+ 'len' => 18,
+ );
+ $expected = '
SELECT *
FROM `tTable_A` A
INNER JOIN `tTable_B` B ON B.ID = A.ID;
';
+
+ $this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
+ }
+
+ function testFormatSQLfmTypeNone_1(){
+ global $cfg;
+ $cfg['SQP']['fmtType'] = 'none';
+ $cfg['MySQLManualType'] = 'viewable';
+
+ $sql = array (
+ 'raw' => 'SELECT 1;',
+ 0 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'SELECT',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ 1 =>
+ array (
+ 'type' => 'digit_integer',
+ 'data' => '1',
+ 'pos' => 8,
+ ),
+ 2 =>
+ array (
+ 'type' => 'punct_queryend',
+ 'data' => ';',
+ 'pos' => 0,
+ ),
+ 'len' => 3,
+ );
+ $unparsed = "SELECT 1;";
+
+ $expected = "
\nSELECT 1;\n
";
+ $this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
+
+ $expected = "SELECT 1;";
+ $this->assertEquals($expected,PMA_formatSql($sql));
+ }
+
+ function testFormatSQLfmTypeNone_2(){
+ global $cfg;
+ $cfg['SQP']['fmtType'] = 'none';
+ $cfg['MySQLManualType'] = 'viewable';
+
+ $unparsed = "SELECT * from `tTable`;";
+ $sql = array (
+ 'raw' => $unparsed,
+ 0 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'SELECT',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ 1 =>
+ array (
+ 'type' => 'punct',
+ 'data' => '*',
+ 'pos' => 0,
+ ),
+ 2 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'from',
+ 'pos' => 13,
+ 'forbidden' => true,
+ ),
+ 3 =>
+ array (
+ 'type' => 'quote_backtick',
+ 'data' => '`tTable`',
+ 'pos' => 0,
+ ),
+ 4 =>
+ array (
+ 'type' => 'punct_queryend',
+ 'data' => ';',
+ 'pos' => 0,
+ ),
+ 'len' => 5,
+ );
+
+ $expected = "
\nSELECT * from `tTable`;\n
";
+ $this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
+
+ $expected = "SELECT * from `tTable`;";
+ $this->assertEquals($expected,PMA_formatSql($sql));
+ }
+
+ function testFormatSQLfmTypeNone_3(){
+ global $cfg;
+ $cfg['SQP']['fmtType'] = 'none';
+ $cfg['MySQLManualType'] = 'viewable';
+
+ $unparsed = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;';
+ $sql = array (
+ 'raw' => $unparsed,
+ 0 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'SELECT',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ 1 =>
+ array (
+ 'type' => 'punct',
+ 'data' => '*',
+ 'pos' => 0,
+ ),
+ 2 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'FROM',
+ 'pos' => 13,
+ 'forbidden' => true,
+ ),
+ 3 =>
+ array (
+ 'type' => 'quote_backtick',
+ 'data' => '`tTable_A`',
+ 'pos' => 0,
+ ),
+ 4 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'A',
+ 'pos' => 26,
+ 'forbidden' => false,
+ ),
+ 5 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'INNER',
+ 'pos' => 32,
+ 'forbidden' => true,
+ ),
+ 6 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'JOIN',
+ 'pos' => 37,
+ 'forbidden' => true,
+ ),
+ 7 =>
+ array (
+ 'type' => 'quote_backtick',
+ 'data' => '`tTable_B`',
+ 'pos' => 0,
+ ),
+ 8 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'B',
+ 'pos' => 50,
+ 'forbidden' => false,
+ ),
+ 9 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'ON',
+ 'pos' => 53,
+ 'forbidden' => true,
+ ),
+ 10 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'B',
+ 'pos' => 55,
+ 'forbidden' => false,
+ ),
+ 11 =>
+ array (
+ 'type' => 'punct_qualifier',
+ 'data' => '.',
+ 'pos' => 0,
+ ),
+ 12 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'ID',
+ 'pos' => 58,
+ 'forbidden' => false,
+ ),
+ 13 =>
+ array (
+ 'type' => 'punct',
+ 'data' => '=',
+ 'pos' => 0,
+ ),
+ 14 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'A',
+ 'pos' => 62,
+ 'forbidden' => false,
+ ),
+ 15 =>
+ array (
+ 'type' => 'punct_qualifier',
+ 'data' => '.',
+ 'pos' => 0,
+ ),
+ 16 =>
+ array (
+ 'type' => 'alpha_identifier',
+ 'data' => 'ID',
+ 'pos' => 65,
+ 'forbidden' => false,
+ ),
+ 17 =>
+ array (
+ 'type' => 'punct_queryend',
+ 'data' => ';',
+ 'pos' => 0,
+ ),
+ 'len' => 18,
+ );
+
+ $expected = "
\nSELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;\n
";
+ $this->assertEquals($expected,PMA_formatSql($sql, $unparsed));
+
+ $expected = 'SELECT * FROM `tTable_A` A INNER JOIN `tTable_B` B ON B.ID = A.ID;';
+ $this->assertEquals($expected,PMA_formatSql($sql));
+ }
+
+ function testFormatSQLWithoutType(){
+ global $cfg;
+ $cfg['SQP']['fmtType'] = '';
+ $cfg['MySQLManualType'] = 'viewable';
+ $sql = array (
+ 'raw' => 'SELECT 1;',
+ 0 =>
+ array (
+ 'type' => 'alpha_reservedWord',
+ 'data' => 'SELECT',
+ 'pos' => 6,
+ 'forbidden' => true,
+ ),
+ 1 =>
+ array (
+ 'type' => 'digit_integer',
+ 'data' => '1',
+ 'pos' => 8,
+ ),
+ 2 =>
+ array (
+ 'type' => 'punct_queryend',
+ 'data' => ';',
+ 'pos' => 0,
+ ),
+ 'len' => 3,
+ );
+ $this->assertEmpty(PMA_formatSql($sql));
+ }
+
+ function testFormatSQLError(){
+ global $SQP_errorString;
+ $SQP_errorString = true;
+ $sql = array("raw" => "& \" < >");
+ $this->assertEquals("& " < >",PMA_formatSql($sql));
+ $SQP_errorString = false;
+ }
+}
diff --git a/test/libraries/common/PMA_generateHiddenMaxFileSize_test.php b/test/libraries/common/PMA_generateHiddenMaxFileSize_test.php
new file mode 100644
index 0000000000..3cd6810a47
--- /dev/null
+++ b/test/libraries/common/PMA_generateHiddenMaxFileSize_test.php
@@ -0,0 +1,40 @@
+assertEquals(PMA_generateHiddenMaxFileSize($size),
+ '
');
+ }
+}
diff --git a/test/libraries/common/PMA_generate_html_dropdown_test.php b/test/libraries/common/PMA_generate_html_dropdown_test.php
new file mode 100644
index 0000000000..8e27c2088b
--- /dev/null
+++ b/test/libraries/common/PMA_generate_html_dropdown_test.php
@@ -0,0 +1,69 @@
+';
+
+ $this->assertEquals($result, PMA_generate_html_dropdown($name,$choices,$active_choice,$id));
+ }
+
+ function testGenerateHtmlDropdown()
+ {
+ $name = "&test_dropdown_name";
+ $choices = array("value_1" => "label_1", "value&_2\"" => "label_2");
+ $active_choice = null;
+ $id = "test_<dropdown>_name";
+
+ $result = '
';
+
+ $this->assertEquals($result, PMA_generate_html_dropdown($name,$choices,$active_choice,$id));
+ }
+
+ function testGenerateHtmlDropdownWithActive()
+ {
+ $name = "&test_dropdown_name";
+ $choices = array("value_1" => "label_1", "value&_2\"" => "label_2");
+ $active_choice = "value&_2\"";
+ $id = "test_<dropdown>_name";
+
+ $result = '
';
+
+ $this->assertEquals($result, PMA_generate_html_dropdown($name,$choices,$active_choice,$id));
+ }
+}
\ No newline at end of file
diff --git a/test/libraries/common/PMA_generate_slider_effect_test.php b/test/libraries/common/PMA_generate_slider_effect_test.php
new file mode 100644
index 0000000000..62458be8da
--- /dev/null
+++ b/test/libraries/common/PMA_generate_slider_effect_test.php
@@ -0,0 +1,53 @@
+expectOutputString('
' . "\n" . ' ');
+ PMA_generate_slider_effect($id,$message);
+ }
+
+ function testGenerateSliderEffectTestClosed()
+ {
+ global $cfg;
+ $cfg['InitialSlidersState'] = 'closed';
+
+ $id = "test_id";
+ $message = "test_message";
+
+ $this->expectOutputString('
' . "\n" . ' ');
+ PMA_generate_slider_effect($id,$message);
+ }
+
+ function testGenerateSliderEffectTestDisabled()
+ {
+ global $cfg;
+ $cfg['InitialSlidersState'] = 'disabled';
+
+ $id = "test_id";
+ $message = "test_message";
+
+ $this->expectOutputString('
');
+ PMA_generate_slider_effect($id,$message);
+ }
+}
\ No newline at end of file
diff --git a/test/libraries/common/PMA_getDbLink_test.php b/test/libraries/common/PMA_getDbLink_test.php
new file mode 100644
index 0000000000..00053e1d37
--- /dev/null
+++ b/test/libraries/common/PMA_getDbLink_test.php
@@ -0,0 +1,57 @@
+assertEmpty(PMA_getDbLink());
+ }
+
+ function testGetDbLinkNull()
+ {
+ global $cfg;
+ $GLOBALS['db'] = 'test_db';
+ $database = $GLOBALS['db'];
+ $this->assertEquals('
'
+ . htmlspecialchars($database) . '',PMA_getDbLink());
+ }
+
+ function testGetDbLink()
+ {
+ global $cfg;
+ $database = 'test_database';
+ $this->assertEquals('
'
+ . htmlspecialchars($database) . '',PMA_getDbLink($database));
+ }
+
+ function testGetDbLinkWithSpecialChars()
+ {
+ global $cfg;
+ $database = 'test&data\'base';
+ $this->assertEquals('
'
+ . htmlspecialchars($database) . '',PMA_getDbLink($database));
+ }
+}
\ No newline at end of file
diff --git a/test/libraries/common/PMA_getIcon_test.php b/test/libraries/common/PMA_getIcon_test.php
new file mode 100644
index 0000000000..7835acabd7
--- /dev/null
+++ b/test/libraries/common/PMA_getIcon_test.php
@@ -0,0 +1,74 @@
+assertEquals('
',
+ PMA_getIcon('b_comment.png') );
+ }
+
+ function testGetIconWithPropertiesIconic(){
+
+ $GLOBALS['cfg']['PropertiesIconic'] = true;
+ $GLOBALS['pmaThemeImage'] = 'theme/';
+
+ $this->assertEquals('

',
+ PMA_getIcon('b_comment.png') );
+ }
+
+ function testGetIconAlternate(){
+
+ $GLOBALS['cfg']['PropertiesIconic'] = true;
+ $GLOBALS['pmaThemeImage'] = 'theme/';
+ $alternate_text = 'alt_str';
+
+ $this->assertEquals('

',
+ PMA_getIcon('b_comment.png',$alternate_text) );
+ }
+
+ function testGetIconWithContainer(){
+
+ $GLOBALS['cfg']['PropertiesIconic'] = true;
+ $GLOBALS['pmaThemeImage'] = 'theme/';
+ $alternate_text = 'alt_str';
+
+ $this->assertEquals('

',
+ PMA_getIcon('b_comment.png',$alternate_text, true) );
+
+ }
+
+ function testGetIconWithContainerAndForceText(){
+
+ $GLOBALS['cfg']['PropertiesIconic'] = true;
+ $GLOBALS['pmaThemeImage'] = 'theme/';
+ $alternate_text = 'alt_str';
+
+ $this->assertEquals('
' . $alternate_text . '',
+ PMA_getIcon('b_comment.png',$alternate_text, true, true) );
+
+ }
+}
\ No newline at end of file
diff --git a/test/libraries/common/PMA_getTitleForTarget_test.php b/test/libraries/common/PMA_getTitleForTarget_test.php
new file mode 100644
index 0000000000..17566813af
--- /dev/null
+++ b/test/libraries/common/PMA_getTitleForTarget_test.php
@@ -0,0 +1,43 @@
+assertEquals($result,PMA_getTitleForTarget($target));
+ }
+
+}
+
+//PMA_getTitleForTarget
\ No newline at end of file
diff --git a/test/PMA_localisedDateTimespan_test.php b/test/libraries/common/PMA_localisedDateTimespan_test.php
similarity index 92%
rename from test/PMA_localisedDateTimespan_test.php
rename to test/libraries/common/PMA_localisedDateTimespan_test.php
index e472373f7d..7ec03645ec 100644
--- a/test/PMA_localisedDateTimespan_test.php
+++ b/test/libraries/common/PMA_localisedDateTimespan_test.php
@@ -5,41 +5,29 @@
*
* @package phpMyAdmin-test
* @version $Id: PMA_localisedDateTimespan_test.php
+ * @group common.lib-tests
*/
-/**
- * Tests core.
- */
-require_once 'PHPUnit/Framework.php';
-
-/**
+/*
* Include to test.
*/
-require_once './libraries/common.lib.php';
+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;
/**
@@ -67,7 +55,6 @@ class PMA_localisedDateTimespan_test extends PHPUnit_Framework_TestCase
/**
* data provider for localised date test
*/
-
public function localisedDateDataProvider() {
return array(
array(1227455558, '', 'Nov 23, 2008 at 03:52 PM'),
@@ -79,7 +66,6 @@ class PMA_localisedDateTimespan_test extends PHPUnit_Framework_TestCase
* localised date test, globals are defined
* @dataProvider localisedDateDataProvider
*/
-
public function testLocalisedDate($a, $b, $e) {
$this->assertEquals($e, PMA_localisedDate($a, $b));
}
@@ -99,7 +85,6 @@ class PMA_localisedDateTimespan_test extends PHPUnit_Framework_TestCase
* localised timestamp test, globals are defined
* @dataProvider timespanFormatDataProvider
*/
-
public function testTimespanFormat($a, $e) {
$GLOBALS['timespanfmt'] = '%s days, %s hours, %s minutes and %s seconds';
diff --git a/test/PMA_pow_test.php b/test/libraries/common/PMA_pow_test.php
similarity index 91%
rename from test/PMA_pow_test.php
rename to test/libraries/common/PMA_pow_test.php
index cb62e528c6..ff55e16b81 100644
--- a/test/PMA_pow_test.php
+++ b/test/libraries/common/PMA_pow_test.php
@@ -1,20 +1,18 @@
assertEquals($expected, PMA_unQuote($param));
}
@@ -66,7 +56,6 @@ class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
/**
* data provider for unQuote test with chosen quote
*/
-
public function unQuoteSelectedProvider() {
return array(
array('"test\'"', "test'"),
@@ -80,7 +69,6 @@ class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
* unQuote test with chosen quote
* @dataProvider unQuoteSelectedProvider
*/
-
public function testUnQuoteSelectedChar($param, $expected) {
$this->assertEquals($expected, PMA_unQuote($param, '"'));
}
@@ -88,7 +76,6 @@ class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
/**
* data provider for backquote test
*/
-
public function backquoteDataProvider() {
return array(
array('0', '`0`'),
@@ -102,10 +89,20 @@ class PMA_quoting_slashing_test extends PHPUnit_Framework_TestCase
* backquote test with different param $do_it (true, false)
* @dataProvider backquoteDataProvider
*/
-
public function testBackquote($a, $b) {
+ // Test bypass quoting (used by dump functions)
$this->assertEquals($a, PMA_backquote($a, false));
+
+ // Test backquote
$this->assertEquals($b, PMA_backquote($a));
}
+
+ public function testBackquoteForbidenWords() {
+ global $PMA_SQPdata_forbidden_word;
+
+ foreach ($PMA_SQPdata_forbidden_word as $forbidden){
+ $this->assertEquals("`" . $forbidden . "`", PMA_backquote($forbidden, false));
+ }
+ }
}
?>
diff --git a/test/libraries/common/PMA_showDocu_test.php b/test/libraries/common/PMA_showDocu_test.php
new file mode 100644
index 0000000000..b287ea107a
--- /dev/null
+++ b/test/libraries/common/PMA_showDocu_test.php
@@ -0,0 +1,39 @@
+

';
+
+ $this->assertEquals($expected, PMA_showDocu($anchor));
+
+ }
+
+ function testShowDocuNotReplaceHelpImg()
+ {
+ $GLOBALS['cfg']['ReplaceHelpImg'] = false;
+
+ $anchor = "relation";
+ $expected = '[
' . __('Documentation') . ']';
+
+ $this->assertEquals($expected, PMA_showDocu($anchor));
+
+ }
+}
\ No newline at end of file
diff --git a/test/libraries/common/PMA_showMessage_test_disabled.php b/test/libraries/common/PMA_showMessage_test_disabled.php
new file mode 100644
index 0000000000..d89aa10e98
--- /dev/null
+++ b/test/libraries/common/PMA_showMessage_test_disabled.php
@@ -0,0 +1,67 @@
+expectOutputString("
+
");
+
+ echo PMA_showMessage("msg");
+
+ //$this->assertEquals("",PMA_showMessage("msg"));
+ $this->assertTrue(true);
+ }
+}
\ No newline at end of file
diff --git a/test/libraries/common/PMA_showPHPDocu_test.php b/test/libraries/common/PMA_showPHPDocu_test.php
new file mode 100644
index 0000000000..eb98f306b7
--- /dev/null
+++ b/test/libraries/common/PMA_showPHPDocu_test.php
@@ -0,0 +1,42 @@
+

';
+
+ $this->assertEquals($expected, PMA_showPHPDocu($target));
+ }
+
+ function testShwoPHPDocuNotReplaceHelpImg()
+ {
+ $GLOBALS['cfg']['ReplaceHelpImg'] = false;
+
+ $target = "docu";
+ $lang = _pgettext('PHP documentation language', 'en');
+ $expected = '[
' . __('Documentation') . ']';
+
+ $this->assertEquals($expected, PMA_showPHPDocu($target));
+ }
+
+
+}
\ No newline at end of file
diff --git a/test/PMA_stringOperations_test.php b/test/libraries/common/PMA_stringOperations_test.php
similarity index 95%
rename from test/PMA_stringOperations_test.php
rename to test/libraries/common/PMA_stringOperations_test.php
index 38aa26bf7c..f57a2b4570 100644
--- a/test/PMA_stringOperations_test.php
+++ b/test/libraries/common/PMA_stringOperations_test.php
@@ -3,23 +3,16 @@
/**
* Test for several string operations
*
+ * @package phpMyAdmin-test
* @version $Id: PMA_stringOperations_test.php
+ * @group common.lib-tests
*/
-/**
- * Tests core.
- */
-require_once 'PHPUnit/Framework.php';
-
-/**
+/*
* Include to test.
*/
-require_once './libraries/common.lib.php';
+require_once 'libraries/common.lib.php';
-/**
- * Test string operations.
- * @package phpMyAdmin-test
- */
class PMA_stringOperations_test extends PHPUnit_Framework_TestCase
{
@@ -40,6 +33,7 @@ class PMA_stringOperations_test extends PHPUnit_Framework_TestCase
*/
public function setUp() {
+ global $GLOBALS, $_SESSION;
$this->tmpGlobals = $GLOBALS;
$this->tmpSession = $_SESSION;
diff --git a/test/libraries/common/PMA_unsupportedDatatypes_test.php b/test/libraries/common/PMA_unsupportedDatatypes_test.php
new file mode 100644
index 0000000000..686e4ee851
--- /dev/null
+++ b/test/libraries/common/PMA_unsupportedDatatypes_test.php
@@ -0,0 +1,32 @@
+assertEquals($no_support_types, PMA_unsupportedDatatypes());
+ }
+}
\ No newline at end of file
diff --git a/test/PMA_whichCrlf_test.php b/test/libraries/common/PMA_whichCrlf_test.php
similarity index 85%
rename from test/PMA_whichCrlf_test.php
rename to test/libraries/common/PMA_whichCrlf_test.php
index 244b548cd2..52d8323bbd 100644
--- a/test/PMA_whichCrlf_test.php
+++ b/test/libraries/common/PMA_whichCrlf_test.php
@@ -5,22 +5,14 @@
*
* @package phpMyAdmin-test
* @version $Id: PMA_whichCrlf_test.php
+ * @group common.lib-tests
*/
-/**
- * Tests core.
- */
-require_once 'PHPUnit/Framework.php';
-
-/**
+/*
* Include to test.
*/
-require_once './libraries/common.inc.php';
+require_once 'libraries/common.lib.php';
-/**
- * Test whichCrlf function.
- *
- */
class PMA_whichCrlf_test extends PHPUnit_Framework_TestCase
{
@@ -29,7 +21,6 @@ class PMA_whichCrlf_test extends PHPUnit_Framework_TestCase
* 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');
@@ -47,9 +38,10 @@ class PMA_whichCrlf_test extends PHPUnit_Framework_TestCase
} else {
- if ($runkit)
+ if ($runkit) {
define('PMA_USR_OS', 'Linux');
- $this->assertEquals("\n", PMA_whichCrlf());
+ $this->assertEquals("\n", PMA_whichCrlf());
+ }
if ($runkit)
runkit_constant_redefine('PMA_USR_OS', 'Win');
diff --git a/test/libraries/core/PMA_array_test.php b/test/libraries/core/PMA_array_test.php
new file mode 100644
index 0000000000..aae83324bc
--- /dev/null
+++ b/test/libraries/core/PMA_array_test.php
@@ -0,0 +1,231 @@
+ 1,
+ "str" => "str_val",
+ "arr" => array('val1', 'val2', 'val3'),
+ "sarr" => array('arr1' => array(1, 2, 3), array(3, array('a', 'b', 'c'), 4))
+ );
+
+ $this->assertEquals(PMA_array_read('int', $arr), $arr['int']);
+
+ $this->assertEquals(PMA_array_read('str', $arr), $arr['str']);
+
+ $this->assertEquals(PMA_array_read('arr/0', $arr), $arr['arr'][0]);
+
+ $this->assertEquals(PMA_array_read('arr/1', $arr), $arr['arr'][1]);
+
+ $this->assertEquals(PMA_array_read('arr/2', $arr), $arr['arr'][2]);
+
+ $this->assertEquals(PMA_array_read('sarr/arr1/0', $arr), $arr['sarr']['arr1'][0]);
+
+ $this->assertEquals(PMA_array_read('sarr/arr1/1', $arr), $arr['sarr']['arr1'][1]);
+
+ $this->assertEquals(PMA_array_read('sarr/arr1/2', $arr), $arr['sarr']['arr1'][2]);
+
+ $this->assertEquals(PMA_array_read('sarr/0/0', $arr), $arr['sarr'][0][0]);
+
+ $this->assertEquals(PMA_array_read('sarr/0/1', $arr), $arr['sarr'][0][1]);
+
+ $this->assertEquals(PMA_array_read('sarr/0/1/2', $arr), $arr['sarr'][0][1][2]);
+
+ $this->assertEquals(PMA_array_read('sarr/not_exiting/1', $arr), null);
+
+ $this->assertEquals(PMA_array_read('sarr/not_exiting/1', $arr, 0), 0);
+
+ $this->assertEquals(PMA_array_read('sarr/not_exiting/1', $arr, 'defailt_val'), 'defailt_val');
+ }
+
+ function testPMA_array_write()
+ {
+ $arr = array(
+ "int" => 1,
+ "str" => "str_val",
+ "arr" => array('val1', 'val2', 'val3'),
+ "sarr" => array('arr1' => array(1, 2, 3), array(3, array('a', 'b', 'c'), 4))
+ );
+
+ PMA_array_write('int', $arr, 5);
+ $this->assertEquals($arr['int'], 5);
+
+ PMA_array_write('str', $arr, '_str');
+ $this->assertEquals($arr['str'], '_str');
+
+ PMA_array_write('arr/0', $arr, 'val_arr_0');
+ $this->assertEquals($arr['arr'][0], 'val_arr_0');
+
+ PMA_array_write('arr/1', $arr, 'val_arr_1');
+ $this->assertEquals($arr['arr'][1], 'val_arr_1');
+
+ PMA_array_write('arr/2', $arr, 'val_arr_2');
+ $this->assertEquals($arr['arr'][2], 'val_arr_2');
+
+ PMA_array_write('sarr/arr1/0', $arr, 'val_sarr_arr_0');
+ $this->assertEquals($arr['sarr']['arr1'][0], 'val_sarr_arr_0');
+
+ PMA_array_write('sarr/arr1/1', $arr, 'val_sarr_arr_1');
+ $this->assertEquals($arr['sarr']['arr1'][1], 'val_sarr_arr_1');
+
+ PMA_array_write('sarr/arr1/2', $arr, 'val_sarr_arr_2');
+ $this->assertEquals($arr['sarr']['arr1'][2], 'val_sarr_arr_2');
+
+ PMA_array_write('sarr/0/0', $arr, 5);
+ $this->assertEquals($arr['sarr'][0][0], 5);
+
+ PMA_array_write('sarr/0/1/0', $arr, 'e');
+ $this->assertEquals($arr['sarr'][0][1][0], 'e');
+
+ PMA_array_write('sarr/not_existing/1', $arr, 'some_val');
+ $this->assertEquals($arr['sarr']['not_existing'][1], 'some_val');
+
+ PMA_array_write('sarr/0/2', $arr, NULL);
+ $this->assertNull($arr['sarr'][0][2]);
+ }
+
+ function testPMA_array_remove()
+ {
+ $arr = array(
+ "int" => 1,
+ "str" => "str_val",
+ "arr" => array('val1', 'val2', 'val3'),
+ "sarr" => array('arr1' => array(1, 2, 3), array(3, array('a', 'b', 'c'), 4))
+ );
+
+ PMA_array_remove('int', $arr);
+ $this->assertArrayNotHasKey('int', $arr);
+
+ PMA_array_remove('str', $arr);
+ $this->assertArrayNotHasKey('str', $arr);
+
+ PMA_array_remove('arr/0', $arr);
+ $this->assertArrayNotHasKey(0, $arr['arr']);
+
+ PMA_array_remove('arr/1', $arr);
+ $this->assertArrayNotHasKey(1, $arr['arr']);
+
+ PMA_array_remove('arr/2', $arr);
+ $this->assertArrayNotHasKey('arr', $arr);
+
+ $tmp_arr = $arr;
+ PMA_array_remove('sarr/not_existing/1', $arr);
+ $this->assertEquals($tmp_arr, $arr);
+
+ PMA_array_remove('sarr/arr1/0', $arr);
+ $this->assertArrayNotHasKey(0, $arr['sarr']['arr1']);
+
+ PMA_array_remove('sarr/arr1/1', $arr);
+ $this->assertArrayNotHasKey(1, $arr['sarr']['arr1']);
+
+ PMA_array_remove('sarr/arr1/2', $arr);
+ $this->assertArrayNotHasKey('arr1', $arr['sarr']);
+
+ PMA_array_remove('sarr/0/0', $arr);
+ $this->assertArrayNotHasKey(0, $arr['sarr'][0]);
+
+ PMA_array_remove('sarr/0/1/0', $arr);
+ $this->assertArrayNotHasKey(0, $arr['sarr'][0][1]);
+
+ PMA_array_remove('sarr/0/1/1', $arr);
+ $this->assertArrayNotHasKey(1, $arr['sarr'][0][1]);
+
+ PMA_array_remove('sarr/0/1/2', $arr);
+ $this->assertArrayNotHasKey(1, $arr['sarr'][0]);
+
+ PMA_array_remove('sarr/0/2', $arr);
+
+ $this->assertEmpty($arr);
+ }
+
+ function testPMA_array_merge_recursive()
+ {
+ $arr1 = array('key1' => 1, 'key2' => 2.3, 'key3' => 'str3');
+ $arr2 = array('key1' => 4, 'key2' => 5, 'key3' => 6);
+ $arr3 = array('key4' => 7, 'key5' => 'str8', 'key6' => 9);
+ $arr4 = array(1, 2, 3);
+
+ $this->assertFalse(PMA_array_merge_recursive());
+
+ $this->assertEquals(PMA_array_merge_recursive($arr1), $arr1);
+
+ $this->assertEquals(PMA_array_merge_recursive($arr1, 'str'), 'str');
+
+ $this->assertEquals(PMA_array_merge_recursive('str1', $arr2), $arr2);
+
+ $this->assertEquals(PMA_array_merge_recursive($arr1, $arr2), array('key1' => 4, 'key2' => 5, 'key3' => 6));
+
+ $this->assertEquals(PMA_array_merge_recursive($arr1, $arr3), array('key1' => 1, 'key2' => 2.3, 'key3' => 'str3', 'key4' => 7, 'key5' => 'str8', 'key6' => 9));
+
+ $this->assertEquals(PMA_array_merge_recursive($arr2, $arr4), array(1, 2, 3));
+
+ $this->assertEquals(PMA_array_merge_recursive($arr1, $arr2, $arr3), array('key1' => 4, 'key2' => 5, 'key3' => 6, 'key4' => 7, 'key5' => 'str8', 'key6' => 9));
+ }
+
+
+ function testPMA_arrayWalkRecursive()
+ {
+ function fConcat($var)
+ {
+ return 'val: ' . $var . ' processed';
+ }
+
+ $arr = array(1, 2, 3, 4);
+ $target = array('val: 1 processed','val: 2 processed','val: 3 processed','val: 4 processed');
+
+ PMA_arrayWalkRecursive($arr, 'fConcat');
+ $this->assertEquals($arr, $target);
+ }
+
+ /**
+ * @depends testPMA_arrayWalkRecursive
+ */
+ function testPMA_arrayWalkRecursiveNotProcessIntKeys()
+ {
+ function fAdd($var)
+ {
+ return ++$var;
+ }
+
+ $arr = array(1, 2, 3, 4);
+ $target = array(2, 3, 4, 5);
+
+ PMA_arrayWalkRecursive($arr, 'fAdd', true);
+ $this->assertEquals($arr, $target);
+ }
+
+ /**
+ * @depends testPMA_arrayWalkRecursiveNotProcessIntKeys
+ */
+ function testPMA_arrayWalkRecursiveSubArray()
+ {
+ $arr = array("key1"=>'val1', 'key2'=>array('skey1'=>'sval1','skey2'=>'sval2'),'key3'=>'val3');
+ $target = array('key1'=>'val: val1 processed', 'key2'=> array('skey1'=>'val: sval1 processed', 'skey2'=>'val: sval2 processed'),'key3'=>'val: val3 processed');
+
+ PMA_arrayWalkRecursive($arr, 'fConcat');
+ $this->assertEquals($arr, $target);
+ }
+
+ function testPMA_arrayWalkRecursiveApplyToKeysStripSlashes()
+ {
+ $arr = array("key\\1"=>'v\\\\al1', 'k\\ey2'=>array('s\\\\key1'=>'sval\\1','s\\k\\ey2'=>'s\\v\\al2'),'key3'=>'val3');
+ $target = array("key1"=>'val1', 'key2'=>array('skey1'=>'sval1','skey2'=>'sval2'),'key3'=>'val3');
+
+ PMA_arrayWalkRecursive($arr, 'stripslashes',true);
+ $this->assertEquals($arr, $target);
+ }
+}
\ No newline at end of file
diff --git a/test/libraries/core/PMA_checkPageValidity_test.php b/test/libraries/core/PMA_checkPageValidity_test.php
new file mode 100644
index 0000000000..ebc174d5fd
--- /dev/null
+++ b/test/libraries/core/PMA_checkPageValidity_test.php
@@ -0,0 +1,66 @@
+assertFalse(PMA_checkPageValidity($page,null));
+ }
+
+ function testGotoWhitelist(){
+ $page = 'export.php';
+
+ $this->assertTrue(PMA_checkPageValidity($page,$this->goto_whitelist));
+ }
+
+ function testGotoNotInWhitelist(){
+ $page = 'shell.php';
+
+ $this->assertFalse(PMA_checkPageValidity($page,$this->goto_whitelist));
+ }
+
+ function testGotoWhitelistPage(){
+ $page = 'main.php?sql.php&test=true';
+
+ $this->assertTrue(PMA_checkPageValidity($page,$this->goto_whitelist));
+ }
+
+ function testGotoWhitelistEncodedPage(){
+ $page = 'main.php%3Fsql.php%26test%3Dtrue';
+
+ $this->assertTrue(PMA_checkPageValidity($page,$this->goto_whitelist));
+ }
+
+}
\ No newline at end of file
diff --git a/test/libraries/core/PMA_fatalError_test.php b/test/libraries/core/PMA_fatalError_test.php
new file mode 100644
index 0000000000..643c4d9005
--- /dev/null
+++ b/test/libraries/core/PMA_fatalError_test.php
@@ -0,0 +1,43 @@
+expectOutputRegex("/FatalError!/");
+ PMA_fatalError("FatalError!");
+ }
+
+ public function testFatalErrorMessageWithArgs()
+ {
+ $message = "Fatal error #%d in file %s.";
+ $params = array(1, 'error_file.php');
+
+ $this->expectOutputRegex("/Fatal error #1 in file error_file.php./", "Not EQ");
+ PMA_fatalError($message, $params);
+
+ $message = "Fatal error in file %s.";
+ $params = 'error_file.php';
+
+ $this->expectOutputRegex("/Fatal error in file error_file.php./");
+ PMA_fatalError($message, $params);
+ }
+
+}
\ No newline at end of file
diff --git a/test/libraries/core/PMA_getLinks_test.php b/test/libraries/core/PMA_getLinks_test.php
new file mode 100644
index 0000000000..59aac3e240
--- /dev/null
+++ b/test/libraries/core/PMA_getLinks_test.php
@@ -0,0 +1,59 @@
+assertEquals(PMA_getPHPDocLink('function'), 'http://php.net/manual/' . $lang . '/function');
+ }
+
+ public function providerLinkURL(){
+ return array(
+ array('http://wiki.phpmyadmin.net', './url.php?url=http%3A%2F%2Fwiki.phpmyadmin.net&lang=en'),
+ array('https://wiki.phpmyadmin.net', './url.php?url=https%3A%2F%2Fwiki.phpmyadmin.net&lang=en'),
+ array('wiki.phpmyadmin.net', 'wiki.phpmyadmin.net'),
+ array('index.php?db=phpmyadmin', 'index.php?db=phpmyadmin')
+ );
+ }
+
+ /**
+ * @dataProvider providerLinkURL
+ */
+ public function testPMA_linkURL($link, $url){
+ $this->assertEquals(PMA_linkURL($link), $url);
+ }
+
+ public function testPMA_includeJS()
+ {
+ $filename = "common.js";
+ $mod = 0;
+
+ if (file_exists('./js/'.$filename)) {
+ $mod = filemtime('./js/'.$filename);
+ }
+ else{
+ $this->fail("JS file doesn't exists.");
+ }
+ $this->assertEquals(PMA_includeJS($filename), ''. "\n");
+
+ $filename = '?file.js';
+ //$this->assertEquals(PMA_includeJS($filename), '\n');
+ $this->assertEquals(PMA_includeJS($filename), ''."\n");
+
+ //$this->assertFalse(PMA_includeJS(null));
+ }
+
+}
diff --git a/test/libraries/core/PMA_getTableCount_test_dis.php b/test/libraries/core/PMA_getTableCount_test_dis.php
new file mode 100644
index 0000000000..7910377bfb
--- /dev/null
+++ b/test/libraries/core/PMA_getTableCount_test_dis.php
@@ -0,0 +1,37 @@
+assertEquals(5,PMA_getTableCount('meddb'));
+ $this->assertTrue(true);
+ }
+}
diff --git a/test/PMA_get_real_size_test.php b/test/libraries/core/PMA_get_real_size_test.php
similarity index 75%
rename from test/PMA_get_real_size_test.php
rename to test/libraries/core/PMA_get_real_size_test.php
index 14d2a61fee..894e22c9eb 100644
--- a/test/PMA_get_real_size_test.php
+++ b/test/libraries/core/PMA_get_real_size_test.php
@@ -1,20 +1,16 @@
assertEquals(12 * 1024 * 1024 * 1024, PMA_get_real_size('12gb'));
}
+
+ public function testUnspecified()
+ {
+ $this->assertEquals(1024, PMA_get_real_size('1024'));
+ }
}
?>
diff --git a/test/PMA_headerLocation_test.php b/test/libraries/core/PMA_headerLocation_test_disabled.php
similarity index 95%
rename from test/PMA_headerLocation_test.php
rename to test/libraries/core/PMA_headerLocation_test_disabled.php
index daad6897c9..b2f522db3b 100644
--- a/test/PMA_headerLocation_test.php
+++ b/test/libraries/core/PMA_headerLocation_test_disabled.php
@@ -3,21 +3,16 @@
/**
* Test for PMA_sendHeaderLocation
*
+ * @package phpMyAdmin-test
*/
-/**
- * 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';
-require_once './libraries/select_lang.lib.php';
+require_once 'libraries/common.lib.php';
+require_once 'libraries/url_generating.lib.php';
+require_once 'libraries/core.lib.php';
+require_once 'libraries/select_lang.lib.php';
/**
* Test function sending headers.
@@ -40,8 +35,6 @@ class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
protected $runkitExt;
protected $apdExt;
-
-
public function __construct()
{
parent::__construct();
@@ -102,6 +95,8 @@ class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
public function setUp()
{
+ //session_start();
+
// cleaning constants
if ($this->runkitExt) {
@@ -132,6 +127,8 @@ class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
public function tearDown()
{
+ //session_destroy();
+
// cleaning constants
if ($this->runkitExt) {
@@ -264,7 +261,7 @@ class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
"\n" .
"\n";
@@ -283,7 +280,7 @@ class PMA_headerLocation_test extends PHPUnit_Extensions_OutputTestCase
$GLOBALS['reload'] = true;
$GLOBALS['db'] = 'test_db';
- $url = './navigation.php?db='.$GLOBALS['db'] . '&lang=en-utf-8&convcharset=utf-8';
+ $url = './navigation.php?'.PMA_generate_common_url($GLOBALS['db'], '', '&');
$write = PHP_EOL . '