/** * Returns Html for show create. * * @param string $db Database name * @param array $db_objects Array containing DB objects * * @return string Html */ function PMA_getHtmlShowCreate($db, $db_objects) { // Main outer container. $html_output = '<div class="show_create_results">' . '<h2>' . __('Showing create queries') . '</h2>'; // Table header. $output_table = '<fieldset>' . '<legend>%s</legend>' . '<table class="show_create">' . '<thead>' . '<tr>' . '<th>%s</th>' . '<th>Create %s</th>' . '</tr>' . '</thead>' . '<tbody>'; // Holds rows html for views. $views = ''; // Holds rows html for tables. $tables = ''; // Handles odd, even classes for rows. // for 'Views' $odd1 = true; // for 'Tables' $odd2 = true; // Iterate through each object. foreach ($db_objects as $key => $object) { // Check if current object is a View or Table. $isView = PMA_Table::isView($db, $object); if ($isView) { $row_class = $odd1 ? 'odd' : 'even'; $create_data = PMA_getShowCreate($db, $object, 'view'); $views .= '<tr class="' . $row_class . '">' . '<td><strong>' . PMA_mimeDefaultFunction($create_data['View']) . '</strong></td>' . '<td>' . PMA_mimeDefaultFunction($create_data['Create View']) . '</td>' . '</tr>'; $odd1 = !$odd1; } else { $row_class = $odd2 ? 'odd' : 'even'; $create_data = PMA_getShowCreate($db, $object, 'table'); $tables .= '<tr class="' . $row_class . '">' . '<td><strong>' . PMA_mimeDefaultFunction($create_data['Table']) . '</strong></td>' . '<td>' . PMA_mimeDefaultFunction($create_data['Create Table']) . '</td>' . '</tr>'; $odd2 = !$odd2; } } // Prepare table header for each type of object. if (!empty($tables)) { $title = __('Tables'); $tables = sprintf($output_table, $title, 'Table', 'Table') . $tables . '</tbody></table></fieldset>'; } if (!empty($views)) { $title = __('Views'); $views = sprintf($output_table, $title, 'View', 'View') . $views . '</tbody></table></fieldset>'; } // Compile the final html. $html_output .= $tables . $views . '</div>'; return $html_output; }
/** * Test for PMA_getHtmlShowCreate * * @return void */ public function testPMAGetHtmlShowCreate() { //mock DBI $dbi = $this->getMockBuilder('PMA_DatabaseInterface')->disableOriginalConstructor()->getMock(); $db = 'PMA'; $table = 'PMA_Table'; $is_view_query = "SELECT TABLE_NAME\n FROM information_schema.VIEWS\n WHERE TABLE_SCHEMA = '" . PMA_Util::sqlAddSlashes($db) . "'\n AND TABLE_NAME = '" . PMA_Util::sqlAddSlashes($table) . "'"; $show_create_query = 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table); $expected_result = 'CREATE TABLE `PMA_Table` ( ' . '`id` numeric ' . ') ENGINE=InnoDB DEFAULT CHARSET=latin1'; $dbi->expects($this->any())->method('fetchResult')->with($is_view_query)->will($this->returnValue(false)); $dbi->expects($this->any())->method('fetchSingleRow')->with($show_create_query)->will($this->returnValue(array('Table' => 'PMA_Table', 'Create Table' => $expected_result))); $GLOBALS['dbi'] = $dbi; $output = PMA_getHtmlShowCreate($db, array($table)); $this->assertContains('Showing create queries', $output); $this->assertContains('<legend>Tables</legend><table class="show_create">', $output); $this->assertContains('<th>Create Table</th>', $output); $this->assertContains(PMA_mimeDefaultFunction($expected_result), $output); }