]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20734 Changed tests behaviour so insert/update/set_field will be expected to...
authorEloy Lafuente <stronk7@moodle.org>
Tue, 3 Nov 2009 19:53:11 +0000 (19:53 +0000)
committerEloy Lafuente <stronk7@moodle.org>
Tue, 3 Nov 2009 19:53:11 +0000 (19:53 +0000)
empty strings (in numeric columns) to 0

lib/dml/simpletest/testdml.php

index ec03870b8e5c4e5c61802e7b4243c63f4d3385c9..6c5b37b4d1417eb6819330ab0b327d973870e993 100755 (executable)
@@ -1239,23 +1239,22 @@ class dml_test extends UnitTestCase {
             $this->assertTrue($e instanceof dml_exception);
         }
 
-        // Check empty string data causes exception in numeric types
+        // Check empty string data is stored as 0 in numeric datatypes
         $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);
-        }
+        $recid = $DB->insert_record($tablename, $record);
+        $rs = $DB->get_recordset($tablename, array('id' => $recid));
+        $record = $rs->current();
+        $rs->close();
+        $this->assertTrue(is_numeric($record->oneint) && $record->oneint == 0);
+
         $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);
-        }
+        $recid = $DB->insert_record($tablename, $record);
+        $rs = $DB->get_recordset($tablename, array('id' => $recid));
+        $record = $rs->current();
+        $rs->close();
+        $this->assertTrue(is_numeric($record->onenum) && $record->onenum == 0);
 
         // Check empty strings are set properly in string types
         $record->oneint = 0;
@@ -1468,23 +1467,18 @@ class dml_test extends UnitTestCase {
             $this->assertTrue($e instanceof dml_exception);
         }
 
-        // Check empty string data causes exception in numeric types
+        // Check empty string data is stored as 0 in numeric datatypes
         $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);
-        }
+        $DB->update_record($tablename, $record);
+        $record = $DB->get_record($tablename, array('course' => 2));
+        $this->assertTrue(is_numeric($record->oneint) && $record->oneint == 0);
+
         $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);
-        }
+        $DB->update_record($tablename, $record);
+        $record = $DB->get_record($tablename, array('course' => 2));
+        $this->assertTrue(is_numeric($record->onenum) && $record->onenum == 0);
 
         // Check empty strings are set properly in string types
         $record->oneint = 0;
@@ -1642,19 +1636,14 @@ 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 string data is stored as 0 in numeric datatypes
+        $DB->set_field_select($tablename, 'oneint', '', 'id = ?', array(1));
+        $field = $DB->get_field($tablename, 'oneint', array('id' => 1));
+        $this->assertTrue(is_numeric($field) && $field == 0);
+
+        $DB->set_field_select($tablename, 'onenum', '', 'id = ?', array(1));
+        $field = $DB->get_field($tablename, 'onenum', array('id' => 1));
+        $this->assertTrue(is_numeric($field) && $field == 0);
 
         // Check empty strings are set properly in string types
         $DB->set_field_select($tablename, 'onechar', '', 'id = ?', array(1));