Skip to content

Commit

Permalink
Unit tests for PMA_getPageIdsAndNames() and PMA_getHtmlForEditOrDelet…
Browse files Browse the repository at this point in the history
…ePages()

Signed-off-by: Bimal Yashodha <kb.yashodha@gmail.com>
  • Loading branch information
kb-yashodha committed Jun 19, 2014
1 parent e2af757 commit 685f6dc
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libraries/designer.lib.php
Expand Up @@ -9,6 +9,8 @@
exit;
}

require_once 'libraries/relation.lib.php';

/**
* Function to get html for displaying the page edit/delete form
*
Expand Down Expand Up @@ -101,7 +103,7 @@ function PMA_getHtmlForPageSaveAs($db)

/**
* Retrieve IDs and names of schema pages
*
*
* @param string $db database name
*
* @return array array of schema page id and names
Expand All @@ -117,7 +119,7 @@ function PMA_getPageIdsAndNames($db)
$page_rs = PMA_queryAsControlUser(
$page_query, false, PMA_DatabaseInterface::QUERY_STORE
);

$result = array();
while ($curr_page = $GLOBALS['dbi']->fetchAssoc($page_rs)) {
$result[$curr_page['page_nr']] = $curr_page['page_descr'];
Expand Down
118 changes: 118 additions & 0 deletions test/libraries/PMA_designer_test.php
@@ -0,0 +1,118 @@
<?php
/**
* Tests for libraries/designer.lib.php
*
* @package PhpMyAdmin-test
*/
/*
* Include to test.
*/
require_once 'libraries/designer.lib.php';

require_once 'libraries/database_interface.inc.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/relation.lib.php';

/**
* Tests for libraries/designer.lib.php
*
* @package PhpMyAdmin-test
*/
class PMA_DesginerTest extends PHPUnit_Framework_TestCase
{

/**
* Setup for test cases
*
* @return void
*/
public function setup()
{
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['ServerDefault'] = 1;

$_SESSION = array(
'relation' => array(
'1' => array('db' => 'pmadb', 'pdf_pages' => 'pdf_pages')
),
' PMA_token ' => 'token'
);
}

private function _mockDatabaseInteraction($db)
{
$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();

$dbi->expects($this->at(0))
->method('tryQuery')
->with(
"SELECT `page_nr`, `page_descr` FROM `pmadb`.`pdf_pages` WHERE db_name = '" . $db . "' ORDER BY `page_nr`",
2,
PMA_DatabaseInterface::QUERY_STORE,
false
)
->will($this->returnValue('dummyRS'));

$dbi->expects($this->at(1))
->method('fetchAssoc')
->with('dummyRS')
->will($this->returnValue(array('page_nr' => '1', 'page_descr' => 'page1')));

$dbi->expects($this->at(2))
->method('fetchAssoc')
->with('dummyRS')
->will($this->returnValue(array('page_nr' => '2', 'page_descr' => 'page2')));

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

$GLOBALS['dbi'] = $dbi;
}

/**
* Test for PMA_getPageIdsAndNames()
*
* @return void
*/
public function testGetPageIdsAndNames()
{
$db = 'db';
$this->_mockDatabaseInteraction($db);

$result = PMA_getPageIdsAndNames($db);

$this->assertEquals(
array(
'1' => 'page1',
'2' => 'page2'
),
$result
);
}

/**
* Test for PMA_getHtmlForEditOrDeletePages()
*
* @return void
*/
public function testGetHtmlForEditOrDeletePages()
{
$db = 'db';
$operation = 'edit';
$this->_mockDatabaseInteraction($db);

$result = PMA_getHtmlForEditOrDeletePages($db, $operation);
$this->assertContains('<input type="hidden" name="' . $operation . '" value="edit" />', $result);
$this->assertContains('<select name="selected_page" id="selected_page">', $result);
$this->assertContains('<option value="0">', $result);
$this->assertContains('<option value="1">page1</option>', $result);
$this->assertContains('<option value="2">page2</option>', $result);
}
}
?>

0 comments on commit 685f6dc

Please sign in to comment.