From: Oliver Gasser Date: Wed, 18 Dec 2013 22:40:11 +0000 (+0100) Subject: Add unit tests for decimal type usage X-Git-Tag: v7.0.0alpha2~1010^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cacb66480b4bebc8511842bcc588ffd750ef0c38;p=nextcloud-server.git Add unit tests for decimal type usage --- 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 @@ decimal true - 15 + 12 + 2 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 @@ decimal true - 15 + 12 + 2 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); + } + } + }