MDL-30147 dml - added some tests demoing bad get_columns() behavior
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Sat, 12 Nov 2011 19:47:42 +0000 (20:47 +0100)
committerPetr Skoda <commits@skodak.org>
Sat, 19 Nov 2011 08:27:09 +0000 (09:27 +0100)
lib/dml/simpletest/testdml.php

index 802b68f..d6298a8 100644 (file)
@@ -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()
     }