Permalink
Browse files

MDL-27325 Now also testing update_record and set_field

  • Loading branch information...
1 parent 280a641 commit 15516e644592741386a90f6eb55d8779cd098ae1 @stronk7 stronk7 committed May 5, 2011
Showing with 43 additions and 0 deletions.
  1. +43 −0 lib/dml/simpletest/testdml.php
View
43 lib/dml/simpletest/testdml.php
@@ -2118,6 +2118,27 @@ public function test_update_record() {
$this->assertEqual($newclob, $record->onetext, 'Test "small" CLOB update (full contents output disabled)');
$this->assertEqual($newblob, $record->onebinary, 'Test "small" BLOB update (full contents output disabled)');
+ // Test saving a float in a CHAR column, and reading it back.
+ $id = $DB->insert_record($tablename, array('onechar' => 'X'));
+ $DB->update_record($tablename, array('id' => $id, 'onechar' => 1.0));
+ $this->assertEqual(1.0, $DB->get_field($tablename, 'onechar', array('id' => $id)));
+ $DB->update_record($tablename, array('id' => $id, 'onechar' => 1e20));
+ $this->assertEqual(1e20, $DB->get_field($tablename, 'onechar', array('id' => $id)));
+ $DB->update_record($tablename, array('id' => $id, 'onechar' => 1e-4));
+ $this->assertEqual(1e-4, $DB->get_field($tablename, 'onechar', array('id' => $id)));
+ $DB->update_record($tablename, array('id' => $id, 'onechar' => 1e-5));
+ $this->assertEqual(1e-5, $DB->get_field($tablename, 'onechar', array('id' => $id)));
+
+ // Test saving a float in a TEXT column, and reading it back.
+ $id = $DB->insert_record($tablename, array('onetext' => 'X'));
+ $DB->update_record($tablename, array('id' => $id, 'onetext' => 1.0));
+ $this->assertEqual(1.0, $DB->get_field($tablename, 'onetext', array('id' => $id)));
+ $DB->update_record($tablename, array('id' => $id, 'onetext' => 1e20));
+ $this->assertEqual(1e20, $DB->get_field($tablename, 'onetext', array('id' => $id)));
+ $DB->update_record($tablename, array('id' => $id, 'onetext' => 1e-4));
+ $this->assertEqual(1e-4, $DB->get_field($tablename, 'onetext', array('id' => $id)));
+ $DB->update_record($tablename, array('id' => $id, 'onetext' => 1e-5));
+ $this->assertEqual(1e-5, $DB->get_field($tablename, 'onetext', array('id' => $id)));
}
public function test_set_field() {
@@ -2183,6 +2204,28 @@ public function test_set_field() {
$this->assertEqual($e->errorcode, 'textconditionsnotallowed');
}
+ // Test saving a float in a CHAR column, and reading it back.
+ $id = $DB->insert_record($tablename, array('onechar' => 'X'));
+ $DB->set_field($tablename, 'onechar', 1.0, array('id' => $id));
+ $this->assertEqual(1.0, $DB->get_field($tablename, 'onechar', array('id' => $id)));
+ $DB->set_field($tablename, 'onechar', 1e20, array('id' => $id));
+ $this->assertEqual(1e20, $DB->get_field($tablename, 'onechar', array('id' => $id)));
+ $DB->set_field($tablename, 'onechar', 1e-4, array('id' => $id));
+ $this->assertEqual(1e-4, $DB->get_field($tablename, 'onechar', array('id' => $id)));
+ $DB->set_field($tablename, 'onechar', 1e-5, array('id' => $id));
+ $this->assertEqual(1e-5, $DB->get_field($tablename, 'onechar', array('id' => $id)));
+
+ // Test saving a float in a TEXT column, and reading it back.
+ $id = $DB->insert_record($tablename, array('onetext' => 'X'));
+ $DB->set_field($tablename, 'onetext', 1.0, array('id' => $id));
+ $this->assertEqual(1.0, $DB->get_field($tablename, 'onetext', array('id' => $id)));
+ $DB->set_field($tablename, 'onetext', 1e20, array('id' => $id));
+ $this->assertEqual(1e20, $DB->get_field($tablename, 'onetext', array('id' => $id)));
+ $DB->set_field($tablename, 'onetext', 1e-4, array('id' => $id));
+ $this->assertEqual(1e-4, $DB->get_field($tablename, 'onetext', array('id' => $id)));
+ $DB->set_field($tablename, 'onetext', 1e-5, array('id' => $id));
+ $this->assertEqual(1e-5, $DB->get_field($tablename, 'onetext', array('id' => $id)));
+
// Note: All the nulls, booleans, empties, quoted and backslashes tests
// go to set_field_select() because set_field() is just one wrapper over it
}

0 comments on commit 15516e6

Please sign in to comment.