Skip to content

Commit

Permalink
Merge pull request #689 from ayushchd/ut_fix
Browse files Browse the repository at this point in the history
Fix date-second issue with Tracker tests
  • Loading branch information
madhuracj committed Sep 16, 2013
2 parents 0d9e452 + 4b7edee commit 4205e2a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 7 deletions.
47 changes: 44 additions & 3 deletions test/bootstrap-dist.php
Expand Up @@ -41,11 +41,11 @@

/**
* Function to emulate headers() function by storing headers in GLOBAL array
*
*
* @param string $string header string
* @param boolean $replace .
* @param integer $http_response_code .
*
*
* @return void
*/
function test_header($string, $replace = true, $http_response_code = 200)
Expand All @@ -59,14 +59,26 @@ function test_header($string, $replace = true, $http_response_code = 200)

/**
* Function to emulate headers_hest.
*
*
* @return boolean false
*/
function test_headers_sent()
{
return false;
}

/**
* Function to emulate date() function
*
* @param string $date_format arg
*
* @return string dummy date
*/
function test_date($date_format)
{
return '0000-00-00 00:00:00';
}

if (PMA_HAS_RUNKIT && $GLOBALS['runkit_internal_override']) {
echo "Enabling headers testing...\n";
runkit_function_rename('header', 'test_header_override');
Expand Down Expand Up @@ -106,4 +118,33 @@ function PMA_getTagArray($elementHTML, $arr = array())

return $arr;
}

/**
* Overrides date function
*
* @return boolean whether function was overridden or not
*/
function setupForTestsUsingDate()
{
if (PMA_HAS_RUNKIT && $GLOBALS['runkit_internal_override']) {
runkit_function_rename('date', 'test_date_override');
runkit_function_rename('test_date', 'date');
return true;
} else {
return false;
}
}

/**
* Restores date function
*
* @return void
*/
function tearDownForTestsUsingDate()
{
if (PMA_HAS_RUNKIT && $GLOBALS['runkit_internal_override']) {
runkit_function_rename('date', 'test_date');
runkit_function_rename('test_date_override', 'date');
}
}
?>
28 changes: 24 additions & 4 deletions test/libraries/PMA_Tracker_test.php
Expand Up @@ -269,13 +269,19 @@ public function testIsTracked()
*/
public function testGetLogComment()
{
if (!setupForTestsUsingDate()) {
$this->markTestSkipped("Cannot override internal function date()");
}

$date = date('Y-m-d H:i:s');
$GLOBALS['cfg']['Server']['user'] = "pma_test_user";

$this->assertEquals(
"# log $date pma_test_user\n",
PMA_Tracker::getLogComment()
);

tearDownForTestsUsingDate();
}

/**
Expand All @@ -286,6 +292,10 @@ public function testGetLogComment()
*/
public function testCreateVersion()
{
if (!setupForTestsUsingDate()) {
$this->markTestSkipped("Cannot override internal function date()");
}

$GLOBALS['cfg']['Server']['tracking_add_drop_table'] = true;
$GLOBALS['cfg']['Server']['tracking_add_drop_view'] = true;
$GLOBALS['cfg']['Server']['user'] = "pma_test_user";
Expand Down Expand Up @@ -406,6 +416,8 @@ public function testCreateVersion()
'executed',
PMA_Tracker::createVersion('pma_test', 'pma_tbl', '1', '11', true)
);

tearDownForTestsUsingDate();
}

/**
Expand Down Expand Up @@ -449,6 +461,10 @@ public function testDeleteTracking()
*/
public function testCreateDatabaseVersion()
{
if (!setupForTestsUsingDate()) {
$this->markTestSkipped("Cannot override internal function date()");
}

$GLOBALS['cfg']['Server']['tracking_add_drop_table'] = true;
$GLOBALS['cfg']['Server']['tracking_add_drop_view'] = true;
$GLOBALS['cfg']['Server']['user'] = "pma_test_user";
Expand Down Expand Up @@ -491,6 +507,8 @@ public function testCreateDatabaseVersion()
'executed',
PMA_Tracker::createDatabaseVersion('pma_test', '1', 'SHOW DATABASES')
);

tearDownForTestsUsingDate();
}

/**
Expand Down Expand Up @@ -564,6 +582,10 @@ public function testChangeTracking($dbname = 'pma_db', $tablename = 'pma_tbl',
*/
public function testChangeTrackingData()
{
if (!setupForTestsUsingDate()) {
$this->markTestSkipped("Cannot override internal function date()");
}

$reflection = new \ReflectionProperty('PMA_Tracker', 'pma_table');
$reflection->setAccessible(true);
$reflection->setValue(null, 'pma_table_tracking');
Expand Down Expand Up @@ -597,10 +619,6 @@ public function testChangeTrackingData()
)
);

/* FIXME: This breaks sometimes
* (when the query is executed in different second than
* date is read).
*/
$sql_query_2 = " UPDATE pma_table_tracking" .
" SET `data_sql` = '# log $date user1test_statement1\n" .
"# log $date user2test_statement2\n' " .
Expand Down Expand Up @@ -641,6 +659,8 @@ public function testChangeTrackingData()
$new_data
)
);

tearDownForTestsUsingDate();
}

/**
Expand Down

0 comments on commit 4205e2a

Please sign in to comment.