/**
  * 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);
 }
示例#2
0
$data = array();
$result = $GLOBALS['dbi']->tryQuery($sql_query);
$fields_meta = $GLOBALS['dbi']->getFieldsMeta($result);
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
    $data[] = $row;
}
$keys = array_keys($data[0]);
$numeric_types = array('int', 'real');
$numeric_column_count = 0;
foreach ($keys as $idx => $key) {
    if (in_array($fields_meta[$idx]->type, $numeric_types)) {
        $numeric_column_count++;
    }
}
if ($numeric_column_count == 0) {
    $response->isSuccess(false);
    $response->addJSON('message', __('No numeric columns present in the table to plot.'));
    exit;
}
// get settings if any posted
$chartSettings = array();
if (PMA_isValid($_REQUEST['chartSettings'], 'array')) {
    $chartSettings = $_REQUEST['chartSettings'];
}
$url_params['db'] = $GLOBALS['db'];
$url_params['reload'] = 1;
/**
 * Displays the page
 */
$htmlString = PMA_getHtmlForTableChartDisplay($url_query, $url_params, $keys, $fields_meta, $numeric_types, $numeric_column_count, $sql_query);
$response->addHTML($htmlString);