Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Unit test cases for PMA_tbl_indexes #698

Merged
merged 1 commit into from
Sep 16, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions test/libraries/PMA_tbl_indexes_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Tests for libraries/tbl_indexes.lib.php
*
* @package PhpMyAdmin-test
*/

/*
* Include to test.
*/
require_once 'libraries/tbl_indexes.lib.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/Index.class.php';
require_once 'libraries/Message.class.php';
require_once 'libraries/database_interface.inc.php';
require_once 'libraries/php-gettext/gettext.inc';
require_once 'libraries/relation.lib.php';
require_once 'libraries/url_generating.lib.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/sanitizing.lib.php';

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

/**
* Setup function for test cases
*
* @access protected
* @return void
*/
protected function setUp()
{
/**
* SET these to avoid undefined index error
*/
$GLOBALS['server'] = 1;
$GLOBALS['cfg']['Server']['pmadb'] = '';
$GLOBALS['pmaThemeImage'] = 'theme/';
$GLOBALS['cfg']['ServerDefault'] = "server";
$GLOBALS['cfg']['ShowHint'] = true;

$dbi = $this->getMockBuilder('PMA_DatabaseInterface')
->disableOriginalConstructor()
->getMock();

$GLOBALS['dbi'] = $dbi;

//$_SESSION
$_SESSION['PMA_Theme'] = PMA_Theme::load('./themes/pmahomme');
$_SESSION['PMA_Theme'] = new PMA_Theme();
}

/**
* Tests for PMA_getSqlQueryForIndexCreateOrEdit() method.
*
* @return void
* @test
*/
public function testPMAGetSqlQueryForIndexCreateOrEdit()
{
$db = "pma_db";
$table = "pma_table";
$index = new PMA_Index();
$error = false;

$_REQUEST['old_index'] = "PRIMARY";

$sql = PMA_getSqlQueryForIndexCreateOrEdit(
$db, $table, $index, $error
);

$this->assertEquals(
"ALTER TABLE `pma_db`.`pma_table` DROP PRIMARY KEY,COMMENT '';",
$sql
);
}

/**
* Tests for PMA_getNumberOfFieldsForForm() method.
*
* @return void
* @test
*/
public function testPMAGetNumberOfFieldsForForm()
{
$index = new PMA_Index();
$error = false;

$add_fields = PMA_getNumberOfFieldsForForm($index);

$this->assertEquals(
1,
$add_fields
);

$_REQUEST['create_index'] = true;
$_REQUEST['added_fields'] = 2;
$add_fields = PMA_getNumberOfFieldsForForm($index);
$this->assertEquals(
$_REQUEST['added_fields'],
$add_fields
);
}

/**
* Tests for PMA_getFormParameters() method.
*
* @return void
* @test
*/
public function testPMAGetFormParameters()
{
$db = "pma_db";
$table = "pma_table";

$form_params = PMA_getFormParameters($db, $table);
$expect = array(
'db' => $db,
'table' => $table,
);
$this->assertEquals(
$expect,
$form_params
);

$_REQUEST['index'] = "index";
$form_params = PMA_getFormParameters($db, $table);
$expect = array(
'db' => $db,
'table' => $table,
'old_index' => $_REQUEST['index'],
);
$this->assertEquals(
$expect,
$form_params
);

$_REQUEST['old_index'] = "old_index";
$form_params = PMA_getFormParameters($db, $table);
$expect = array(
'db' => $db,
'table' => $table,
'old_index' => $_REQUEST['old_index'],
);
$this->assertEquals(
$expect,
$form_params
);

$_REQUEST['create_index'] = "create_index";
$form_params = PMA_getFormParameters($db, $table);
$expect = array(
'db' => $db,
'table' => $table,
'create_index' => 1,
);
$this->assertEquals(
$expect,
$form_params
);
}
}
?>