From fdc45ac360f33a8e6a20776e480fc21c33f1ebc3 Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Tue, 3 Nov 2009 18:11:18 +0000 Subject: [PATCH] NOBUG: Added some tests with empty strings in insert_record/update_record/set_field that reveal inconsistencies between DBs --- lib/dml/simpletest/testdml.php | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/lib/dml/simpletest/testdml.php b/lib/dml/simpletest/testdml.php index 333e942f53..ec03870b8e 100755 --- a/lib/dml/simpletest/testdml.php +++ b/lib/dml/simpletest/testdml.php @@ -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)); -- 2.39.5