diff --git a/libraries/DatabaseInterface.class.php b/libraries/DatabaseInterface.class.php index be2f84ef99..d8399ad3be 100644 --- a/libraries/DatabaseInterface.class.php +++ b/libraries/DatabaseInterface.class.php @@ -11,6 +11,7 @@ if (! defined('PHPMYADMIN')) { require_once './libraries/logging.lib.php'; require_once './libraries/Index.class.php'; +require_once './libraries/SystemDatabase.class.php'; /** * Main interface for database interactions @@ -46,7 +47,7 @@ class PMA_DatabaseInterface * * @param PMA_DBI_Extension $ext Object to be used for database queries */ - public function __construct(PMA_DBI_Extension $ext) + function __construct($ext) { $this->_extension = $ext; } @@ -1149,6 +1150,50 @@ class PMA_DatabaseInterface ); } // end of the '_usortComparisonCallback()' method + /** + * returns detailed array with all columns for sql + * + * @param string $sql_query target SQL query to get columns + * @param array $view_columns alias for columns + * + * @return array + */ + public function getColumnMapFromSql($sql_query, $view_columns = array()) + { + $result = $this->tryQuery($sql_query); + + if ($result === false) { + return array(); + } + + $meta = $this->getFieldsMeta( + $result + ); + + $nbFields = count($meta); + if ($nbFields <= 0) { + return array(); + } + + $column_map = array(); + $nbColumns = count($view_columns); + + for ($i=0; $i < $nbFields; $i++) { + + $map = array(); + $map['table_name'] = $meta[$i]->table; + $map['refering_column'] = $meta[$i]->name; + + if ($nbColumns > 1) { + $map['real_column'] = $view_columns[$i]; + } + + $column_map[] = $map; + } + + return $column_map; + } + /** * returns detailed array with all columns for given table in database, * or all tables/databases @@ -2862,5 +2907,15 @@ class PMA_DatabaseInterface return 'KILL ' . $process . ';'; } } + + /** + * Get the phpmyadmin database manager + * + * @return PMA\SystemDatabase + */ + public function getSystemDatabase() + { + return new PMA\SystemDatabase($this); + } } ?> diff --git a/libraries/SystemDatabase.class.php b/libraries/SystemDatabase.class.php new file mode 100644 index 0000000000..59a8028dd3 --- /dev/null +++ b/libraries/SystemDatabase.class.php @@ -0,0 +1,119 @@ +_dbi = $dbi; + } + + /** + * Get existing data on transformations applied for + * columns in a particular table + * + * @param string $db Database name looking for + * + * @return \mysqli_result Result of executed SQL query + */ + public function getExistingTransformationData($db) + { + $cfgRelation = \PMA_getRelationsParam(); + + // Get the existing transformation details of the same database + // from pma__column_info table + $pma_transformation_sql = sprintf( + "SELECT * FROM %s.%s WHERE `db_name` = '%s'", + \PMA_Util::backquote($cfgRelation['db']), + \PMA_Util::backquote($cfgRelation['column_info']), + \PMA_Util::sqlAddSlashes($db) + ); + + return $this->_dbi->tryQuery($pma_transformation_sql); + } + + /** + * Get SQL query for store new transformation details of a VIEW + * + * @param object $pma_transformation_data Result set of SQL execution + * @param array $column_map Details of VIEW columns + * @param string $view_name Name of the VIEW + * @param string $db Database name of the VIEW + * + * @return string $new_transformations_sql SQL query for new transformations + */ + function getNewTransformationDataSql( + $pma_transformation_data, $column_map, $view_name, $db + ) { + $cfgRelation = \PMA_getRelationsParam(); + + // Need to store new transformation details for VIEW + $new_transformations_sql = sprintf( + "INSERT INTO %s.%s (" + . "`db_name`, `table_name`, `column_name`, " + . "`comment`, `mimetype`, `transformation`, " + . "`transformation_options`) VALUES", + \PMA_Util::backquote($cfgRelation['db']), + \PMA_Util::backquote($cfgRelation['column_info']) + ); + + $column_count = 0; + $add_comma = false; + + while ($data_row = $this->_dbi->fetchAssoc($pma_transformation_data)) { + + foreach ($column_map as $column) { + + if ($data_row['table_name'] != $column['table_name'] + || $data_row['column_name'] != $column['refering_column'] + ) { + continue; + } + + $new_transformations_sql .= sprintf( + "%s ('%s', '%s', '%s', '%s', '%s', '%s', '%s')", + $add_comma ? ', ' : '', + $db, + $view_name, + isset($column['real_column']) + ? $column['real_column'] + : $column['refering_column'], + $data_row['comment'], + $data_row['mimetype'], + $data_row['transformation'], + \PMA_Util::sqlAddSlashes( + $data_row['transformation_options'] + ) + ); + + $add_comma = true; + $column_count++; + break; + } + + if ($column_count == count($column_map)) { + break; + } + } + + return ($column_count > 0) ? $new_transformations_sql : ''; + } +} diff --git a/libraries/Template.class.php b/libraries/Template.class.php new file mode 100644 index 0000000000..bbf618830d --- /dev/null +++ b/libraries/Template.class.php @@ -0,0 +1,44 @@ +name = $name; + } + + public static function get($name) + { + return new Template($name); + } + + public function render($data = array()) + { + $template = static::BASE_PATH . $this->name . '.php'; + try { + extract($data); + ob_start(); + if (file_exists($template)) { + include $template; + } else { + throw new \LogicException( + 'The template "' . $template . '" not found.' + ); + } + $content = ob_get_clean(); + return $content; + } catch (\LogicException $e) { + ob_end_clean(); + throw new \LogicException($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/libraries/tbl_chart.lib.php b/libraries/tbl_chart.lib.php index 8862b33859..b7989a4c62 100644 --- a/libraries/tbl_chart.lib.php +++ b/libraries/tbl_chart.lib.php @@ -12,285 +12,8 @@ if (! defined('PHPMYADMIN')) { exit; } -/** - * Function to get html for pma_token and url_query - * - * @param string $url_query url query - * - * @return string - */ -function PMA_getHtmlForPmaTokenAndUrlQuery($url_query) -{ - $htmlString = ''; - return $htmlString; -} - -/** - * Function to get html for the chart type options - * - * @return string - */ -function PMA_getHtmlForChartTypeOptions() -{ - $html = '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '' - . '

