summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOliver Gasser <oliver@flowriver.net>2013-12-17 22:46:45 +0100
committerOliver Gasser <oliver@flowriver.net>2014-01-07 16:07:54 +0100
commit6a21922854b0374d4059ea08f4a4606b6b5e2c41 (patch)
tree7924162cb9990df55a7989c8f89b38efe7a112e1 /tests
parent956a4419d8cbe14326ec42fef1e203ca11b170a5 (diff)
downloadnextcloud-server-6a21922854b0374d4059ea08f4a4606b6b5e2c41.tar.gz
nextcloud-server-6a21922854b0374d4059ea08f4a4606b6b5e2c41.zip
DB: Support DECIMAL(precision,scale) syntax in XML
Add support for specifying the precision and scale of a decimal data type to the XML description language. Added new unit tests and adapted existing ones. See owncloud/core#6475 Backported from owncloud/core#6476
Diffstat (limited to 'tests')
-rw-r--r--tests/data/db_structure.xml3
-rw-r--r--tests/data/db_structure2.xml3
-rw-r--r--tests/lib/db.php28
-rw-r--r--tests/lib/db/mdb2schemareader.php5
-rw-r--r--tests/lib/db/testschema.xml6
5 files changed, 42 insertions, 3 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 1977025cf12..432fa415065 100644
--- a/tests/lib/db.php
+++ b/tests/lib/db.php
@@ -25,6 +25,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() {
@@ -145,4 +146,31 @@ class Test_DB extends PHPUnit_Framework_TestCase {
$this->assertEquals(1, $result->numRows());
}
+
+ 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);
+ }
+ }
}
diff --git a/tests/lib/db/mdb2schemareader.php b/tests/lib/db/mdb2schemareader.php
index 57cafa7c76b..f08996cbeaf 100644
--- a/tests/lib/db/mdb2schemareader.php
+++ b/tests/lib/db/mdb2schemareader.php
@@ -39,7 +39,7 @@ class MDB2SchemaReader extends \PHPUnit_Framework_TestCase {
$this->assertCount(1, $schema->getTables());
$table = $schema->getTable('test_table');
- $this->assertCount(7, $table->getColumns());
+ $this->assertCount(8, $table->getColumns());
$this->assertEquals(4, $table->getColumn('integerfield')->getLength());
$this->assertTrue($table->getColumn('integerfield')->getAutoincrement());
@@ -69,6 +69,9 @@ class MDB2SchemaReader extends \PHPUnit_Framework_TestCase {
$this->assertTrue($table->getColumn('booleanfield_true')->getDefault());
$this->assertFalse($table->getColumn('booleanfield_false')->getDefault());
+ $this->assertEquals(12, $table->getColumn('decimalfield_precision_scale')->getPrecision());
+ $this->assertEquals(2, $table->getColumn('decimalfield_precision_scale')->getScale());
+
$this->assertCount(2, $table->getIndexes());
$this->assertEquals(array('integerfield'), $table->getIndex('primary')->getUnquotedColumns());
$this->assertTrue($table->getIndex('primary')->isPrimary());
diff --git a/tests/lib/db/testschema.xml b/tests/lib/db/testschema.xml
index 509b55ee81f..dfca920a0ef 100644
--- a/tests/lib/db/testschema.xml
+++ b/tests/lib/db/testschema.xml
@@ -53,6 +53,12 @@
<type>boolean</type>
<default>false</default>
</field>
+ <field>
+ <name>decimalfield_precision_scale</name>
+ <type>decimal</type>
+ <precision>12</precision>
+ <scale>2</scale>
+ </field>
<index>
<name>index_primary</name>