cvs: pear /MDB2/tests MDB2_reverse_testcase.php
| From: | Lorenzo Alberton | Date: | Wed, 12 Oct 2005 17:10:07 +0000 |
| Subject: | cvs: pear /MDB2/tests MDB2_reverse_testcase.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35460@lists.php.net to get a copy of this message | ||
quipo Wed Oct 12 13:10:07 2005 EDT
Modified files:
/pear/MDB2/tests MDB2_reverse_testcase.php
Log:
added test for getTableIndexDefinition() [the setup method may need a refactoring]
http://cvs.php.net/diff.php/pear/MDB2/tests/MDB2_reverse_testcase.php?r1=1.11&r2=1.12&ty=u
Index: pear/MDB2/tests/MDB2_reverse_testcase.php
diff -u pear/MDB2/tests/MDB2_reverse_testcase.php:1.11
pear/MDB2/tests/MDB2_reverse_testcase.php:1.12
--- pear/MDB2/tests/MDB2_reverse_testcase.php:1.11 Wed Oct 12 10:36:28 2005
+++ pear/MDB2/tests/MDB2_reverse_testcase.php Wed Oct 12 13:10:07 2005
@@ -41,7 +41,7 @@
// | Author: Lorenzo Alberton <l dot alberton at quipo dot it> |
// +----------------------------------------------------------------------+
//
-// $Id: MDB2_reverse_testcase.php,v 1.11 2005/10/12 14:36:28 quipo Exp $
+// $Id: MDB2_reverse_testcase.php,v 1.12 2005/10/12 17:10:07 quipo Exp $
class MDB2_Reverse_TestCase extends PHPUnit_TestCase
{
@@ -74,15 +74,15 @@
$this->db->setDatabase($this->database);
$this->db->loadModule('Reverse');
$this->fields = array(
- 'user_name' => 'text',
+ 'user_name' => 'text',
'user_password' => 'text',
- 'subscribed' => 'boolean',
- 'user_id' => 'integer',
- 'quota' => 'decimal',
- 'weight' => 'float',
- 'access_date' => 'date',
- 'access_time' => 'time',
- 'approved' => 'timestamp',
+ 'subscribed' => 'boolean',
+ 'user_id' => 'integer',
+ 'quota' => 'decimal',
+ 'weight' => 'float',
+ 'access_date' => 'date',
+ 'access_time' => 'time',
+ 'approved' => 'timestamp',
);
}
@@ -104,6 +104,11 @@
return false;
}
+ function tableExists($table) {
+ $tables = $this->db->manager->listTables();
+ return in_array($table, $tables);
+ }
+
/**
* Test tableInfo('table_name')
*/
@@ -172,5 +177,92 @@
$this->assertEquals('', $field_info['default'], 'The field
default value is different from the expected one');
}
}
+
+ /**
+ * Test getTableIndexDefinition($table, $index)
+ */
+ function testGetTableIndexDefinition()
+ {
+ if (!$this->methodExists($this->db->reverse, 'getTableIndexDefinition'))
{
+ return;
+ }
+
+ //setup
+ $this->db->loadModule('Manager');
+ $fields = array(
+ 'id' => array(
+ 'type' => 'integer',
+ 'unsigned' => 1,
+ 'notnull' => 1,
+ 'default' => 0,
+ ),
+ 'name' => array(
+ 'type' => 'text',
+ 'length' => 12,
+ ),
+ 'description' => array(
+ 'type' => 'text',
+ 'length' => 12,
+ ),
+ 'sex' => array(
+ 'type' => 'text',
+ 'length' => 1,
+ 'default' => 'M',
+ ),
+ );
+ $table = 'newtable';
+ if ($this->tableExists($table)) {
+ $result = $this->db->manager->dropTable($table);
+ $this->assertFalse(PEAR::isError($result), 'Error dropping table');
+ }
+ $result = $this->db->manager->createTable($table, $fields);
+ $this->assertFalse(PEAR::isError($result), 'Error creating table');
+ $indices = array(
+ 'uniqueindex' => array(
+ 'fields' => array(
+ 'name' => array(
+ 'sorting' => 'ascending',
+ ),
+ ),
+ 'unique' => true,
+ ),
+ 'pkindex' => array(
+ 'fields' => array(
+ 'id' => array(
+ 'sorting' => 'ascending',
+ ),
+ ),
+ 'primary' => true,
+ ),
+ 'multipleindex' => array(
+ 'fields' => array(
+ 'description' => array(
+ 'sorting' => 'ascending',
+ ),
+ 'sex' => array(
+ 'sorting' => 'ascending',
+ ),
+ ),
+ ),
+ );
+ foreach ($indices as $index_name => $index) {
+ $result = $this->db->manager->createIndex($table, $index_name, $index);
+ $this->assertFalse(PEAR::isError($result), 'Error creating index');
+ }
+
+ //test
+ foreach ($indices as $index_name => $index) {
+ $result = $this->db->reverse->getTableIndexDefinition($table, $index_name);
+ $this->assertFalse(PEAR::isError($result), 'Error getting table index
definition');
+ $field_names = array_keys($index['fields']);
+ $this->assertEquals($field_names, array_keys($result['fields']),
'Error listing index fields');
+ if (!empty($index['unique'])) {
+ $this->assertTrue($result['unique'], 'Error: missing UNIQUE
constraint');
+ }
+ if (!empty($index['primary'])) {
+ $this->assertTrue($result['primary'], 'Error: missing PRIMARY KEY
constraint');
+ }
+ }
+ }
}
?>
\ No newline at end of file