From 8f201c9deda46f8f2fcebfbc45fdf66d20b67db0 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sat, 12 Nov 2011 20:47:42 +0100 Subject: [PATCH] MDL-30147 dml - added some tests demoing bad get_columns() behavior --- lib/dml/simpletest/testdml.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/dml/simpletest/testdml.php b/lib/dml/simpletest/testdml.php index 802b68f9223..d6298a847af 100644 --- a/lib/dml/simpletest/testdml.php +++ b/lib/dml/simpletest/testdml.php @@ -821,6 +821,10 @@ class dml_test extends UnitTestCase { $this->assertEqual($next_column->name, $next_field->name); } + + // Test get_columns for non-existing table returns empty array. MDL-30147 + $columns = $DB->get_columns('xxxx'); + $this->assertEqual(array(), $columns); } public function test_get_manager() { @@ -1262,6 +1266,24 @@ class dml_test extends UnitTestCase { $this->assertEqual($e->errorcode, 'textconditionsnotallowed'); } + // test get_records passing non-existing table + try { + $records = $DB->get_records('xxxx', array('id' => 0)); + $this->fail('An Exception is missing, expected due to query against non-existing table'); + } catch (exception $e) { + $this->assertTrue($e instanceof dml_exception); + $this->assertEqual($e->errorcode, 'ddltablenotexist'); + } + + // test get_records passing non-existing column + try { + $records = $DB->get_records($tablename, array('xxxx' => 0)); + $this->fail('An Exception is missing, expected due to query against non-existing column'); + } catch (exception $e) { + $this->assertTrue($e instanceof dml_exception); + $this->assertEqual($e->errorcode, 'ddlfieldnotexist'); + } + // note: delegate limits testing to test_get_records_sql() }