diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php
index a2226ea4c4..d56d9e52c0 100644
--- a/libraries/insert_edit.lib.php
+++ b/libraries/insert_edit.lib.php
@@ -1552,9 +1552,9 @@ function PMA_getSumbitAndResetButtonForActionsPanel($tabindex, $tabindex_for_val
. ''
. '
'
. ''
+ . ' tabindex="' . ($tabindex + $tabindex_for_value + 6) . '" id="buttonYes" />'
. ''
+ . ' tabindex="' . ($tabindex + $tabindex_for_value + 7) . '" />'
. ' | ';
}
@@ -1613,6 +1613,7 @@ function PMA_getSpecialCharsAndBackupFieldForExistingRow(
$real_null_value, $gis_data_types, $column_name_appendix
) {
$special_chars_encoded = '';
+ $data = null;
// (we are editing)
if (is_null($current_row[$column['Field']])) {
$real_null_value = true;
@@ -1775,8 +1776,10 @@ function PMA_isInsertRow()
$header = $response->getHeader();
$scripts = $header->getScripts();
$scripts->addFile('tbl_change.js');
- include 'tbl_change.php';
- exit;
+ if (!defined('TESTSUITE')) {
+ include 'tbl_change.php';
+ exit;
+ }
}
}
diff --git a/test/libraries/PMA_insert_edit_test.php b/test/libraries/PMA_insert_edit_test.php
new file mode 100644
index 0000000000..97c20e7991
--- /dev/null
+++ b/test/libraries/PMA_insert_edit_test.php
@@ -0,0 +1,2731 @@
+ 'bar ', '1' => ' test');
+ $_REQUEST['clause_is_unique'] = false;
+ $_REQUEST['sql_query'] = 'SELECT a';
+ $GLOBALS['goto'] = 'index.php';
+
+ $result = PMA_getFormParametersForInsertForm(
+ 'dbname', 'tablename', false, $where_clause, 'localhost'
+ );
+
+ $this->assertEquals(
+ array(
+ 'db' => 'dbname',
+ 'table' => 'tablename',
+ 'goto' => 'index.php',
+ 'err_url' => 'localhost',
+ 'sql_query' => 'SELECT a',
+ 'where_clause[foo]' => 'bar',
+ 'where_clause[1]' => 'test',
+ 'clause_is_unique' => false
+ ),
+ $result
+ );
+ }
+
+ /**
+ * Test for PMA_getWhereClauseArray
+ *
+ * @return void
+ */
+ public function testGetWhereClauseArray()
+ {
+ $this->assertNull(
+ PMA_getWhereClauseArray(null)
+ );
+
+ $this->assertEquals(
+ array(1, 2, 3),
+ PMA_getWhereClauseArray(array(1, 2, 3))
+ );
+
+ $this->assertEquals(
+ array('clause'),
+ PMA_getWhereClauseArray('clause')
+ );
+ }
+
+ /**
+ * Test for PMA_analyzeWhereClauses
+ *
+ * @return void
+ */
+ public function testAnalyzeWhereClause()
+ {
+ $clauses = array('a=1', 'b="fo\o"');
+
+ $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $dbi->expects($this->at(0))
+ ->method('query')
+ ->with(
+ 'SELECT * FROM `db`.`table` WHERE a=1;',
+ null,
+ PMA_DatabaseInterface::QUERY_STORE
+ )
+ ->will($this->returnValue('result1'));
+
+ $dbi->expects($this->at(3))
+ ->method('query')
+ ->with(
+ 'SELECT * FROM `db`.`table` WHERE b="fo\o";',
+ null,
+ PMA_DatabaseInterface::QUERY_STORE
+ )
+ ->will($this->returnValue('result2'));
+
+ $dbi->expects($this->at(1))
+ ->method('fetchAssoc')
+ ->with('result1')
+ ->will($this->returnValue(array('assoc1')));
+
+ $dbi->expects($this->at(4))
+ ->method('fetchAssoc')
+ ->with('result2')
+ ->will($this->returnValue(array('assoc2')));
+
+ $GLOBALS['dbi'] = $dbi;
+ $result = PMA_analyzeWhereClauses($clauses, 'table', 'db');
+
+ $this->assertEquals(
+ array(
+ array('a=1', 'b="fo\\\\o"'),
+ array('result1', 'result2'),
+ array(
+ array('assoc1'),
+ array('assoc2')
+ ),
+ ''
+ ),
+ $result
+ );
+ }
+
+ /**
+ * Test for PMA_showEmptyResultMessageOrSetUniqueCondition
+ *
+ * @return void
+ */
+ public function testShowEmptyResultMessageOrSetUniqueCondition()
+ {
+ $temp = new stdClass;
+ $temp->orgname = 'orgname';
+ $temp->table = 'table';
+ $temp->type = 'real';
+ $temp->primary_key = 1;
+ $meta_arr = array($temp);
+
+ $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $dbi->expects($this->at(0))
+ ->method('getFieldsMeta')
+ ->with('result1')
+ ->will($this->returnValue($meta_arr));
+
+ $GLOBALS['dbi'] = $dbi;
+
+ $result = PMA_showEmptyResultMessageOrSetUniqueCondition(
+ array('1' => array('1' => 1)), 1, array(),
+ 'SELECT', array('1' => 'result1')
+ );
+
+ $this->assertTrue($result);
+
+ // case 2
+ $GLOBALS['cfg']['ShowSQL'] = false;
+
+ $responseMock = $this->getMockBuilder('PMA_Response')
+ ->disableOriginalConstructor()
+ ->setMethods(array('addHtml'))
+ ->getMock();
+
+ $response = new ReflectionProperty('PMA_Response', '_instance');
+ $response->setAccessible(true);
+ $response->setValue(null, $responseMock);
+
+ $result = PMA_showEmptyResultMessageOrSetUniqueCondition(
+ array(false), 0, array('1'), 'SELECT', array('1' => 'result1')
+ );
+
+ $this->assertFalse($result);
+ }
+
+ /**
+ * Test for PMA_loadFirstRow
+ *
+ * @return void
+ */
+ public function testLoadFirstRow()
+ {
+ $GLOBALS['cfg']['InsertRows'] = 2;
+
+ $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $dbi->expects($this->at(0))
+ ->method('query')
+ ->with(
+ 'SELECT * FROM `db`.`table` LIMIT 1;',
+ null,
+ PMA_DatabaseInterface::QUERY_STORE
+ )
+ ->will($this->returnValue('result1'));
+
+ $GLOBALS['dbi'] = $dbi;
+
+ $result = PMA_loadFirstRow('table', 'db');
+
+ $this->assertEquals(
+ array('result1', array(false, false)),
+ $result
+ );
+ }
+
+ /**
+ * Test for PMA_urlParamsInEditMode
+ *
+ * @return void
+ */
+ public function testUrlParamsInEditMode()
+ {
+ $where_clause_array = array('foo=1', 'bar=2');
+ $_REQUEST['sql_query'] = 'SELECT 1';
+
+ $result = PMA_urlParamsInEditMode(array(1), $where_clause_array, true);
+
+ $this->assertEquals(
+ array(
+ '0' => 1,
+ 'where_clause' => 'bar=2',
+ 'sql_query' => 'SELECT 1'
+ ),
+ $result
+ );
+ }
+
+ /**
+ * Test for PMA_showFunctionFieldsInEditMode
+ *
+ * @return void
+ */
+ public function testShowFunctionFieldsInEditMode()
+ {
+ $GLOBALS['cfg']['ShowFieldTypesInDataEditView'] = true;
+ $GLOBALS['cfg']['ServerDefault'] = 1;
+ $url_params = array('ShowFunctionFields' => 2);
+
+ $result = PMA_showFunctionFieldsInEditMode($url_params, false);
+
+ $this->assertEquals(
+ ' : '
+ . 'Function' . "\n",
+ $result
+ );
+
+ // case 2
+ $result = PMA_showFunctionFieldsInEditMode($url_params, true);
+
+ $this->assertEquals(
+ 'Function | ' . "\n",
+ $result
+ );
+ }
+
+ /**
+ * Test for PMA_showColumnTypesInDataEditView
+ *
+ * @return void
+ */
+ public function testShowColumnTypesInDataEditView()
+ {
+ $GLOBALS['cfg']['ShowFieldTypesInDataEditView'] = true;
+ $GLOBALS['cfg']['ShowFunctionFields'] = true;
+ $GLOBALS['cfg']['ServerDefault'] = 1;
+ $url_params = array('ShowFunctionFields' => 2);
+
+ $result = PMA_showColumnTypesInDataEditView($url_params, false);
+
+ $this->assertEquals(
+ ' : '
+ . 'Type' . "\n",
+ $result
+ );
+
+ // case 2
+ $result = PMA_showColumnTypesInDataEditView($url_params, true);
+
+ $this->assertEquals(
+ 'Type | ' . "\n",
+ $result
+ );
+ }
+
+ /**
+ * Test for PMA_getDefaultForDatetime
+ *
+ * @return void
+ */
+ public function testGetDefaultForDatetime()
+ {
+ $column['Type'] = 'datetime';
+ $column['Null'] = 'YES';
+
+ $this->assertNull(
+ PMA_getDefaultForDatetime($column) //should be passed as reference?
+ );
+ }
+
+ /**
+ * Test for PMA_analyzeTableColumnsArray
+ *
+ * @return void
+ */
+ public function testAnalyzeTableColumnsArray()
+ {
+ $column = array(
+ 'Field' => '1<2',
+ 'Field_md5' => 'pswd',
+ 'Type' => 'float(10, 1)'
+ );
+
+ $result = PMA_analyzeTableColumnsArray(
+ $column, array(), false
+ );
+
+ $this->assertEquals(
+ $result['Field_html'],
+ '1<2'
+ );
+
+ $this->assertEquals(
+ $result['Field_md5'],
+ '4342210df36bf2ff2c4e2a997a6d4089'
+ );
+
+ $this->assertEquals(
+ $result['True_Type'],
+ 'float'
+ );
+
+ $this->assertEquals(
+ $result['len'],
+ 100
+ );
+
+ $this->assertEquals(
+ $result['Field_title'],
+ '1<2'
+ );
+
+ $this->assertEquals(
+ $result['is_binary'],
+ false
+ );
+
+ $this->assertEquals(
+ $result['is_blob'],
+ false
+ );
+
+ $this->assertEquals(
+ $result['is_char'],
+ false
+ );
+
+ $this->assertEquals(
+ $result['pma_type'],
+ 'float(10, 1)'
+ );
+
+ $this->assertEquals(
+ $result['wrap'],
+ ' nowrap'
+ );
+
+ $this->assertEquals(
+ $result['Field'],
+ '1<2'
+ );
+ }
+
+ /**
+ * Test for PMA_getColumnTitle
+ *
+ * @return void
+ */
+ public function testGetColumnTitle()
+ {
+ $column['Field'] = 'f1<';
+ $column['Field_html'] = 'f1<';
+
+ $this->assertEquals(
+ PMA_getColumnTitle($column, array()),
+ 'f1<'
+ );
+
+ $comments['f1<'] = 'comment>';
+
+ $result = PMA_getColumnTitle($column, $comments);
+
+ $this->assertContains(
+ 'title="comment>"',
+ $result
+ );
+
+ $this->assertContains(
+ 'f1<',
+ $result
+ );
+ }
+
+ /**
+ * Test for PMA_isColumnBinary
+ *
+ * @return void
+ */
+ public function testIsColumnBinary()
+ {
+ $column['Type'] = 'binaryfoo';
+ $this->assertEquals('binaryfoo', PMA_isColumnBinary($column));
+
+ $column['Type'] = 'Binaryfoo';
+ $this->assertEquals('Binaryfoo', PMA_isColumnBinary($column));
+
+ $column['Type'] = 'varbinaryfoo';
+ $this->assertEquals('binaryfoo', PMA_isColumnBinary($column));
+
+ $column['Type'] = 'barbinaryfoo';
+ $this->assertFalse(PMA_isColumnBinary($column));
+ }
+
+ /**
+ * Test for PMA_isColumnBlob
+ *
+ * @return void
+ */
+ public function testIsColumnBlog()
+ {
+ $column['Type'] = 'blob';
+ $this->assertEquals('blob', PMA_isColumnBlob($column));
+
+ $column['Type'] = 'bloB';
+ $this->assertEquals('bloB', PMA_isColumnBlob($column));
+
+ $column['Type'] = 'mediumBloB';
+ $this->assertEquals('BloB', PMA_isColumnBlob($column));
+
+ $column['Type'] = 'tinyblobabc';
+ $this->assertEquals('blobabc', PMA_isColumnBlob($column));
+
+ $column['Type'] = 'longblob';
+ $this->assertEquals('blob', PMA_isColumnBlob($column));
+
+ $column['Type'] = 'foolongblobbar';
+ $this->assertFalse(PMA_isColumnBlob($column));
+ }
+
+ /**
+ * Test for PMA_iscolumnchar
+ *
+ * @return void
+ */
+ public function testIsColumnChar()
+ {
+ $column['Type'] = 'char(10)';
+ $this->assertEquals('char(10)', PMA_iscolumnchar($column));
+
+ $column['Type'] = 'VarChar(20)';
+ $this->assertEquals('Char(20)', PMA_iscolumnchar($column));
+
+ $column['Type'] = 'foochar';
+ $this->assertFalse(PMA_iscolumnchar($column));
+ }
+
+ /**
+ * Test for PMA_getEnumSetAndTimestampColumns
+ *
+ * @return void
+ */
+ public function testGetEnumAndTimestampColumns()
+ {
+ $column['True_Type'] = 'set';
+ $this->assertEquals(
+ array('set', '', false),
+ PMA_getEnumSetAndTimestampColumns($column, false)
+ );
+
+ $column['True_Type'] = 'enum';
+ $this->assertEquals(
+ array('enum', '', false),
+ PMA_getEnumSetAndTimestampColumns($column, false)
+ );
+
+ $column['True_Type'] = 'timestamp';
+ $column['Type'] = 'date';
+ $this->assertEquals(
+ array('date', ' nowrap', true),
+ PMA_getEnumSetAndTimestampColumns($column, false)
+ );
+
+ $column['True_Type'] = 'timestamp';
+ $column['Type'] = 'date';
+ $this->assertEquals(
+ array('date', ' nowrap', false),
+ PMA_getEnumSetAndTimestampColumns($column, true)
+ );
+
+ $column['True_Type'] = 'SET';
+ $column['Type'] = 'num';
+ $this->assertEquals(
+ array('num', ' nowrap', false),
+ PMA_getEnumSetAndTimestampColumns($column, false)
+ );
+
+ $column['True_Type'] = '';
+ $column['Type'] = 'num';
+ $this->assertEquals(
+ array('num', ' nowrap', false),
+ PMA_getEnumSetAndTimestampColumns($column, false)
+ );
+ }
+
+ /**
+ * Test for PMA_getFunctionColumn
+ *
+ * @return void
+ */
+ public function testGetFunctionColumn()
+ {
+ $GLOBALS['cfg']['ProtectBinary'] = true;
+ $column['is_blob'] = true;
+ $this->assertTag(
+ PMA_getTagArray('', array('content' => 'Binary')),
+ PMA_getFunctionColumn($column, false, '', '', '', '', '', '', '')
+ );
+
+ $GLOBALS['cfg']['ProtectBinary'] = 'all';
+ $column['is_binary'] = true;
+ $this->assertTag(
+ PMA_getTagArray(' | ', array('content' => 'Binary')),
+ PMA_getFunctionColumn($column, true, '', '', '', '', '', '', '')
+ );
+
+ $GLOBALS['cfg']['ProtectBinary'] = 'noblob';
+ $column['is_blob'] = false;
+ $this->assertTag(
+ PMA_getTagArray(' | ', array('content' => 'Binary')),
+ PMA_getFunctionColumn($column, true, '', '', '', '', '', '', '')
+ );
+
+ $GLOBALS['cfg']['ProtectBinary'] = false;
+ $column['True_Type'] = 'enum';
+ $this->assertTag(
+ PMA_getTagArray(' | ', array('content' => '--')),
+ PMA_getFunctionColumn($column, true, '', '', '', '', '', '', '')
+ );
+
+ $column['True_Type'] = 'set';
+ $this->assertTag(
+ PMA_getTagArray(' | ', array('content' => '--')),
+ PMA_getFunctionColumn($column, true, '', '', '', '', '', '', '')
+ );
+
+ $column['True_Type'] = '';
+ $column['pma_type'] = 'int';
+ $this->assertTag(
+ PMA_getTagArray(' | ', array('content' => '--')),
+ PMA_getFunctionColumn(
+ $column, true, '', '', array('int'), '', '', '', ''
+ )
+ );
+
+ $GLOBALS['PMA_Types'] = new PMA_Types;
+ $column['Field'] = 'num';
+ $this->assertContains(
+ ' |