Merge pull request #701 from adamgsoc2013/UnitTestCases
add Unit test case for PMA_tbl_indexes and PMA_tbl_printview
This commit is contained in:
commit
95fbc0ad13
@ -238,7 +238,7 @@ function PMA_getFormParameters($db, $table)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function PMA_getHtmlForIndexForm($fields, $index, $form_params,$add_fields)
|
||||
function PMA_getHtmlForIndexForm($fields, $index, $form_params, $add_fields)
|
||||
{
|
||||
$html = "";
|
||||
$html .= '<form action="tbl_indexes.php" method="post" name="index_frm" id="'
|
||||
|
||||
@ -44,18 +44,39 @@ class PMA_TblIndexTest extends PHPUnit_Framework_TestCase
|
||||
$GLOBALS['pmaThemeImage'] = 'theme/';
|
||||
$GLOBALS['cfg']['ServerDefault'] = "server";
|
||||
$GLOBALS['cfg']['ShowHint'] = true;
|
||||
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$indexs = array(
|
||||
array(
|
||||
"Schema" => "Schema1",
|
||||
"Key_name"=>"Key_name1",
|
||||
"Column_name"=>"Column_name1"
|
||||
),
|
||||
array(
|
||||
"Schema" => "Schema2",
|
||||
"Key_name"=>"Key_name2",
|
||||
"Column_name"=>"Column_name2"
|
||||
),
|
||||
array(
|
||||
"Schema" => "Schema3",
|
||||
"Key_name"=>"Key_name3",
|
||||
"Column_name"=>"Column_name3"
|
||||
),
|
||||
);
|
||||
|
||||
$dbi->expects($this->any())->method('getTableIndexes')
|
||||
->will($this->returnValue($indexs));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
|
||||
//$_SESSION
|
||||
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
|
||||
$_SESSION['PMA_Theme'] = new PMA_Theme();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests for PMA_getSqlQueryForIndexCreateOrEdit() method.
|
||||
*
|
||||
@ -68,7 +89,7 @@ class PMA_TblIndexTest extends PHPUnit_Framework_TestCase
|
||||
$table = "pma_table";
|
||||
$index = new PMA_Index();
|
||||
$error = false;
|
||||
|
||||
|
||||
$_REQUEST['old_index'] = "PRIMARY";
|
||||
|
||||
$sql = PMA_getSqlQueryForIndexCreateOrEdit(
|
||||
@ -80,7 +101,7 @@ class PMA_TblIndexTest extends PHPUnit_Framework_TestCase
|
||||
$sql
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests for PMA_getNumberOfFieldsForForm() method.
|
||||
*
|
||||
@ -107,7 +128,7 @@ class PMA_TblIndexTest extends PHPUnit_Framework_TestCase
|
||||
$add_fields
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests for PMA_getFormParameters() method.
|
||||
*
|
||||
@ -165,5 +186,89 @@ class PMA_TblIndexTest extends PHPUnit_Framework_TestCase
|
||||
$form_params
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for PMA_getHtmlForIndexForm() method.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testPMAGetHtmlForIndexForm()
|
||||
{
|
||||
$fields = array("field_name" => "field_type");
|
||||
$index = new PMA_Index();
|
||||
$form_params = array(
|
||||
'db' => 'db',
|
||||
'table' => 'table',
|
||||
'create_index' => 1,
|
||||
);
|
||||
$add_fields = 3;
|
||||
|
||||
$html = PMA_getHtmlForIndexForm($fields, $index, $form_params, $add_fields);
|
||||
|
||||
//PMA_URL_getHiddenInputs
|
||||
$this->assertContains(
|
||||
PMA_URL_getHiddenInputs($form_params),
|
||||
$html
|
||||
);
|
||||
|
||||
//Index name
|
||||
$this->assertContains(
|
||||
__('Index name:'),
|
||||
$html
|
||||
);
|
||||
$doc_html = PMA_Util::showHint(
|
||||
PMA_Message::notice(
|
||||
__(
|
||||
'"PRIMARY" <b>must</b> be the name of'
|
||||
. ' and <b>only of</b> a primary key!'
|
||||
)
|
||||
)
|
||||
);
|
||||
$this->assertContains(
|
||||
$doc_html,
|
||||
$html
|
||||
);
|
||||
|
||||
//Index name
|
||||
$this->assertContains(
|
||||
__('Index name:'),
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
PMA_Util::showMySQLDocu('ALTER_TABLE'),
|
||||
$html
|
||||
);
|
||||
|
||||
//generateIndexSelector
|
||||
$this->assertContains(
|
||||
$index->generateIndexSelector(),
|
||||
$html
|
||||
);
|
||||
|
||||
//items
|
||||
$this->assertContains(
|
||||
__('Column'),
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
__('Size'),
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
sprintf(__('Add %s column(s) to index'), 1),
|
||||
$html
|
||||
);
|
||||
|
||||
//$field_name & $field_type
|
||||
$this->assertContains(
|
||||
"field_name",
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
"field_type",
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@ -16,9 +16,11 @@ require_once 'libraries/php-gettext/gettext.inc';
|
||||
require_once 'libraries/relation.lib.php';
|
||||
require_once 'libraries/url_generating.lib.php';
|
||||
require_once 'libraries/Tracker.class.php';
|
||||
require_once 'libraries/transformations.lib.php';
|
||||
require_once 'libraries/Message.class.php';
|
||||
require_once 'libraries/Table.class.php';
|
||||
require_once 'libraries/js_escape.lib.php';
|
||||
require_once 'libraries/sqlparser.lib.php';
|
||||
|
||||
/**
|
||||
* Tests for libraries/tbl_printview.lib.php
|
||||
@ -39,10 +41,33 @@ class PMA_TblPrintViewTest extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* SET these to avoid undefined index error
|
||||
*/
|
||||
$GLOBALS['server'] = 1;
|
||||
$GLOBALS['cfg']['TableNavigationLinksMode'] = 'icons';
|
||||
$GLOBALS['cfg']['LimitChars'] = 100;
|
||||
$_SESSION['relation'][$GLOBALS['server']] = array(
|
||||
'table_coords' => "table_name",
|
||||
'displaywork' => 'displaywork',
|
||||
'db' => "information_schema",
|
||||
'table_info' => 'table_info',
|
||||
'column_info' => 'column_info',
|
||||
'relwork' => 'relwork',
|
||||
'relation' => 'relation',
|
||||
'commwork' => 'commwork',
|
||||
'bookmarkwork' => 'bookmarkwork',
|
||||
);
|
||||
|
||||
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$fetchResult = array(
|
||||
'column1' => array('mimetype' => 'value1', 'transformation'=> 'pdf'),
|
||||
'column2' => array('mimetype' => 'value2', 'transformation'=> 'xml'),
|
||||
);
|
||||
|
||||
$dbi->expects($this->any())->method('fetchResult')
|
||||
->will($this->returnValue($fetchResult));
|
||||
|
||||
$GLOBALS['dbi'] = $dbi;
|
||||
}
|
||||
|
||||
@ -323,7 +348,7 @@ class PMA_TblPrintViewTest extends PHPUnit_Framework_TestCase
|
||||
$db = "pma_db";
|
||||
$table = "pma_table";
|
||||
$cell_align_left = "cell_align_left";
|
||||
|
||||
|
||||
$html = PMA_getHtmlForSpaceUsageAndRowStatistics(
|
||||
$showtable, $db, $table, $cell_align_left
|
||||
);
|
||||
@ -341,7 +366,7 @@ class PMA_TblPrintViewTest extends PHPUnit_Framework_TestCase
|
||||
$html
|
||||
);
|
||||
|
||||
//validation 2 : $data_size, $data_unit
|
||||
//validation 2 : $data_size, $data_unit
|
||||
list($index_size, $index_unit)
|
||||
= PMA_Util::formatByteDown(
|
||||
$showtable['Index_length']
|
||||
@ -384,7 +409,7 @@ class PMA_TblPrintViewTest extends PHPUnit_Framework_TestCase
|
||||
$html
|
||||
);
|
||||
|
||||
//validation 5 : $effect_size, $effect_unit
|
||||
//validation 5 : $effect_size, $effect_unit
|
||||
list($tot_size, $tot_unit) = PMA_Util::formatByteDown(
|
||||
$showtable['Data_length'] + $showtable['Index_length']
|
||||
);
|
||||
@ -397,6 +422,75 @@ class PMA_TblPrintViewTest extends PHPUnit_Framework_TestCase
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for PMA_getHtmlForPrintViewColumns() method.
|
||||
*
|
||||
* @return void
|
||||
* @test
|
||||
*/
|
||||
public function testPMAGetHtmlForPrintViewColumns()
|
||||
{
|
||||
$columns = array(
|
||||
array(
|
||||
"Type" => "Type1",
|
||||
"Default" => "Default1",
|
||||
"Null" => "Null1",
|
||||
"Field" => "Field1",
|
||||
)
|
||||
);
|
||||
$analyzed_sql = array(
|
||||
array(
|
||||
'create_table_fields' => array(
|
||||
"Field1" => array(
|
||||
"type" => "TIMESTAMP",
|
||||
"timestamp_not_null" => true
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$pk_array = array(
|
||||
"Field1" => "pk_array"
|
||||
);
|
||||
$have_rel = false;
|
||||
$res_rel = array();
|
||||
$db = "pma_db";
|
||||
$table = "pma_table";
|
||||
$cfgRelation = array('mimework' => true);
|
||||
|
||||
$html = PMA_getHtmlForPrintViewColumns(
|
||||
$columns, $analyzed_sql, $pk_array, $have_rel,
|
||||
$res_rel, $db, $table, $cfgRelation
|
||||
);
|
||||
|
||||
//validation 1 : $row
|
||||
$row = $columns[0];
|
||||
$this->assertContains(
|
||||
htmlspecialchars($row['Default']),
|
||||
$html
|
||||
);
|
||||
$this->assertContains(
|
||||
htmlspecialchars($row['Field']),
|
||||
$html
|
||||
);
|
||||
|
||||
//validation 2 : $pk_array
|
||||
$field_name = htmlspecialchars($row['Field']);
|
||||
$comments = PMA_getComments($db, $table);
|
||||
$this->assertContains(
|
||||
$field_name,
|
||||
$html
|
||||
);
|
||||
|
||||
//validation 3 : $extracted_columnspec
|
||||
$extracted_columnspec = PMA_Util::extractColumnSpec($row['Type']);
|
||||
$type = $extracted_columnspec['print_type'];
|
||||
$attribute = $extracted_columnspec['attribute'];
|
||||
$this->assertContains(
|
||||
$type,
|
||||
$html
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user