object = new PMA_DisplayResults('as', '', '', '');
$GLOBALS['PMA_Config'] = new PMA_Config();
$GLOBALS['PMA_Config']->enableBc();
$GLOBALS['text_dir'] = 'ltr';
$GLOBALS['collation_connection'] = 'utf-8';
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 _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, true)
)
);
}
/**
* 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 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, $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;
$_SESSION['tmpval']['repeat_cells'] = '1';
/**
* FIXME Counting words of a generated large HTML is not a good way
* of testing IMO. Introduce more granular assertions that assert for
* existence of important content inside the generated HTML.
*/
/*
$this->assertEquals(
$output,
str_word_count(
$this->_callPrivateFunction(
'_getTableNavigation',
array(
$pos_next, $pos_prev, $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,
false,
'310'
)
);
}
/**
* Data provider for testGetClassesForColumn
*
* @return array parameters and output
*/
public function dataProviderForTestGetClassesForColumn()
{
return array(
array(
'grid_edit',
'not_null',
'',
'',
'',
'data grid_edit not_null '
)
);
}
/**
* 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 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, $output
) {
$GLOBALS['cfg']['BrowsePointerEnable'] = true;
$GLOBALS['cfg']['BrowseMarkerEnable'] = true;
$this->assertEquals(
$output,
$this->_callPrivateFunction(
'_getClassesForColumn',
array(
$grid_edit_class, $not_null_class, $relation_class,
$hide_class, $field_type_class
)
)
);
}
/**
* 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)
)
);
}
/**
* Data provider for testGetCheckBoxesForMultipleRowOperations
*
* @return array parameters and output
*/
public function dataProviderForGetCheckBoxesForMultipleRowOperations()
{
return array(
array(
'_left',
array('edit_lnk' => null, 'del_lnk' => null),
//array('edit_lnk' => 'nn', 'del_lnk' => 'nn'),
'
'
. '
'
)
);
}
/**
* Test for _getCheckBoxesForMultipleRowOperations
*
* @param string $dir _left / _right
* @param array $displayParts which parts to display
* @param string $output output of _getCheckBoxesForMultipleRowOperations
*
* @return void
*
* @dataProvider dataProviderForGetCheckBoxesForMultipleRowOperations
*/
public function testGetCheckBoxesForMultipleRowOperations(
$dir, $displayParts, $output
) {
$vertical_display = array(
'row_delete' => array(
'
'
. '
',
'
'
. '
'
)
);
$this->object->__set('vertical_display', $vertical_display);
$_SESSION['tmpval']['repeat_cells'] = 0;
$this->assertEquals(
$output,
$this->_callPrivateFunction(
'_getCheckBoxesForMultipleRowOperations',
array($dir, $displayParts)
)
);
}
/**
* Test for _getOffsets - case 1
*
* @return void
*/
public function testGetOffsetsCase1()
{
$_SESSION['tmpval']['max_rows'] = PMA_DisplayResults::ALL_ROWS;
$this->assertEquals(
array(0, 0),
$this->_callPrivateFunction('_getOffsets', array())
);
}
/**
* Test for _getOffsets - case 2
*
* @return void
*/
public function testGetOffsetsCase2()
{
$_SESSION['tmpval']['max_rows'] = 5;
$_SESSION['tmpval']['pos'] = 4;
$this->assertEquals(
array(9, 0),
$this->_callPrivateFunction('_getOffsets', array())
);
}
/**
* Data provider for testGetSortParams
*
* @return array parameters and output
*/
public function dataProviderForGetSortParams()
{
return array(
array('', array(array(''), array(''), array(''))),
array(
'`a_sales`.`customer_id` ASC',
array(
array('`a_sales`.`customer_id` ASC'),
array('`a_sales`.`customer_id`'),
array('ASC')
)
),
array(
'`a_sales`.`customer_id` ASC, `b_sales`.`customer_id` DESC',
array(
array(
'`a_sales`.`customer_id` ASC',
'`b_sales`.`customer_id` DESC'
),
array('`a_sales`.`customer_id`', '`b_sales`.`customer_id`'),
array('ASC', 'DESC')
)
),
);
}
/**
* Test for _getSortParams
*
* @param string $order_by_clause the order by clause of the sql query
* @param string $output output of _getSortParams
*
* @return void
*
* @dataProvider dataProviderForGetSortParams
*/
public function testGetSortParams($order_by_clause, $output)
{
$this->assertEquals(
$output,
$this->_callPrivateFunction(
'_getSortParams', array($order_by_clause)
)
);
}
/**
* Data provider for testGetCheckboxForMultiRowSubmissions
*
* @return array parameters and output
*/
public function dataProviderForGetCheckboxForMultiRowSubmissions()
{
return array(
array(
'sql.php?db=data&table=new&sql_query=DELETE+FROM+%60data%60'
. '.%60new%60+WHERE+%60new%60.%60id%60+%3D+1&message_to_show='
. 'The+row+has+been+deleted&goto=sql.php%3Fdb%3Ddata%26table%3D'
. 'new%26sql_query%3DSELECT%2B%252A%2BFROM%2B%2560new%2560%26message'
. '_to_show%3DThe%2Brow%2Bhas%2Bbeen%2Bdeleted%26goto%3Dtbl_'
. 'structure.php%26token%3Dd1aecb47ef7c081e068e7008b38a5d76&'
. 'token=d1aecb47ef7c081e068e7008b38a5d76',
array(
'edit_lnk' => 'ur',
'del_lnk' => 'dr',
'sort_lnk' => '0',
'nav_bar' => '1',
'ins_row' => '1',
'bkm_form' => '1',
'text_btn' => '1',
'pview_lnk' => '1'
),
0,
'%60new%60.%60id%60+%3D+1',
array('`new`.`id`' => '= 1'),
'[%_PMA_CHECKBOX_DIR_%]',
'odd',
'
'
. '
'
)
);
}
/**
* Test for _getCheckboxForMultiRowSubmissions
*
* @param string $del_url delete url
* @param array $displayParts array with explicit indexes for all
* the display elements
* @param string $row_no the row number
* @param string $where_clause_html url encoded where clause
* @param array $condition_array array of conditions in the where clause
* @param string $id_suffix suffix for the id
* @param string $class css classes for the td element
* @param string $output output of _getCheckboxForMultiRowSubmissions
*
* @return void
*
* @dataProvider dataProviderForGetCheckboxForMultiRowSubmissions
*/
public function testGetCheckboxForMultiRowSubmissions(
$del_url, $displayParts, $row_no, $where_clause_html, $condition_array,
$id_suffix, $class, $output
) {
$this->assertEquals(
$output,
$this->_callPrivateFunction(
'_getCheckboxForMultiRowSubmissions',
array(
$del_url, $displayParts, $row_no, $where_clause_html,
$condition_array, $id_suffix, $class
)
)
);
}
/**
* Data provider for testGetEditLink
*
* @return array parameters and output
*/
public function dataProviderForGetEditLink()
{
return array(
array(
'tbl_change.php?db=Data&table=customer&where_clause=%60'
. 'customer%60.%60id%60+%3D+1&clause_is_unique=1&sql_query='
. 'SELECT+%2A+FROM+%60customer%60&goto=sql.php&default_'
. 'action=update&token=bbd5003198a3bd856b21d9607d6c6a1e',
'odd edit_row_anchor',
' Edit',
'`customer`.`id` = 1',
'%60customer%60.%60id%60+%3D+1',
'
' . "\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
)
)
);
}
}