Skip to content

Commit

Permalink
add UT for PMA_server_binlog and PMA_server_database
Browse files Browse the repository at this point in the history
  • Loading branch information
xmujay committed Sep 4, 2013
1 parent 169aa23 commit 7bc9669
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/libraries/PMA_server_binlog_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require_once 'libraries/sanitizing.lib.php';
require_once 'libraries/sqlparser.lib.php';
require_once 'libraries/js_escape.lib.php';
require_once 'libraries/database_interface.inc.php';

/**
* PMA_ServerBinlog_Test class
Expand Down Expand Up @@ -202,4 +203,65 @@ public function testPMAGetLogInfo()
$html
);
}

/**
* Test for PMA_getAllLogItemInfo
*
* @return void
*/
public function testPMAGetAllLogItemInfo()
{
//Mock DBI
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();

$fetchAssoc = array(
'Info' => 'Info',
'Log_name' => 'Log_name',
'Pos' => 'Pos',
'Event_type' => 'Event_type',
'Server_id' => 'Server_id',
'Orig_log_pos' => 'Orig_log_pos',
'End_log_pos' => 'End_log_pos',
);
$dbi->expects($this->at(0))->method('fetchAssoc')
->will($this->returnValue($fetchAssoc));

$dbi->expects($this->at(1))->method('fetchAssoc')
->will($this->returnValue(false));

$GLOBALS['dbi'] = $dbi;
$GLOBALS['cfg']['LimitChars'] = 2;

$result = array();
$dontlimitchars = ";";

$html = PMA_getAllLogItemInfo($result, $dontlimitchars);
$value = $fetchAssoc;
$this->assertContains(
$value['Log_name'],
$html
);
$this->assertContains(
$value['Pos'],
$html
);
$this->assertContains(
$value['Event_type'],
$html
);
$this->assertContains(
$value['Server_id'],
$html
);
$this->assertContains(
$value['Orig_log_pos'],
$html
);
$this->assertContains(
htmlspecialchars($value['Info']),
$html
);
}
}
38 changes: 38 additions & 0 deletions test/libraries/PMA_server_databases_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,42 @@ public function testPMAGetListForSortDatabase()
$sort_order
);
}

/**
* Test for PMA_getHtmlForColumnOrder
*
* @return void
*/
public function testPMAGetHtmlForColumnOrder()
{
//Mock DBI
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();

$GLOBALS['dbi'] = $dbi;

$column_order = array(
"first_database" => array(
'format' => 'byte',
'footer' => '10333',
)
);
$first_database = array(
"first_database" => "db1"
);
$html = PMA_getHtmlForColumnOrder($column_order, $first_database);
$stat = $column_order["first_database" ];
list($value, $unit)
= PMA_Util::formatByteDown($stat['footer'], 3, 1);
$this->assertContains(
$value,
$html
);
$this->assertContains(
$unit,
$html
);

}
}

0 comments on commit 7bc9669

Please sign in to comment.