]> git.mjollnir.org Git - moodle.git/commitdiff
NOBUG: Added some tests with empty strings in insert_record/update_record/set_field
authorEloy Lafuente <stronk7@moodle.org>
Tue, 3 Nov 2009 18:11:18 +0000 (18:11 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Tue, 3 Nov 2009 18:11:18 +0000 (18:11 +0000)
that reveal inconsistencies between DBs

lib/dml/simpletest/testdml.php

index 333e942f538d533533381fd7f7946c3839014247..ec03870b8e5c4e5c61802e7b4243c63f4d3385c9 100755 (executable)
@@ -1239,6 +1239,24 @@ class dml_test extends UnitTestCase {
             $this->assertTrue($e instanceof dml_exception);
         }
 
+        // Check empty string data causes exception in numeric types
+        $record->oneint = ''; // empty string
+        $record->onenum = 0;
+        try {
+            $DB->insert_record($tablename, $record);
+            $this->fail("Expecting an exception, none occurred");
+        } catch (exception $e) {
+            $this->assertTrue($e instanceof dml_exception);
+        }
+        $record->oneint = 0;
+        $record->onenum = ''; // empty string
+        try {
+           $DB->insert_record($tablename, $record);
+           $this->fail("Expecting an exception, none occurred");
+        } catch (exception $e) {
+            $this->assertTrue($e instanceof dml_exception);
+        }
+
         // Check empty strings are set properly in string types
         $record->oneint = 0;
         $record->onenum = 0;
@@ -1450,6 +1468,24 @@ class dml_test extends UnitTestCase {
             $this->assertTrue($e instanceof dml_exception);
         }
 
+        // Check empty string data causes exception in numeric types
+        $record->oneint = ''; // empty string
+        $record->onenum = 0;
+        try {
+            $DB->update_record($tablename, $record);
+            $this->fail("Expecting an exception, none occurred");
+        } catch (exception $e) {
+            $this->assertTrue($e instanceof dml_exception);
+        }
+        $record->oneint = 0;
+        $record->onenum = ''; // empty string
+        try {
+            $DB->update_record($tablename, $record);
+            $this->fail("Expecting an exception, none occurred");
+        } catch (exception $e) {
+            $this->assertTrue($e instanceof dml_exception);
+        }
+
         // Check empty strings are set properly in string types
         $record->oneint = 0;
         $record->onenum = 0;
@@ -1606,6 +1642,20 @@ class dml_test extends UnitTestCase {
             $this->assertTrue($e instanceof dml_exception);
         }
 
+        // Check empty string data causes exception in numeric types
+        try {
+            $DB->set_field_select($tablename, 'oneint', '', 'id = ?', array(1));
+            $this->fail("Expecting an exception, none occurred");
+        } catch (exception $e) {
+            $this->assertTrue($e instanceof dml_exception);
+        }
+        try {
+            $DB->set_field_select($tablename, 'onenum', '', 'id = ?', array(1));
+            $this->fail("Expecting an exception, none occurred");
+        } catch (exception $e) {
+            $this->assertTrue($e instanceof dml_exception);
+        }
+
         // Check empty strings are set properly in string types
         $DB->set_field_select($tablename, 'onechar', '', 'id = ?', array(1));
         $DB->set_field_select($tablename, 'onetext', '', 'id = ?', array(1));