'; - - return $html; -} - -/** - * Function to get html for the bar stacked option - * - * @return string - */ -function PMA_getHtmlForStackedOption() -{ - $html = '' - . '

'; - - return $html; -} - -/** - * Function to get html for the chart x axis options - * - * @param array $keys keys - * @param int &$xaxis x axis - * - * @return string - */ -function PMA_getHtmlForChartXAxisOptions($keys, &$xaxis) -{ - $htmlString = '
' - . '' - . ''; - - return $htmlString; -} - -/** - * Function to get html for chart series options - * - * @param array $keys keys - * @param array $fields_meta fields meta - * @param array $numeric_types numeric types - * @param int $xaxis x axis - * @param int $numeric_column_count numeric column count - * - * @return string - */ -function PMA_getHtmlForChartSeriesOptions($keys, $fields_meta, $numeric_types, - $xaxis, $numeric_column_count -) { - $htmlString = '
' - . '' - . ''; - return $htmlString; -} - -/** - * Function to get html for date time columns - * - * @param array $keys keys - * @param array $fields_meta fields meta - * - * @return string - */ -function PMA_getHtmlForDateTimeCols($keys, $fields_meta) -{ - $htmlString = ' $key) { - if (in_array($fields_meta[$idx]->type, $numeric_types)) { - $htmlString .= $idx . " "; - } - } - $htmlString .= '" />'; - - return $htmlString; -} - -/** - * Function to get html for the table axis label options - * - * @param int $xaxis x axis - * @param array $keys keys - * - * @return string - */ -function PMA_getHtmlForTableAxisLabelOptions($xaxis, $keys) -{ - $htmlString = '
' - . '' - . '
' - . '' - . '
' - . '
'; - - return $htmlString; -} - -/** - * Function to get html for switching to alternative data format - * - * @param array $keys keys - * @param array $fields_meta fields meta - * @param array $numeric_types numeric types - * @param int $xaxis x axis - * - * @return string - */ -function PMA_getHtmlForAlternativeDataFormat($keys, $fields_meta, $numeric_types, - $xaxis -) { - $htmlString = '

 

' - . '
' - . __('Series names are in a column') . ''; - - $htmlString .= '
' - . '' - . ''; - - $htmlString .= '' - . '
'; - return $htmlString; -} - -/** - * Function to get html for the chart area div - * - * @return string - */ -function PMA_getHtmlForChartAreaDiv() -{ - $htmlString = '

 

' - . '
' - . '
' - . PMA_Util::getImage('b_saveimage', __('Save chart as image')) - . '
' - . '
' - . '
' - . '
'; - - return $htmlString; -} +require_once 'libraries/Template.class.php'; +use PMA\Template; /** * Function to get html for displaying table chart @@ -308,44 +31,13 @@ function PMA_getHtmlForChartAreaDiv() function PMA_getHtmlForTableChartDisplay($url_query, $url_params, $keys, $fields_meta, $numeric_types, $numeric_column_count, $sql_query ) { - // pma_token/url_query needed for chart export - $htmlString = PMA_getHtmlForPmaTokenAndUrlQuery($url_query); - $htmlString .= '' - . '
' - . '
' - . PMA_URL_getHiddenInputs($url_params) - . '
' - . '' . __('Display chart') . '' - . '
'; - $htmlString .= PMA_getHtmlForChartTypeOptions(); - $htmlString .= PMA_getHtmlForStackedOption(); - - $htmlString .= '' - . '
'; - $xaxis = null; - $htmlString .= PMA_getHtmlForChartXAxisOptions($keys, $xaxis); - $htmlString .= PMA_getHtmlForChartSeriesOptions( - $keys, $fields_meta, $numeric_types, $xaxis, $numeric_column_count - ); - $htmlString .= PMA_getHtmlForDateTimeCols($keys, $fields_meta); - $htmlString .= PMA_getHtmlForNumericCols($keys, $fields_meta, $numeric_types); - $htmlString .= '
'; - - $htmlString .= PMA_getHtmlForTableAxisLabelOptions($xaxis, $keys); - $htmlString .= PMA_getHtmlForAlternativeDataFormat( - $keys, $fields_meta, $numeric_types, $xaxis - ); - $htmlString .= PMA_Util::getStartAndNumberOfRowsPanel($sql_query); - - $htmlString .= PMA_getHtmlForChartAreaDiv(); - - $htmlString .= '' - . '' - . '
'; - - return $htmlString; + return Template::get('tbl_chart')->render(array( + 'url_query' => $url_query, + 'url_params' => $url_params, + 'keys' => $keys, + 'fields_meta' => $fields_meta, + 'numeric_types' => $numeric_types, + 'numeric_column_count' => $numeric_column_count, + 'sql_query' => $sql_query + )); } -?> diff --git a/libraries/tbl_views.lib.php b/libraries/tbl_views.lib.php deleted file mode 100644 index faee2f85d8..0000000000 --- a/libraries/tbl_views.lib.php +++ /dev/null @@ -1,161 +0,0 @@ -tryQuery($sql_query); - - if ($real_source_result !== false) { - - $real_source_fields_meta = $GLOBALS['dbi']->getFieldsMeta( - $real_source_result - ); - - $nbColumns = count($view_columns); - $nbFields = count($real_source_fields_meta); - if ($nbFields > 0) { - - for ($i = 0; $i < $nbFields; $i++) { - - $map = array(); - $map['table_name'] = $real_source_fields_meta[$i]->table; - $map['refering_column'] = $real_source_fields_meta[$i]->name; - - if ($nbColumns > 1) { - $map['real_column'] = $view_columns[$i]; - } - - $column_map[] = $map; - - } - - } - - } - unset($real_source_result); - - return $column_map; - -} - - -/** - * Get existing data on transformations applied for - * columns in a particular table - * - * @param string $db Database name looking for - * - * @return mysqli_result Result of executed SQL query - */ -function PMA_getExistingTransformationData($db) -{ - $cfgRelation = PMA_getRelationsParam(); - - // Get the existing transformation details of the same database - // from pma__column_info table - $pma_transformation_sql = 'SELECT * FROM ' - . PMA_Util::backquote($cfgRelation['db']) . '.' - . PMA_Util::backquote($cfgRelation['column_info']) - . ' WHERE `db_name` = \'' - . PMA_Util::sqlAddSlashes($db) . '\''; - - return $GLOBALS['dbi']->tryQuery($pma_transformation_sql); - -} - - -/** - * Get SQL query for store new transformation details of a VIEW - * - * @param mysqli_result $pma_transformation_data Result set of SQL execution - * @param array $column_map Details of VIEW columns - * @param string $view_name Name of the VIEW - * @param string $db Database name of the VIEW - * - * @return string $new_transformations_sql SQL query for new transformations - */ -function PMA_getNewTransformationDataSql( - $pma_transformation_data, $column_map, $view_name, $db -) { - $cfgRelation = PMA_getRelationsParam(); - - // Need to store new transformation details for VIEW - $new_transformations_sql = 'INSERT INTO ' - . PMA_Util::backquote($cfgRelation['db']) . '.' - . PMA_Util::backquote($cfgRelation['column_info']) - . ' (`db_name`, `table_name`, `column_name`, `comment`, ' - . '`mimetype`, `transformation`, `transformation_options`)' - . ' VALUES '; - - $column_count = 0; - $add_comma = false; - - while ($data_row = $GLOBALS['dbi']->fetchAssoc($pma_transformation_data)) { - - foreach ($column_map as $column) { - - if ($data_row['table_name'] == $column['table_name'] - && $data_row['column_name'] == $column['refering_column'] - ) { - - $new_transformations_sql .= $add_comma ? ', ' : ''; - - $new_transformations_sql .= '(' - . '\'' . $db . '\', ' - . '\'' . $view_name . '\', ' - . '\''; - - $new_transformations_sql .= (isset($column['real_column'])) - ? $column['real_column'] - : $column['refering_column']; - - $new_transformations_sql .= '\', ' - . '\'' . $data_row['comment'] . '\', ' - . '\'' . $data_row['mimetype'] . '\', ' - . '\'' . $data_row['transformation'] . '\', ' - . '\'' - . PMA_Util::sqlAddSlashes( - $data_row['transformation_options'] - ) - . '\')'; - - $add_comma = true; - $column_count++; - break; - - } - - } - - if ($column_count == count($column_map)) { - break; - } - - } - - return ($column_count > 0) ? $new_transformations_sql : ''; - -} - - -?> diff --git a/templates/tbl_chart.php b/templates/tbl_chart.php new file mode 100644 index 0000000000..a0b619d4d5 --- /dev/null +++ b/templates/tbl_chart.php @@ -0,0 +1,146 @@ + + + +
+
+ +
+ + + +
+ + + + + + + + + + + + + +

+ +

+ +
+ +
+ + +
+ + + + +
+
+ + +
+ + +
+
+

 

+
+ + +
+ + + + +
+ +

 

+
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/test/classes/PMA_DatabaseInterface_test.php b/test/classes/PMA_DatabaseInterface_test.php new file mode 100644 index 0000000000..4c87e70967 --- /dev/null +++ b/test/classes/PMA_DatabaseInterface_test.php @@ -0,0 +1,118 @@ +getMockBuilder('PMA_DBI_Dummy') + ->disableOriginalConstructor() + ->getMock(); + + $extension->expects($this->any()) + ->method('realQuery') + ->will($this->returnValue(true)); + + $meta1 = new FieldMeta(); + $meta1->table = "meta1_table"; + $meta1->name = "meta1_name"; + + $meta2 = new FieldMeta(); + $meta2->table = "meta2_table"; + $meta2->name = "meta2_name"; + + $getFieldsMeta = array($meta1, $meta2); + + $extension->expects($this->any()) + ->method('getFieldsMeta') + ->will($this->returnValue(array( + $meta1, $meta2 + ))); + + $this->dbi = new PMA_DatabaseInterface($extension); + } + + /** + * Tests for DBI::getColumnMapFromSql() method. + * + * @return void + * @test + */ + public function testPMAGetColumnMap() + { + $sql_query = "PMA_sql_query"; + $view_columns = array( + "view_columns1", "view_columns2" + ); + + $column_map = $this->dbi->getColumnMapFromSql( + $sql_query, $view_columns + ); + + $this->assertEquals( + array( + 'table_name' => 'meta1_table', + 'refering_column' => 'meta1_name', + 'real_column' => 'view_columns1' + ), + $column_map[0] + ); + $this->assertEquals( + array( + 'table_name' => 'meta2_table', + 'refering_column' => 'meta2_name', + 'real_column' => 'view_columns2' + ), + $column_map[1] + ); + } + + /** + * Tests for DBI::getSystemDatabase() method. + * + * @return void + * @test + */ + public function testGetSystemDatabase() + { + $sd = $this->dbi->getSystemDatabase(); + $this->assertInstanceOf('PMA\\SystemDatabase', $sd); + } +} + +/** + * class for Table Field Meta + * + * @package PhpMyAdmin-test + */ +class FieldMeta +{ + public $table; + public $name; +} diff --git a/test/classes/PMA_SystemDatabase_test.php b/test/classes/PMA_SystemDatabase_test.php new file mode 100644 index 0000000000..61d0fad1de --- /dev/null +++ b/test/classes/PMA_SystemDatabase_test.php @@ -0,0 +1,115 @@ +getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->any()) + ->method('tryQuery') + ->will($this->returnValue('executeResult2')); + + //_SESSION + $_SESSION['relation'][$GLOBALS['server']] = array( + 'table_coords' => "table_name", + 'displaywork' => 'displaywork', + 'db' => "information_schema", + 'table_info' => 'table_info', + 'relwork' => 'relwork', + 'commwork' => 'commwork', + 'displaywork' => 'displaywork', + 'pdfwork' => 'pdfwork', + 'column_info' => 'column_info', + 'relation' => 'relation', + 'relwork' => 'relwork', + ); + + $dbi->expects($this->any()) + ->method('fetchAssoc') + ->will($this->returnValue(array( + 'table_name' => "table_name", + 'column_name' => "column_name", + 'comment' => "comment", + 'mimetype' => "mimetype", + 'transformation' => "transformation", + 'transformation_options' => "transformation_options", + ))); + + $this->sysDb = new PMA\SystemDatabase($dbi); + } + + /** + * Tests for PMA_getExistingTransformationData() method. + * + * @return void + * @test + */ + public function testPMAGetExistingTransformationData() + { + $db = "PMA_db"; + $ret = $this->sysDb->getExistingTransformationData($db); + + //validate that is the same as $GLOBALS['dbi']->tryQuery + $this->assertEquals( + 'executeResult2', + $ret + ); + } + + /** + * Tests for PMA_getNewTransformationDataSql() method. + * + * @return void + * @test + */ + public function testPMAGetNewTransformationDataSql() + { + $db = "PMA_db"; + $pma_transformation_data = array(); + $column_map = array( + array( + "table_name" => "table_name", + "refering_column" => "column_name" + ) + ); + $view_name = "view_name"; + + $ret = $this->sysDb->getNewTransformationDataSql( + $pma_transformation_data, $column_map, $view_name, $db + ); + + $sql = "INSERT INTO `information_schema`.`column_info` " + . "(`db_name`, `table_name`, `column_name`, `comment`, `mimetype`, " + . "`transformation`, `transformation_options`) VALUES " + . "('PMA_db', 'view_name', 'column_name', 'comment', 'mimetype', " + . "'transformation', 'transformation_options')"; + + $this->assertEquals( + $sql, + $ret + ); + } +} diff --git a/test/libraries/PMA_tbl_chart_test.php b/test/libraries/PMA_tbl_chart_test.php deleted file mode 100644 index 38ea6c1325..0000000000 --- a/test/libraries/PMA_tbl_chart_test.php +++ /dev/null @@ -1,296 +0,0 @@ -getMockBuilder('PMA_DatabaseInterface') - ->disableOriginalConstructor() - ->getMock(); - - $GLOBALS['dbi'] = $dbi; - - //$_SESSION - $_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme'); - $_SESSION['PMA_Theme'] = new PMA_Theme(); - } - - /** - * Tests for PMA_getHtmlForPmaTokenAndUrlQuery() method. - * - * @return void - * @test - */ - public function testPMAGetHtmlForPmaTokenAndUrlQuery() - { - $url_query = "url_query"; - $_SESSION[' PMA_token '] = "PMA_token"; - - $html = PMA_getHtmlForPmaTokenAndUrlQuery($url_query); - - $this->assertContains( - $_SESSION[' PMA_token '], - $html - ); - $this->assertContains( - $url_query, - $html - ); - } - - /** - * Tests for PMA_getHtmlForChartTypeOptions() method. - * - * @return void - * @test - */ - public function testPMAGetHtmlForChartTypeOptions() - { - $html = PMA_getHtmlForChartTypeOptions(); - - $this->assertContains( - _pgettext('Chart type', 'Bar'), - $html - ); - $this->assertContains( - _pgettext('Chart type', 'Column'), - $html - ); - $this->assertContains( - _pgettext('Chart type', 'Line'), - $html - ); - $this->assertContains( - _pgettext('Chart type', 'Spline'), - $html - ); - $this->assertContains( - _pgettext('Chart type', 'Area'), - $html - ); - $this->assertContains( - _pgettext('Chart type', 'Pie'), - $html - ); - $this->assertContains( - _pgettext('Chart type', 'Timeline'), - $html - ); - } - - /** - * Tests for PMA_getHtmlForStackedOption() method. - * - * @return void - * @test - */ - public function testPMAGetHtmlForStackedOption() - { - $html = PMA_getHtmlForStackedOption(); - - $this->assertContains( - __('Stacked'), - $html - ); - } - - /** - * Tests for PMA_getHtmlForChartXAxisOptions() method. - * - * @return void - * @test - */ - public function testPMAGetHtmlForChartXAxisOptions() - { - $keys = array( - "x1" => "value1", - "x2" => "value2", - ); - $yaxis = null; - - $html = PMA_getHtmlForChartXAxisOptions($keys, $yaxis); - - $this->assertContains( - __('X-Axis:'), - $html - ); - - //x-Axis values - $this->assertContains( - "x1", - $html - ); - $this->assertContains( - "value1", - $html - ); - $this->assertContains( - "x2", - $html - ); - $this->assertContains( - "value2", - $html - ); - } - - /** - * Tests for PMA_getHtmlForTableChartDisplay() method. - * - * @return void - * @test - */ - public function testPMAGetHtmlForTableChartDisplay() - { - $_SESSION[' PMA_token '] = "PMA_token"; - $_SESSION['tmpval']['pos'] = "pos"; - $_SESSION['tmpval']['max_rows'] = "all"; - $GLOBALS['cfg']['MaxRows'] = 10; - - $url_query = "url_query"; - $url_params = array("url" => "url_params"); - $keys = array( - "x1" => "value1", - "x2" => "value2", - ); - $fields_meta = array( - "x1" => new Mock_Meta("type1"), - "x2" => new Mock_Meta("type3"), - ); - $numeric_types = array("type1", "type2"); - $numeric_column_count = 2; - $sql_query = "sql_query"; - $yaxis = null; - - $html = PMA_getHtmlForTableChartDisplay( - $url_query, $url_params, $keys, - $fields_meta, $numeric_types, - $numeric_column_count, $sql_query - ); - - //case 1: PMA_getHtmlForPmaTokenAndUrlQuery - $this->assertContains( - PMA_getHtmlForPmaTokenAndUrlQuery($url_query), - $html - ); - - //case 2: PMA_getHtmlForPmaTokenAndUrlQuery - $this->assertContains( - PMA_URL_getHiddenInputs($url_params), - $html - ); - - //case 3: options - $this->assertContains( - PMA_getHtmlForChartTypeOptions(), - $html - ); - $this->assertContains( - PMA_getHtmlForStackedOption(), - $html - ); - - //case 4: options - $this->assertContains( - __('Chart title'), - $html - ); - - //case 5: options - $this->assertContains( - PMA_getHtmlForChartXAxisOptions($keys, $yaxis), - $html - ); - $this->assertContains( - PMA_getHtmlForChartSeriesOptions( - $keys, $fields_meta, $numeric_types, $yaxis, $numeric_column_count - ), - $html - ); - - //case 6: PMA_getHtmlForDateTimeCols - $this->assertContains( - PMA_getHtmlForDateTimeCols($keys, $fields_meta), - $html - ); - $this->assertContains( - PMA_getHtmlForTableAxisLabelOptions($yaxis, $keys), - $html - ); - $this->assertContains( - PMA_Util::getStartAndNumberOfRowsPanel($sql_query), - $html - ); - $this->assertContains( - PMA_getHtmlForChartAreaDiv(), - $html - ); - } -} - -/** - * Mock class for Meta Field - * - * @package PhpMyAdmin-test - */ -class Mock_Meta -{ - var $type; - - /** - * Constructor - * - * @param string $type1 meta type - */ - public function __construct($type1) - { - $this->type = $type1; - } -} - -?> diff --git a/test/libraries/PMA_tbl_views_test.php b/test/libraries/PMA_tbl_views_test.php deleted file mode 100644 index 7d6a086336..0000000000 --- a/test/libraries/PMA_tbl_views_test.php +++ /dev/null @@ -1,201 +0,0 @@ -getMockBuilder('PMA_DatabaseInterface') - ->disableOriginalConstructor() - ->getMock(); - - $dbi->expects($this->any()) - ->method('tryQuery') - ->will($this->returnValue('executeResult2')); - - //_SESSION - $_SESSION['relation'][$GLOBALS['server']] = array( - 'table_coords' => "table_name", - 'displaywork' => 'displaywork', - 'db' => "information_schema", - 'table_info' => 'table_info', - 'relwork' => 'relwork', - 'relation' => 'relation', - 'column_info' => 'column_info', - ); - - //_SESSION - $_SESSION['relation'][$GLOBALS['server']] = array( - 'table_coords' => "table_name", - 'displaywork' => 'displaywork', - 'db' => "information_schema", - 'table_info' => 'table_info', - 'relwork' => 'relwork', - 'commwork' => 'commwork', - 'displaywork' => 'displaywork', - 'pdfwork' => 'pdfwork', - 'column_info' => 'column_info', - 'relation' => 'relation', - 'relwork' => 'relwork', - ); - - $meta1 = new FieldMeta(); - $meta1->table = "meta1_table"; - $meta1->name = "meta1_name"; - $meta2 = new FieldMeta(); - $meta2->table = "meta2_table"; - $meta2->name = "meta2_name"; - - $getFieldsMeta = array($meta1, $meta2); - - $dbi->expects($this->any()) - ->method('getFieldsMeta') - ->will($this->returnValue($getFieldsMeta)); - - $GLOBALS['dbi'] = $dbi; - } - - /** - * Tests for PMA_getColumnMap() method. - * - * @return void - * @test - */ - public function testPMAGetColumnMap() - { - $sql_query = "PMA_sql_query"; - $view_columns = array( - "view_columns1", "view_columns2" - ); - - $column_map = PMA_getColumnMap($sql_query, $view_columns); - - $this->assertEquals( - array( - 'table_name' => 'meta1_table', - 'refering_column' => 'meta1_name', - 'real_column' => 'view_columns1' - ), - $column_map[0] - ); - $this->assertEquals( - array( - 'table_name' => 'meta2_table', - 'refering_column' => 'meta2_name', - 'real_column' => 'view_columns2' - ), - $column_map[1] - ); - } - - /** - * Tests for PMA_getExistingTransformationData() method. - * - * @return void - * @test - */ - public function testPMAGetExistingTransformationData() - { - $db = "PMA_db"; - $ret = PMA_getExistingTransformationData($db); - - //validate that is the same as $GLOBALS['dbi']->tryQuery - $this->assertEquals( - 'executeResult2', - $ret - ); - } - - /** - * Tests for PMA_getNewTransformationDataSql() method. - * - * @return void - * @test - */ - public function testPMAGetNewTransformationDataSql() - { - $dbi = $GLOBALS['dbi']; - $value = array( - 'table_name' => "table_name", - 'column_name' => "column_name", - 'comment' => "comment", - 'mimetype' => "mimetype", - 'transformation' => "transformation", - 'transformation_options' => "transformation_options", - ); - - $dbi->expects($this->at(0))->method('fetchAssoc') - ->will($this->returnValue($value)); - - $GLOBALS['dbi'] = $dbi; - - $db = "PMA_db"; - $pma_tranformation_data = array(); - $column_map = array( - array( - "table_name" => "table_name", - "refering_column" => "column_name" - ) - ); - $view_name = "view_name"; - - $ret = PMA_getNewTransformationDataSql( - $pma_tranformation_data, $column_map, $view_name, $db - ); - - $sql = "INSERT INTO `information_schema`.`column_info` " - . "(`db_name`, `table_name`, `column_name`, `comment`, `mimetype`, " - . "`transformation`, `transformation_options`) VALUES " - . "('PMA_db', 'view_name', 'column_name', 'comment', 'mimetype', " - . "'transformation', 'transformation_options')"; - $this->assertEquals( - $sql, - $ret - ); - } -} - -/** - * class for Table Field Meta - * - * @package PhpMyAdmin-test - */ -class FieldMeta -{ - public $table; - public $name; -} - -?> \ No newline at end of file diff --git a/view_create.php b/view_create.php index 86ac4c5cf5..100984b089 100644 --- a/view_create.php +++ b/view_create.php @@ -8,10 +8,8 @@ * @package PhpMyAdmin */ -/** - * - */ require_once './libraries/common.inc.php'; +require_once './libraries/SystemDatabase.class.php'; /** * Runs common work @@ -95,15 +93,19 @@ if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) { $view_columns = explode(',', $_REQUEST['view']['column_names']); } - $column_map = PMA_getColumnMap($_REQUEST['view']['as'], $view_columns); - $pma_tranformation_data = PMA_getExistingTransformationData($GLOBALS['db']); + $column_map = $GLOBALS['dbi']->getColumnMapFromSql( + $_REQUEST['view']['as'], $view_columns + ); + $pma_transformation_data = $GLOBALS['dbi']->getSystemDatabase()->getExistingTransformationData( + $GLOBALS['db'] + ); - if ($pma_tranformation_data !== false) { + if ($pma_transformation_data !== false) { // SQL for store new transformation details of VIEW - $new_transformations_sql = PMA_getNewTransformationDataSql( - $pma_tranformation_data, $column_map, $_REQUEST['view']['name'], - $GLOBALS['db'] + $new_transformations_sql = $GLOBALS['dbi']->getSystemDatabase()->getNewTransformationDataSql( + $pma_transformation_data, $column_map, + $_REQUEST['view']['name'], $GLOBALS['db'] ); // Store new transformations @@ -112,7 +114,7 @@ if (isset($_REQUEST['createview']) || isset($_REQUEST['alterview'])) { } } - unset($pma_tranformation_data); + unset($pma_transformation_data); if (! isset($_REQUEST['ajax_dialog'])) { $message = PMA_Message::success();