Merge pull request #576 from adamgsoc2013/ut_plu_dbi

add more test cases
This commit is contained in:
Michal Čihař 2013-08-08 23:33:59 -07:00
commit 2a3d5c608a
4 changed files with 117 additions and 4 deletions

View File

@ -187,6 +187,16 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase
$dbi->expects($this->any())->method('fetchResult')
->will($this->returnValueMap($fetchResult));
$dbi->expects($this->any())->method('fetchValue')
->will(
$this->returnValue(
"CREATE TABLE `PMA`.`PMA_BookMark_2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` text NOT NULL
)"
)
);
$databases = array();
$database_name = 'PMA';
$databases[$database_name]['SCHEMA_TABLES'] = 1;
@ -456,6 +466,17 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase
array('type'=>'DATA_TYPE'),
$show_create_table[0]['create_table_fields']['COLUMN_NAME']
);
//not a view
$show_create_table = PMA_Table::analyzeStructure('PMA', 'PMA_BookMark_2');
$this->assertEquals(
array('type'=>'INT', 'timestamp_not_null'=>false),
$show_create_table[0]['create_table_fields']['id']
);
$this->assertEquals(
array('type'=>'TEXT', 'timestamp_not_null'=>false),
$show_create_table[0]['create_table_fields']['username']
);
}
/**
@ -776,6 +797,13 @@ class PMA_Table_Test extends PHPUnit_Framework_TestCase
false,
$is_define_property
);
//getUiProp after removeUiProp
$is_define_property = $table->getUiProp($property);
$this->assertEquals(
false,
$is_define_property
);
}
/**

View File

@ -60,7 +60,18 @@ class PMA_Ip_Allow_Deny_Test extends PHPUnit_Framework_TestCase
"101.0.0.25",
PMA_getIp()
);
//proxy
$var_name = "direct_ip";
$direct_ip = $_SERVER['REMOTE_ADDR'];
$GLOBALS['cfg']['TrustedProxies'][$direct_ip] = $var_name;
$_SERVER[$var_name] = "192.168.0.1";
$this->assertEquals(
"192.168.0.1",
PMA_getIp()
);
unset($_SERVER[$var_name]);
unset($GLOBALS['cfg']['TrustedProxies'][$direct_ip]);
}
/**

View File

@ -86,10 +86,23 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase
true,
$cfgRelation['commwork']
);
//validate PMA_getDbComments when commwork = true
$db_comments = PMA_getDbComments();
$this->assertEquals(
array('db_name0' => 'comment0','db_name1' => 'comment1'),
$db_comments
);
$this->assertEquals(
true,
$cfgRelation['displaywork']
);
//validate PMA_getDisplayField when displaywork = true
$display_field = PMA_getDisplayField($db, $table);
$this->assertEquals(
'PMA_display_field',
$display_field
);
$this->assertEquals(
true,
$cfgRelation['relwork']
@ -308,10 +321,11 @@ class PMA_Relation_Cleanup_Test extends PHPUnit_Framework_TestCase
class DBI_PMA_Relation_Cleanup extends PMA_DatabaseInterface
{
var $index;
var $assocIndex;
var $totalNum;
var $values = array();
var $indexs = array();
/**
* Constructor
*
@ -319,6 +333,8 @@ class DBI_PMA_Relation_Cleanup extends PMA_DatabaseInterface
public function __construct()
{
$this->index = 0;
$this->assocIndex = 0;
$this->totalNum = 2;
$this->values = array(
'bookmark',
'relation',
@ -414,6 +430,7 @@ class DBI_PMA_Relation_Cleanup extends PMA_DatabaseInterface
if (stripos($sql, "bookmark") !== false) {
unset($GLOBALS [$this->indexs['bookmark']]);
}
return true;
}
/**
@ -456,4 +473,62 @@ class DBI_PMA_Relation_Cleanup extends PMA_DatabaseInterface
{
return true;
}
/**
* returns only the first row from the result
*
* <code>
* $sql = 'SELECT * FROM `user` WHERE `id` = 123';
* $user = $GLOBALS['dbi']->fetchSingleRow($sql);
* // produces
* // $user = array('id' => 123, 'name' => 'John Doe')
* </code>
*
* @param string|mysql_result $result query or mysql result
* @param string $type NUM|ASSOC|BOTH
* returned array should either numeric
* associativ or booth
* @param resource $link mysql link
*
* @return array|boolean first row from result
* or false if result is empty
*/
public function fetchSingleRow($result, $type = 'ASSOC', $link = null)
{
return array(
'display_field' => "PMA_display_field"
);
}
/**
* returns array of rows with associative keys from $result
*
* @param object $result result set identifier
*
* @return array
*/
public function fetchAssoc($result)
{
if ($this->assocIndex < $this->totalNum) {
$assocResult['db_name'] = "db_name" . $this->assocIndex;
$assocResult['comment'] = "comment" . $this->assocIndex;
$this->assocIndex++;
return $assocResult;
}
$this->assocIndex = 0;
return false;
}
/**
* returns the number of rows returned by last query
*
* @param object $result result set identifier
*
* @return string|int
*/
public function numRows($result)
{
return $this->totalNum;
}
}

View File

@ -167,8 +167,7 @@ class PMA_Relation_Test extends PHPUnit_Framework_TestCase
* @return void
*/
public function testPMA_getDisplayField()
{
{
$db = 'information_schema';
$table = 'CHARACTER_SETS';
$this->assertEquals(