object = new PMA_DisplayResults('as', '', '', '');
$GLOBALS['PMA_Config'] = new PMA_Config();
$GLOBALS['PMA_Config']->enableBc();
$GLOBALS['text_dir'] = 'ltr';
$GLOBALS['PMA_String'] = new PMA_String();
include_once 'libraries/Response.class.php';
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$dbi->expects($this->any())->method('fieldFlags')
->will($this->returnArgument(1));
$GLOBALS['dbi'] = $dbi;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
* @return void
*/
protected function tearDown()
{
unset($this->object);
}
/**
* Call private functions by setting visibility to public.
*
* @param string $name method name
* @param array $params parameters for the invocation
*
* @return the output from the private method.
*/
private function _callPrivateFunction($name, $params)
{
$class = new ReflectionClass('PMA_DisplayResults');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method->invokeArgs($this->object, $params);
}
/**
* Test for setting display mode
*
* @param string $the_disp_mode the synthetic value for display_mode (see
* a few lines above for explanations)
* @param integer $the_total the total number of rows returned by the SQL
* query without any programmatically appended
* LIMIT clause
* (just a copy of $unlim_num_rows if it exists,
* elsecomputed inside this function)
* @param string $output output from the _setDisplayMode method
*
* @return void
*
* @dataProvider providerForTestSetDisplayModeCase1
* @group medium
*/
public function testSetDisplayModeCase1($the_disp_mode, $the_total, $output)
{
if (!isset($GLOBALS['fields_meta'])) {
$fields_meta = array();
$fields_meta[0] = new stdClass();
$fields_meta[0]->table = 'company';
} else {
$fields_meta = $GLOBALS['fields_meta'];
}
$this->object->setProperties(
null, $fields_meta, true, null, null,
null, null, null, null, null, null,
true, null, null, null, null, null, false
);
$this->assertEquals(
$output,
$this->_callPrivateFunction(
'_setDisplayMode',
array(&$the_disp_mode, &$the_total)
)
);
}
/**
* Provider for testSetDisplayModeCase1
*
* @return array data for testSetDisplayModeCase1
*/
public function providerForTestSetDisplayModeCase1()
{
return array(
array(
'urkp111111',
5,
array(
'edit_lnk' => 'nn',
'del_lnk' => 'nn',
'sort_lnk' => 0,
'nav_bar' => 0,
'ins_row' => 0,
'bkm_form' => 1,
'text_btn' => 1,
'pview_lnk' => 1
)
),
array(
'nnnn000000',
5,
array(
'edit_lnk' => 'nn',
'del_lnk' => 'nn',
'sort_lnk' => 0,
'nav_bar' => 0,
'ins_row' => 0,
'bkm_form' => 0,
'text_btn' => 0,
'pview_lnk' => 0
)
)
);
}
/**
* Test for setting display mode
*
* @param string $the_disp_mode the synthetic value for display_mode (see a
* few lines above for explanations)
* @param integer $the_total the total number of rows returned by the SQL
* query without any programmatically appended
* LIMIT clause
* (just a copy of $unlim_num_rows if it exists,
* elsecomputed inside this function)
* @param string $output output from the _setDisplayMode method
*
* @return void
*
* @dataProvider providerForTestSetDisplayModeCase2
*/
public function testSetDisplayModeCase2($the_disp_mode, $the_total, $output)
{
if (!isset($GLOBALS['fields_meta'])) {
$fields_meta = array();
$fields_meta[0] = new stdClass();
$fields_meta[0]->table = 'company';
} else {
$fields_meta = $GLOBALS['fields_meta'];
}
$this->object->setProperties(
1, $fields_meta, false, null, null,
false, null, null, null, null, null,
false, false, true, null, null, null, false
);
$this->object->__set('sql_query', 'SELECT * FROM `pma_bookmark` WHERE 1');
$this->assertEquals(
$output,
$this->_callPrivateFunction(
'_setDisplayMode',
array(&$the_disp_mode, &$the_total)
)
);
}
/**
* Provider for testSetDisplayModeCase2
*
* @return array data for testSetDisplayModeCase2
*/
public function providerForTestSetDisplayModeCase2()
{
return array(
array(
'urkp111111',
5,
array(
'edit_lnk' => 'nn',
'del_lnk' => 'nn',
'sort_lnk' => 0,
'nav_bar' => 0,
'ins_row' => 0,
'bkm_form' => 1,
'text_btn' => 1,
'pview_lnk' => 1
)
),
array(
'nnnn000000',
5,
array(
'edit_lnk' => 'nn',
'del_lnk' => 'nn',
'sort_lnk' => 0,
'nav_bar' => 0,
'ins_row' => 0,
'bkm_form' => 0,
'text_btn' => 0,
'pview_lnk' => 0
)
)
);
}
/**
* Test for setting display mode
*
* @param string $the_disp_mode the synthetic value for display_mode (see a
* few lines above for explanations)
* @param integer $the_total the total number of rows returned by the SQL
* query without any programmatically appended
* LIMIT clause
* (just a copy of $unlim_num_rows if it exists,
* elsecomputed inside this function)
* @param string $output output from the _setDisplayMode method
*
* @return void
*
* @dataProvider providerForTestSetDisplayModeCase3
*/
public function testSetDisplayModeCase3($the_disp_mode, $the_total, $output)
{
if (!isset($GLOBALS['fields_meta'])) {
$fields_meta = array();
$fields_meta[0] = new stdClass();
$fields_meta[0]->table = 'company';
} else {
$fields_meta = $GLOBALS['fields_meta'];
}
$this->object->setProperties(
1, $fields_meta, false, null, null,
false, null, null, null, null, null,
false, false, null, null, '1', null, false
);
$this->assertEquals(
$output,
$this->_callPrivateFunction(
'_setDisplayMode',
array(&$the_disp_mode, &$the_total)
)
);
}
/**
* Provider for testSetDisplayModeCase3
*
* @return array data for testSetDisplayModeCase3
*/
public function providerForTestSetDisplayModeCase3()
{
return array(
array(
'urkp111111',
5,
array(
'edit_lnk' => 'nn',
'del_lnk' => 'nn',
'sort_lnk' => 0,
'nav_bar' => 0,
'ins_row' => 0,
'bkm_form' => 0,
'text_btn' => 0,
'pview_lnk' => 0
)
),
array(
'nnnn000000',
5,
array(
'edit_lnk' => 'nn',
'del_lnk' => 'nn',
'sort_lnk' => 0,
'nav_bar' => 0,
'ins_row' => 0,
'bkm_form' => 0,
'text_btn' => 0,
'pview_lnk' => 0
)
)
);
}
/**
* Test for _isSelect function
*
* @return void
*/
public function testisSelect()
{
$analyzed_sql = array(array());
$analyzed_sql[0]['select_expr'] = array();
$analyzed_sql[0]['queryflags']['select_from'] = 'pma';
$analyzed_sql[0]['table_ref'] = array('table_ref');
$this->assertTrue(
$this->_callPrivateFunction(
'_isSelect',
array($analyzed_sql)
)
);
}
/**
* Test for navigation buttons
*
* @param string $caption iconic caption for button
* @param string $title text for button
* @param integer $pos position for next query
* @param string $html_sql_query query ready for display
* @param string $output output from the _getTableNavigationButton
* method
*
* @return void
*
* @dataProvider providerForTestGetTableNavigationButton
*/
public function testGetTableNavigationButton(
$caption, $title, $pos, $html_sql_query, $output
) {
$GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons';
$_SESSION[' PMA_token '] = 'token';
$this->assertEquals(
$output,
$this->_callPrivateFunction(
'_getTableNavigationButton',
array(&$caption, $title, $pos, $html_sql_query)
)
);
}
/**
* Provider for testGetTableNavigationButton
*
* @return array array data for testGetTableNavigationButton
*/
public function providerForTestGetTableNavigationButton()
{
return array(
array(
'btn',
'Submit',
1,
'SELECT * FROM `pma_bookmark` WHERE 1',
'
'
)
);
}
/**
* Test for table navigation
*
* @param integer $pos_next the offset for the "next" page
* @param integer $pos_prev the offset for the "previous" page
* @param string $id_for_direction_dropdown the id for the direction dropdown
* @param boolean $is_innodb the table type is innoDb or not
* @param string $output output from the _getTableNavigation
* method
*
* @return void
*
* @dataProvider providerForTestGetTableNavigation
*/
public function testGetTableNavigation(
$pos_next, $pos_prev, $id_for_direction_dropdown, $is_innodb, $output
) {
$_SESSION['tmpval']['max_rows'] = '20';
$_SESSION['tmpval']['pos'] = true;
$GLOBALS['num_rows'] = '20';
$GLOBALS['unlim_num_rows'] = '50';
$GLOBALS['cfg']['ShowAll'] = true;
$GLOBALS['cfg']['ShowDisplayDirection'] = true;
$_SESSION['tmpval']['repeat_cells'] = '1';
$_SESSION['tmpval']['disp_direction'] = '1';
/**
* FIXME Counting words of a generated large HTML is not a good way
* of testing IMO. Introduce more granular assertations that assert for
* existance of important content inside the generated HTML.
*/
/*
$this->assertEquals(
$output,
str_word_count(
$this->_callPrivateFunction(
'_getTableNavigation',
array(
$pos_next, $pos_prev, $id_for_direction_dropdown, $is_innodb
)
)
)
);
*/
$this->markTestIncomplete('Not yet implemented!');
}
/**
* Provider for testing table navigation
*
* @return array data for testGetTableNavigation
*/
public function providerForTestGetTableNavigation()
{
return array(
array(
21,
41,
'123',
false,
'310'
)
);
}
/**
* Data provider for testGetClassesForColumn
*
* @return array parameters and output
*/
public function dataProviderForTestGetClassesForColumn()
{
return array(
array(
'grid_edit',
'not_null',
'',
'',
'',
0,
'data grid_edit not_null row_0 vpointer vmarker'
)
);
}
/**
* Test for _getClassesForColumn
*
* @param string $grid_edit_class the class for all editable columns
* @param string $not_null_class the class for not null columns
* @param string $relation_class the class for relations in a column
* @param string $hide_class the class for visibility of a column
* @param string $field_type_class the class related to type of the field
* @param integer $row_no the row index
* @param string $output output of__getResettedClassForInlineEdit
*
* @return void
*
* @dataProvider dataProviderForTestGetClassesForColumn
*/
public function testGetClassesForColumn(
$grid_edit_class, $not_null_class, $relation_class,
$hide_class, $field_type_class, $row_no, $output
) {
$GLOBALS['cfg']['BrowsePointerEnable'] = true;
$GLOBALS['cfg']['BrowseMarkerEnable'] = true;
$_SESSION['tmpval']['disp_direction']
= PMA_DisplayResults::DISP_DIR_VERTICAL;
$this->assertEquals(
$output,
$this->_callPrivateFunction(
'_getClassesForColumn',
array(
$grid_edit_class, $not_null_class, $relation_class,
$hide_class, $field_type_class, $row_no
)
)
);
}
/**
* Test for _getClassForDateTimeRelatedFields - case 1
*
* @return void
*/
public function testGetClassForDateTimeRelatedFieldsCase1()
{
$this->assertEquals(
'datetimefield',
$this->_callPrivateFunction(
'_getClassForDateTimeRelatedFields',
array(PMA_DisplayResults::DATETIME_FIELD)
)
);
}
/**
* Test for _getClassForDateTimeRelatedFields - case 2
*
* @return void
*/
public function testGetClassForDateTimeRelatedFieldsCase2()
{
$this->assertEquals(
'datefield',
$this->_callPrivateFunction(
'_getClassForDateTimeRelatedFields',
array(PMA_DisplayResults::DATE_FIELD)
)
);
}
/**
* Test for _getClassForDateTimeRelatedFields - case 3
*
* @return void
*/
public function testGetClassForDateTimeRelatedFieldsCase3()
{
$this->assertEquals(
'text',
$this->_callPrivateFunction(
'_getClassForDateTimeRelatedFields',
array(PMA_DisplayResults::STRING_FIELD)
)
);
}
/**
* Provide data for testGetOperationLinksForVerticalTable
*
* @return array parameters and output
*/
public function dataProviderForTestGetOperationLinksForVerticalTable()
{
return array(
array(
'edit',
'
'
),
array(
'copy',
"
\nCOPY1COPY2
\n"
),
array(
'delete',
"
\nDELETE1DELETE2
\n"
),
);
}
/**
* Test for _getOperationLinksForVerticalTable
*
* @param string $operation edit/copy/delete
* @param string $output output of _getOperationLinksForVerticalTable
*
* @return void
*
* @dataProvider dataProviderForTestGetOperationLinksForVerticalTable
*/
public function testGetOperationLinksForVerticalTable(
$operation, $output
) {
$vertical_display = array(
'row_delete' => array(),
'textbtn' => '
' . "\n"
)
);
}
/**
* Test _getDataCellForNonNumericColumns
*
* @param boolean $protectBinary all|blob|noblob|no
* @param string $column the relevant column in data row
* @param string $class the html class for column
* @param object $meta the meta-information about the field
* @param array $map the list of relations
* @param array $_url_params the parameters for generate url
* @param boolean $condition_field the column should highlighted
* or not
* @param string $transformation_plugin the name of transformation function
* @param string $default_function the default transformation function
* @param string $transform_options the transformation parameters
* @param boolean $is_field_truncated is data truncated due to LimitChars
* @param array $analyzed_sql the analyzed query
* @param integer $dt_result the link id associated to the query
* which results have to be displayed
* @param integer $col_index the column index
* @param string $output the output of this function
*
* @return void
*
* @dataProvider dataProviderForTestGetDataCellForNonNumericColumns
*/
public function testGetDataCellForNonNumericColumns(
$protectBinary, $column, $class, $meta, $map,
$_url_params, $condition_field, $transformation_plugin,
$default_function, $transform_options, $is_field_truncated,
$analyzed_sql, $dt_result, $col_index, $output
) {
$_SESSION['tmpval']['display_binary'] = true;
$_SESSION['tmpval']['display_blob'] = false;
$_SESSION['tmpval']['relational_display'] = false;
$GLOBALS['cfg']['LimitChars'] = 50;
$GLOBALS['cfg']['ProtectBinary'] = $protectBinary;
$this->assertEquals(
$output,
$this->_callPrivateFunction(
'_getDataCellForNonNumericColumns',
array(
$column, $class, $meta, $map, $_url_params, $condition_field,
$transformation_plugin, $default_function, $transform_options,
$is_field_truncated, $analyzed_sql, &$dt_result, $col_index
)
)
);
}
}