diff options
author | Oliver Gasser <oliver@flowriver.net> | 2013-12-18 23:40:11 +0100 |
---|---|---|
committer | Oliver Gasser <oliver@flowriver.net> | 2013-12-18 23:40:11 +0100 |
commit | cacb66480b4bebc8511842bcc588ffd750ef0c38 (patch) | |
tree | b7871ce1892b6c443fa87c35a0b34857ecdd212c /tests | |
parent | f0962c99dcebdb1d58033eb1b33d57cf48d88bf7 (diff) | |
download | nextcloud-server-cacb66480b4bebc8511842bcc588ffd750ef0c38.tar.gz nextcloud-server-cacb66480b4bebc8511842bcc588ffd750ef0c38.zip |
Add unit tests for decimal type usage
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/db_structure.xml | 3 | ||||
-rw-r--r-- | tests/data/db_structure2.xml | 3 | ||||
-rw-r--r-- | tests/lib/db.php | 29 |
3 files changed, 33 insertions, 2 deletions
diff --git a/tests/data/db_structure.xml b/tests/data/db_structure.xml index 5f2edbbc516..bfff2143349 100644 --- a/tests/data/db_structure.xml +++ b/tests/data/db_structure.xml @@ -216,7 +216,8 @@ <type>decimal</type> <default/> <notnull>true</notnull> - <length>15</length> + <precision>12</precision> + <scale>2</scale> </field> </declaration> </table> diff --git a/tests/data/db_structure2.xml b/tests/data/db_structure2.xml index 6cd071451df..ae5f22e9573 100644 --- a/tests/data/db_structure2.xml +++ b/tests/data/db_structure2.xml @@ -113,7 +113,8 @@ <type>decimal</type> <default/> <notnull>true</notnull> - <length>15</length> + <precision>12</precision> + <scale>2</scale> </field> </declaration> </table> diff --git a/tests/lib/db.php b/tests/lib/db.php index 3fcdf8a7dc6..96d5f873b5c 100644 --- a/tests/lib/db.php +++ b/tests/lib/db.php @@ -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); + } + } + } |