Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add Unit test cases for PMA_tbl_relation #665

Merged
merged 2 commits into from

2 participants

@adamgsoc2013

No description provided.

@nijel nijel merged commit d9724bf into phpmyadmin:master

1 check passed

Details default The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 2, 2013
  1. @adamgsoc2013
  2. @adamgsoc2013

    fix redefined error

    adamgsoc2013 authored
This page is out of date. Refresh to see the latest.
View
4 libraries/tbl_relation.lib.php
@@ -193,8 +193,8 @@ function PMA_getHtmlForCommonForm($db, $table, $columns, $cfgRelation,
* @param array $columns columns
* @param array $cfgRelation configuration relation
* @param string $tbl_storage_engine table storage engine
- * @param array $existrel db, table, column
- * @param array $existrel_foreign db, table, column
+ * @param array $existrel existed relations
+ * @param array $existrel_foreign existed relations for foreign keys
* @param array $options_array options array
* @param string $db current database
* @param string $table current table
View
266 test/libraries/PMA_tbl_relation_test.php
@@ -11,6 +11,10 @@
*/
require_once 'libraries/tbl_relation.lib.php';
require_once 'libraries/Util.class.php';
+require_once 'libraries/url_generating.lib.php';
+require_once 'libraries/database_interface.inc.php';
+require_once 'libraries/php-gettext/gettext.inc';
+require_once 'libraries/relation.lib.php';
/**
* Tests for libraries/tbl_relation.lib.php
@@ -20,6 +24,25 @@
class PMA_TblRelationTest extends PHPUnit_Framework_TestCase
{
/**
+ * Configures environment
+ *
+ * @return void
+ */
+ protected function setUp()
+ {
+ $GLOBALS['server'] = 0;
+
+ $GLOBALS['pma'] = new DataBasePMAMockForTblRelation();
+ $GLOBALS['pma']->databases = new DataBaseMockForTblRelation();
+
+ $dbi = $this->getMockBuilder('PMA_DatabaseInterface')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $GLOBALS['dbi'] = $dbi;
+ }
+
+ /**
* Tests for PMA_generateRelationalDropdown() method.
*
* @return void
@@ -72,12 +95,12 @@ public function testGenerateRelationalDropdown()
// test for selected value not found in values array and its escaping
$this->assertContains(
- '<option value="valu&lt;4" selected="selected">valu&lt;4'
+ '<option value="valu&lt;4" selected="selected">valu&lt;4'
. '</option></select>',
PMA_generateRelationalDropdown('name', $values, 'valu<4')
);
}
-
+
/**
* Tests for PMA_generateDropdown() method.
*
@@ -90,7 +113,7 @@ public function testPMAGenerateDropdown()
$select_name = "select_name";
$choices = array("choice1", "choice2");
$selected_value = "";
-
+
$html_output = PMA_generateDropdown(
$dropdown_question, $select_name, $choices, $selected_value
);
@@ -115,7 +138,7 @@ public function testPMAGenerateDropdown()
$html_output
);
}
-
+
/**
* Tests for PMA_backquoteSplit() method.
*
@@ -131,7 +154,7 @@ public function testPMABackquoteSplit()
PMA_backquoteSplit($text)
);
}
-
+
/**
* Tests for PMA_getSQLToCreateForeignKey() method.
*
@@ -149,15 +172,15 @@ public function testPMAGetSQLToCreateForeignKey()
$sql = PMA_getSQLToCreateForeignKey(
$table, $field, $foreignDb, $foreignTable, $foreignField
);
- $sql_excepted = 'ALTER TABLE `PMA_table` ADD '
- . 'FOREIGN KEY (`PMA_field`) REFERENCES '
+ $sql_excepted = 'ALTER TABLE `PMA_table` ADD '
+ . 'FOREIGN KEY (`PMA_field`) REFERENCES '
. '`foreignDb`.`foreignTable`(`foreignField`);';
$this->assertEquals(
$sql_excepted,
$sql
);
}
-
+
/**
* Tests for PMA_getSQLToDropForeignKey() method.
*
@@ -174,5 +197,232 @@ public function testPMAGetSQLToDropForeignKey()
PMA_getSQLToDropForeignKey($table, $fk)
);
}
+
+ /**
+ * Tests for PMA_getHtmlForCommonForm() method.
+ *
+ * @return void
+ * @test
+ */
+ public function testPMAGetHtmlForCommonForm()
+ {
+ $db = "pma_db";
+ $table = "pma_table";
+ $columns = array(
+ array("Field" => "Field1")
+ );
+ $cfgRelation = array(
+ 'displaywork' => true,
+ 'relwork' => true,
+ 'displaywork' => true,
+ );
+ $tbl_storage_engine = "InnerDB";
+ $existrel = array();
+ $existrel_foreign = array();
+ $options_array = array();
+
+ $save_row = array();
+ foreach ($columns as $row) {
+ $save_row[] = $row;
+ }
+
+ $html = PMA_getHtmlForCommonForm(
+ $db, $table, $columns, $cfgRelation,
+ $tbl_storage_engine, $existrel, $existrel_foreign, $options_array
+ );
+
+ //case 1: PMA_getHtmlForCommonFormHeader
+ $this->assertContains(
+ PMA_getHtmlForCommonFormHeader($db, $table),
+ $html
+ );
+
+ $this->assertContains(
+ PMA_URL_getHiddenInputs($db, $table),
+ $html
+ );
+
+ //case 2: PMA_getHtmlForCommonFormRows
+ $this->assertContains(
+ __('Relations'),
+ $html
+ );
+
+ $this->assertContains(
+ __('Column'),
+ $html
+ );
+
+ $this->assertContains(
+ __('Internal relation'),
+ $html
+ );
+
+ $this->assertContains(
+ __('Choose column to display:'),
+ $html
+ );
+
+ //case 3: PMA_getHtmlForCommonFormTableHeaders
+ $this->assertContains(
+ PMA_getHtmlForCommonFormTableHeaders($cfgRelation, $tbl_storage_engine),
+ $html
+ );
+
+ //case 4: PMA_getHtmlForRow
+ $row = PMA_getHtmlForRow(
+ $save_row, 0, true, $cfgRelation, $existrel, $db,
+ $tbl_storage_engine, $existrel_foreign, $options_array
+ );
+ $this->assertContains(
+ $row,
+ $html
+ );
+
+ //case 5: PMA_getHtmlForDisplayFieldInfos
+ $this->assertContains(
+ PMA_getHtmlForDisplayFieldInfos($db, $table, $save_row),
+ $html
+ );
+
+ //case 6: PMA_getHtmlForCommonFormFooter
+ $this->assertContains(
+ PMA_getHtmlForCommonFormFooter(),
+ $html
+ );
+ }
+
+ /**
+ * Tests for PMA_getHtmlForDisplayFieldInfos() method.
+ *
+ * @return void
+ * @test
+ */
+ public function testPMAGetHtmlForDisplayFieldInfos()
+ {
+ $db = "pma_db";
+ $table = "pma_table";
+ $save_row = array(
+ array("Field" => "Field1"),
+ array("Field" => "Field2"),
+ );
+
+ $html = PMA_getHtmlForDisplayFieldInfos($db, $table, $save_row);
+
+ $this->assertContains(
+ __('Choose column to display:'),
+ $html
+ );
+ $this->assertContains(
+ htmlspecialchars($save_row[0]['Field']),
+ $html
+ );
+ $this->assertContains(
+ htmlspecialchars($save_row[1]['Field']),
+ $html
+ );
+ }
+
+ /**
+ * Tests for PMA_getQueryForDisplayUpdate() method.
+ *
+ * @return void
+ * @test
+ */
+ public function testPMAGetQueryForDisplayUpdate()
+ {
+ $disp = true;
+ $display_field = '';
+ $db = "pma_db";
+ $table = "pma_table";
+ $cfgRelation = array(
+ 'displaywork' => true,
+ 'relwork' => true,
+ 'displaywork' => true,
+ 'table_info' => 'table_info',
+ );
+
+ $GLOBALS['cfgRelation']['db'] = 'global_db';
+
+ //case 1: $disp == true && $display_field == ''
+ $query = PMA_getQueryForDisplayUpdate(
+ $disp, $display_field, $db, $table, $cfgRelation
+ );
+ $query_expect = "DELETE FROM `global_db`.`table_info` "
+ . "WHERE db_name = 'pma_db' AND table_name = 'pma_table'";
+ $this->assertEquals(
+ $query_expect,
+ $query
+ );
+
+ //case 2: $disp == true && $display_field == 'display_field'
+ $display_field == 'display_field';
+ $query = PMA_getQueryForDisplayUpdate(
+ $disp, $display_field, $db, $table, $cfgRelation
+ );
+ $query_expect = "DELETE FROM `global_db`.`table_info` "
+ . "WHERE db_name = 'pma_db' AND table_name = 'pma_table'";
+ $this->assertEquals(
+ $query_expect,
+ $query
+ );
+
+ //case 3: $disp == false && $display_field == 'display_field'
+ $disp = false;
+ $display_field = 'display_field';
+ $query = PMA_getQueryForDisplayUpdate(
+ $disp, $display_field, $db, $table, $cfgRelation
+ );
+ $query_expect = "INSERT INTO `global_db`.`table_info`"
+ . "(db_name, table_name, display_field)"
+ . " VALUES('pma_db','pma_table','display_field')";
+ $this->assertEquals(
+ $query_expect,
+ $query
+ );
+
+ //case 4: $disp == false && $display_field == ''
+ $disp = false;
+ $display_field = '';
+ $query = PMA_getQueryForDisplayUpdate(
+ $disp, $display_field, $db, $table, $cfgRelation
+ );
+ $query_expect = '';
+ $this->assertEquals(
+ $query_expect,
+ $query
+ );
+ }
+}
+
+/**
+ * Mock class for DataBasePMAMock
+ *
+ * @package PhpMyAdmin-test
+ */
+Class DataBasePMAMockForTblRelation
+{
+ var $databases;
+}
+
+/**
+ * Mock class for DataBaseMock
+ *
+ * @package PhpMyAdmin-test
+ */
+Class DataBaseMockForTblRelation
+{
+ /**
+ * mock function to return table is existed
+ *
+ * @param string $name table name
+ *
+ * @return bool
+ */
+ function exists($name)
+ {
+ return true;
+ }
}
?>
+
Something went wrong with that request. Please try again.