]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add unit tests for decimal type usage
authorOliver Gasser <oliver@flowriver.net>
Wed, 18 Dec 2013 22:40:11 +0000 (23:40 +0100)
committerOliver Gasser <oliver@flowriver.net>
Wed, 18 Dec 2013 22:40:11 +0000 (23:40 +0100)
tests/data/db_structure.xml
tests/data/db_structure2.xml
tests/lib/db.php

index 5f2edbbc5160ff4a8282ff4ddb7e6c125b9368e9..bfff214334933c7626d798f61ed5d1fc25727057 100644 (file)
     <type>decimal</type>
     <default/>
     <notnull>true</notnull>
-    <length>15</length>
+    <precision>12</precision>
+    <scale>2</scale>
    </field>
   </declaration>
  </table>
index 6cd071451df58072840b8daa7e933b9fd5a104e6..ae5f22e957344d60c37cd0cfaf7790632cdd2322 100644 (file)
     <type>decimal</type>
     <default/>
     <notnull>true</notnull>
-    <length>15</length>
+    <precision>12</precision>
+    <scale>2</scale>
    </field>
   </declaration>
  </table>
index 3fcdf8a7dc654cd968f7559ce1e7797c3b58cc7d..96d5f873b5c0c3dbdb63998d1962c5954241db0e 100644 (file)
@@ -40,6 +40,7 @@ class Test_DB extends PHPUnit_Framework_TestCase {
                $this->table1 = $this->test_prefix.'cntcts_addrsbks';
                $this->table2 = $this->test_prefix.'cntcts_cards';
                $this->table3 = $this->test_prefix.'vcategory';
+               $this->table4 = $this->test_prefix.'decimal';
        }
 
        public function tearDown() {
@@ -172,4 +173,32 @@ class Test_DB extends PHPUnit_Framework_TestCase {
                $actual = OC_DB::prepare("SELECT `fullname` FROM `$table`")->execute()->fetchOne();
                $this->assertSame($expected, $actual);
        }
+
+       public function testDecimal() {
+               $table = "*PREFIX*" . $this->table4;
+               $rowname = 'decimaltest';
+
+               // Insert, select and delete decimal(12,2) values
+               $inserts = array('1337133713.37', '1234567890');
+               $expects = array('1337133713.37', '1234567890.00');
+
+               for ($i = 0; $i < count($inserts); $i++) {
+                       $insert = $inserts[$i];
+                       $expect = $expects[$i];
+
+                       $query = OC_DB::prepare('INSERT INTO `' . $table . '` (`' . $rowname . '`) VALUES (?)');
+                       $result = $query->execute(array($insert));
+                       $this->assertEquals(1, $result);
+                       $query = OC_DB::prepare('SELECT `' . $rowname . '` FROM `' . $table . '`');
+                       $result = $query->execute();
+                       $this->assertTrue((bool)$result);
+                       $row = $result->fetchRow();
+                       $this->assertArrayHasKey($rowname, $row);
+                       $this->assertEquals($expect, $row[$rowname]);
+                       $query = OC_DB::prepare('DELETE FROM `' . $table . '`');
+                       $result = $query->execute();
+                       $this->assertTrue((bool)$result);
+               }
+       }
+
 }