From 7e67b7b79edf5bf6ba548e693cd37ed92ed21b9f Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 13 Sep 2010 19:05:46 +0000 Subject: [PATCH] MDL-19057 more create_table tests for broken structure of table --- lib/ddl/simpletest/testddl.php | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/ddl/simpletest/testddl.php b/lib/ddl/simpletest/testddl.php index efb6c9ae877..ce9e9a071eb 100755 --- a/lib/ddl/simpletest/testddl.php +++ b/lib/ddl/simpletest/testddl.php @@ -275,6 +275,39 @@ class ddl_test extends UnitTestCase { $this->assertEqual($dbrec->name, 'Moodle'); $this->assertEqual($dbrec->thirdname, ''); + // check exceptions if multiple R columns + $table = new xmldb_table ('test_table2'); + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('rid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('rid')); + $table->setComment("This is a test'n drop table. You can drop it safely"); + + $this->tables[$table->getName()] = $table; + + try { + $dbman->create_table($table); + $this->fail('Exception expected'); + } catch (Exception $e) { + $this->assertTrue($e instanceof ddl_exception); + } + + // check exceptions missing primary key on R column + $table = new xmldb_table ('test_table2'); + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0'); + $table->setComment("This is a test'n drop table. You can drop it safely"); + + $this->tables[$table->getName()] = $table; + + try { + $dbman->create_table($table); + $this->fail('Exception expected'); + } catch (Exception $e) { + $this->assertTrue($e instanceof ddl_exception); + } + } /**