Skip to content
Permalink
Browse files

Adapt table tracking main tests

Signed-off-by: Leonardo Strozzi <laps15@inf.ufpr.br>
  • Loading branch information...
laps15 committed Jul 6, 2018
1 parent bcad25a commit e95505239d5fc8e8ef31faf7f4c1b2a477de372a
Showing with 93 additions and 229 deletions.
  1. +93 −229 test/classes/TrackingTest.php
@@ -163,17 +163,84 @@ public function testExtractTableNames()
* @return void
* @test
*/
public function testGetHtmlForDataDefinitionAndManipulationStatements()
public function testGetHtmlForMain()
{
$url_query = "url_query";
$last_version = 10;
$html = $this->tracking->getHtmlForDataDefinitionAndManipulationStatements(
$sql_result = true;
$last_version = 3;
$url_params = [];
$url_query = "select * from PMA";
$pmaThemeImage = "themePath/img";
$text_dir = "ltr";
// Mock dbi
$dbi_old = $GLOBALS['dbi'];
$dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$fetchArray = [
'tracking_active' => 1,
'version' => 1,
'db_name' => 'db_name',
'table_name' => 'table_name',
'date_created' => 'date_created',
'date_updated' => 'date_updated'
];
// return fetchArray for selectable entries
for ($i = 2; $i < 6; $i++) {
$dbi->expects($this->at($i))
->method('fetchArray')
->will($this->returnValue($fetchArray));
}
$dbi->expects($this->at(6))
->method('fetchArray')
->will($this->returnValue(false));
// return fetchArray for Activate/Deactivate tracking
for ($i = 7; $i < 13; $i++) {
$dbi->expects($this->at($i))
->method('fetchArray')
->will($this->returnValue($fetchArray));
}
$dbi->expects($this->at(13))
->method('fetchArray')
->will($this->returnValue(false));
$dbi->method('numRows')
->will($this->returnValue(1));
$GLOBALS['dbi'] = $dbi;
$html = $this->tracking->getHtmlForMainPage(
$url_query,
$last_version,
$GLOBALS['db'],
[$GLOBALS['table']]
$url_params,
$pmaThemeImage,
$text_dir,
$last_version
);
/*
* test selectables panel
*/
$this->assertContains(
htmlspecialchars($fetchArray['db_name']).'.'.htmlspecialchars($fetchArray['table_name']),
$html
);
/*
* test versions table
*/
$this->assertContains(
"<td>date_created</td>",
$html
);
$this->assertContains(
__('Delete version'),
$html
);
/*
* test create panel
*/
$this->assertContains(
'<div id="div_create_version">',
$html
@@ -210,77 +277,34 @@ public function testGetHtmlForDataDefinitionAndManipulationStatements()
__('Create version'),
$html
);
}
/**
* Tests for getHtmlForActivateDeactivateTracking() method.
*
* @return void
* @test
*/
public function testGetHtmlForActivateDeactivateTracking()
{
$url_query = "url_query";
$last_version = "10";
$html = $this->tracking->getHtmlForActivateDeactivateTracking(
'activate',
$url_query,
$last_version
);
$this->assertContains(
$url_query,
$html
);
$item = sprintf(
__('Activate tracking for %s'),
htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
);
$this->assertContains(
$item,
$html
);
$this->assertContains(
$last_version,
$html
);
/*
* test deactivate/activate panel
*/
$this->assertContains(
__('Activate now'),
'Deactivate now',
$html
);
$html = $this->tracking->getHtmlForActivateDeactivateTracking(
'deactivate',
$fetchArray['tracking_active'] = 0;
$dbi->expects($this->at(9))
->method('fetchArray')
->will($this->returnValue($fetchArray));
$GLOBALS['dbi'] = $dbi;
$html = $this->tracking->getHtmlForMainPage(
$url_query,
$url_params,
$pmaThemeImage,
$text_dir,
$last_version
);
$this->assertContains(
'Activate now',
$html
);
$this->assertContains(
$url_query,
$html
);
$item = sprintf(
__('Deactivate tracking for %s'),
htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
);
$this->assertContains(
$item,
$html
);
$this->assertContains(
$last_version,
$html
);
$this->assertContains(
__('Deactivate now'),
$html
);
//restore DBI
$GLOBALS['dbi'] = $dbi_old;
}
/**
@@ -431,166 +455,6 @@ public function testGetListOfVersionsOfTable()
);
}
/**
* Tests for getHtmlForTableVersionDetails() method.
*
* @return void
* @test
*/
public function testGetHtmlForTableVersionDetails()
{
$sql_result = true;
$last_version = "10";
$url_params = [];
$url_query = "select * from PMA";
$pmaThemeImage = "themePath/img";
$text_dir = "ltr";
$dbi_old = $GLOBALS['dbi'];
$dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$fetchArray = [
'tracking_active' => 1,
'version' => "10",
'db_name' => 'db_name',
'table_name' => 'table_name',
'date_created' => 'date_created',
'date_updated' => 'date_updated'
];
$dbi->expects($this->at(0))
->method('fetchArray')
->will($this->returnValue($fetchArray));
$dbi->expects($this->at(1))
->method('fetchArray')
->will($this->returnValue($fetchArray));
$dbi->expects($this->at(2))
->method('fetchArray')
->will($this->returnValue(false));
$GLOBALS['dbi'] = $dbi;
$ret = $this->tracking->getHtmlForTableVersionDetails(
$sql_result,
$last_version,
$url_params,
$url_query,
$pmaThemeImage,
$text_dir
);
$this->assertContains(
__('Version'),
$ret
);
$this->assertContains(
__('Created'),
$ret
);
$this->assertContains(
__('Updated'),
$ret
);
$this->assertContains(
__('Status'),
$ret
);
$this->assertContains(
__('Action'),
$ret
);
$this->assertContains(
__('Show'),
$ret
);
$this->assertContains(
$fetchArray['version'],
$ret
);
$this->assertContains(
$fetchArray['date_created'],
$ret
);
$this->assertContains(
$fetchArray['date_updated'],
$ret
);
$this->assertContains(
__('Tracking report'),
$ret
);
$this->assertContains(
__('Structure snapshot'),
$ret
);
$html = sprintf(
__('Deactivate tracking for %s'),
htmlspecialchars($GLOBALS['db'] . '.' . $GLOBALS['table'])
);
$this->assertContains(
$html,
$ret
);
//restore DBI
$GLOBALS['dbi'] = $dbi_old;
}
/**
* Tests for getHtmlForSelectableTables() method.
*
* @return void
* @test
*/
public function testGetHtmlForSelectableTables()
{
$selectable_tables_sql_result = true;
$url_query = "select * from PMA";
$dbi_old = $GLOBALS['dbi'];
$dbi = $this->getMockBuilder('PhpMyAdmin\DatabaseInterface')
->disableOriginalConstructor()
->getMock();
$fetchArray = [
'tracking_active' => 1,
'version' => "10",
'db_name' => 'db_name',
'table_name' => 'table_name',
'date_created' => 'date_created',
'date_updated' => 'date_updated'
];
$dbi->expects($this->at(0))
->method('fetchArray')
->will($this->returnValue($fetchArray));
$dbi->expects($this->at(1))
->method('fetchArray')
->will($this->returnValue($fetchArray));
$dbi->expects($this->at(2))
->method('fetchArray')
->will($this->returnValue(false));
$GLOBALS['dbi'] = $dbi;
$ret = $this->tracking->getHtmlForSelectableTables(
$selectable_tables_sql_result,
$url_query
);
$this->assertContains(
htmlspecialchars($fetchArray['table_name']),
$ret
);
$this->assertContains(
htmlspecialchars($fetchArray['db_name']),
$ret
);
//restore DBI
$GLOBALS['dbi'] = $dbi_old;
}
/**
* Tests for getHtmlForTrackingReport() method.
*

0 comments on commit e955052

Please sign in to comment.
You can’t perform that action at this time.