Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-27325 Now also testing update_record and set_field

  • Loading branch information...
commit 15516e644592741386a90f6eb55d8779cd098ae1 1 parent 280a641
Eloy Lafuente (stronk7) stronk7 authored

Showing 1 changed file with 43 additions and 0 deletions. Show diff stats Hide diff stats

  1. +43 0 lib/dml/simpletest/testdml.php
43 lib/dml/simpletest/testdml.php
@@ -2118,6 +2118,27 @@ public function test_update_record() {
2118 2118 $this->assertEqual($newclob, $record->onetext, 'Test "small" CLOB update (full contents output disabled)');
2119 2119 $this->assertEqual($newblob, $record->onebinary, 'Test "small" BLOB update (full contents output disabled)');
2120 2120
  2121 + // Test saving a float in a CHAR column, and reading it back.
  2122 + $id = $DB->insert_record($tablename, array('onechar' => 'X'));
  2123 + $DB->update_record($tablename, array('id' => $id, 'onechar' => 1.0));
  2124 + $this->assertEqual(1.0, $DB->get_field($tablename, 'onechar', array('id' => $id)));
  2125 + $DB->update_record($tablename, array('id' => $id, 'onechar' => 1e20));
  2126 + $this->assertEqual(1e20, $DB->get_field($tablename, 'onechar', array('id' => $id)));
  2127 + $DB->update_record($tablename, array('id' => $id, 'onechar' => 1e-4));
  2128 + $this->assertEqual(1e-4, $DB->get_field($tablename, 'onechar', array('id' => $id)));
  2129 + $DB->update_record($tablename, array('id' => $id, 'onechar' => 1e-5));
  2130 + $this->assertEqual(1e-5, $DB->get_field($tablename, 'onechar', array('id' => $id)));
  2131 +
  2132 + // Test saving a float in a TEXT column, and reading it back.
  2133 + $id = $DB->insert_record($tablename, array('onetext' => 'X'));
  2134 + $DB->update_record($tablename, array('id' => $id, 'onetext' => 1.0));
  2135 + $this->assertEqual(1.0, $DB->get_field($tablename, 'onetext', array('id' => $id)));
  2136 + $DB->update_record($tablename, array('id' => $id, 'onetext' => 1e20));
  2137 + $this->assertEqual(1e20, $DB->get_field($tablename, 'onetext', array('id' => $id)));
  2138 + $DB->update_record($tablename, array('id' => $id, 'onetext' => 1e-4));
  2139 + $this->assertEqual(1e-4, $DB->get_field($tablename, 'onetext', array('id' => $id)));
  2140 + $DB->update_record($tablename, array('id' => $id, 'onetext' => 1e-5));
  2141 + $this->assertEqual(1e-5, $DB->get_field($tablename, 'onetext', array('id' => $id)));
2121 2142 }
2122 2143
2123 2144 public function test_set_field() {
@@ -2183,6 +2204,28 @@ public function test_set_field() {
2183 2204 $this->assertEqual($e->errorcode, 'textconditionsnotallowed');
2184 2205 }
2185 2206
  2207 + // Test saving a float in a CHAR column, and reading it back.
  2208 + $id = $DB->insert_record($tablename, array('onechar' => 'X'));
  2209 + $DB->set_field($tablename, 'onechar', 1.0, array('id' => $id));
  2210 + $this->assertEqual(1.0, $DB->get_field($tablename, 'onechar', array('id' => $id)));
  2211 + $DB->set_field($tablename, 'onechar', 1e20, array('id' => $id));
  2212 + $this->assertEqual(1e20, $DB->get_field($tablename, 'onechar', array('id' => $id)));
  2213 + $DB->set_field($tablename, 'onechar', 1e-4, array('id' => $id));
  2214 + $this->assertEqual(1e-4, $DB->get_field($tablename, 'onechar', array('id' => $id)));
  2215 + $DB->set_field($tablename, 'onechar', 1e-5, array('id' => $id));
  2216 + $this->assertEqual(1e-5, $DB->get_field($tablename, 'onechar', array('id' => $id)));
  2217 +
  2218 + // Test saving a float in a TEXT column, and reading it back.
  2219 + $id = $DB->insert_record($tablename, array('onetext' => 'X'));
  2220 + $DB->set_field($tablename, 'onetext', 1.0, array('id' => $id));
  2221 + $this->assertEqual(1.0, $DB->get_field($tablename, 'onetext', array('id' => $id)));
  2222 + $DB->set_field($tablename, 'onetext', 1e20, array('id' => $id));
  2223 + $this->assertEqual(1e20, $DB->get_field($tablename, 'onetext', array('id' => $id)));
  2224 + $DB->set_field($tablename, 'onetext', 1e-4, array('id' => $id));
  2225 + $this->assertEqual(1e-4, $DB->get_field($tablename, 'onetext', array('id' => $id)));
  2226 + $DB->set_field($tablename, 'onetext', 1e-5, array('id' => $id));
  2227 + $this->assertEqual(1e-5, $DB->get_field($tablename, 'onetext', array('id' => $id)));
  2228 +
2186 2229 // Note: All the nulls, booleans, empties, quoted and backslashes tests
2187 2230 // go to set_field_select() because set_field() is just one wrapper over it
2188 2231 }

0 comments on commit 15516e6

Please sign in to comment.
Something went wrong with that request. Please try again.