Skip to content

Commit

Permalink
NOBUG: Added some tests with empty strings in insert_record/update_re…
Browse files Browse the repository at this point in the history
…cord/set_field

that reveal inconsistencies between DBs
  • Loading branch information
stronk7 committed Nov 3, 2009
1 parent 86449d2 commit fdc45ac
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/dml/simpletest/testdml.php
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,24 @@ public function test_insert_record() {
$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;
Expand Down Expand Up @@ -1450,6 +1468,24 @@ public function test_update_record() {
$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;
Expand Down Expand Up @@ -1606,6 +1642,20 @@ public function test_set_field_select() {
$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));
Expand Down

0 comments on commit fdc45ac

Please sign in to comment.