diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2020-11-11 10:05:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-11 10:05:24 +0100 |
commit | e39d657e24263c0eac8f1a995923305cd59cde7c (patch) | |
tree | 8d8c52c7b2d4495b3b445ebed3e974a7c4fc3817 /tests | |
parent | cdfad9aaacf89885a4fd29ed002f998dfc269b15 (diff) | |
parent | 0c695d97ece66d50d4a131205cf724ed49e8152a (diff) | |
download | nextcloud-server-e39d657e24263c0eac8f1a995923305cd59cde7c.tar.gz nextcloud-server-e39d657e24263c0eac8f1a995923305cd59cde7c.zip |
Merge pull request #23882 from nextcloud/tests/oracle
Run unit tests against oracle
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/AppConfigTest.php | 5 | ||||
-rw-r--r-- | tests/lib/DB/ConnectionTest.php | 47 | ||||
-rw-r--r-- | tests/lib/DB/MDB2SchemaReaderTest.php | 30 | ||||
-rw-r--r-- | tests/lib/DB/testschema.xml | 20 |
4 files changed, 77 insertions, 25 deletions
diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php index ff23454eb8b..40a99709bd5 100644 --- a/tests/lib/AppConfigTest.php +++ b/tests/lib/AppConfigTest.php @@ -9,6 +9,7 @@ namespace Test; +use OC\AppConfig; use OCP\IConfig; /** @@ -42,7 +43,7 @@ class AppConfigTest extends TestCase { $sql->delete('appconfig'); $sql->execute(); - $this->overwriteService('AppConfig', new \OC\AppConfig($this->connection)); + $this->overwriteService(AppConfig::class, new \OC\AppConfig($this->connection)); $sql = $this->connection->getQueryBuilder(); $sql->insert('appconfig') @@ -132,7 +133,7 @@ class AppConfigTest extends TestCase { $sql->execute(); } - $this->restoreService('AppConfig'); + $this->restoreService(AppConfig::class); parent::tearDown(); } diff --git a/tests/lib/DB/ConnectionTest.php b/tests/lib/DB/ConnectionTest.php index be84cb81cb3..cab6133c3c0 100644 --- a/tests/lib/DB/ConnectionTest.php +++ b/tests/lib/DB/ConnectionTest.php @@ -97,14 +97,17 @@ class ConnectionTest extends \Test\TestCase { $this->assertTableNotExist('table'); } - private function getTextValueByIntergerField($integerField) { + private function getTextValueByIntegerField($integerField) { $builder = $this->connection->getQueryBuilder(); - $query = $builder->select('textfield') + $query = $builder->select('*') ->from('table') ->where($builder->expr()->eq('integerfield', $builder->createNamedParameter($integerField, IQueryBuilder::PARAM_INT))); $result = $query->execute(); - return $result->fetchColumn(); + $row = $result->fetch(); + $result->closeCursor(); + + return $row['textfield'] ?? null; } public function testSetValues() { @@ -116,7 +119,7 @@ class ConnectionTest extends \Test\TestCase { 'clobfield' => 'not_null' ]); - $this->assertEquals('foo', $this->getTextValueByIntergerField(1)); + $this->assertEquals('foo', $this->getTextValueByIntegerField(1)); } public function testSetValuesOverWrite() { @@ -133,7 +136,7 @@ class ConnectionTest extends \Test\TestCase { 'textfield' => 'bar' ]); - $this->assertEquals('bar', $this->getTextValueByIntergerField(1)); + $this->assertEquals('bar', $this->getTextValueByIntegerField(1)); } public function testSetValuesOverWritePrecondition() { @@ -154,7 +157,7 @@ class ConnectionTest extends \Test\TestCase { 'booleanfield' => true ]); - $this->assertEquals('bar', $this->getTextValueByIntergerField(1)); + $this->assertEquals('bar', $this->getTextValueByIntegerField(1)); } @@ -200,6 +203,10 @@ class ConnectionTest extends \Test\TestCase { } public function testInsertIfNotExist() { + if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') { + self::markTestSkipped('Insert if not exist does not work with clob on oracle'); + } + $this->makeTestTable(); $categoryEntries = [ ['user' => 'test', 'category' => 'Family', 'expectedResult' => 1], @@ -213,13 +220,15 @@ class ConnectionTest extends \Test\TestCase { ['user' => 'test2', 'category' => 'Coworkers', 'expectedResult' => 1], ]; + $row = 0; foreach ($categoryEntries as $entry) { $result = $this->connection->insertIfNotExist('*PREFIX*table', [ 'textfield' => $entry['user'], 'clobfield' => $entry['category'], - ]); - $this->assertEquals($entry['expectedResult'], $result); + 'integerfield' => $row++, + ], ['textfield', 'clobfield']); + $this->assertEquals($entry['expectedResult'], $result, json_encode($entry)); } $query = $this->connection->prepare('SELECT * FROM `*PREFIX*table`'); @@ -229,6 +238,10 @@ class ConnectionTest extends \Test\TestCase { } public function testInsertIfNotExistNull() { + if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') { + self::markTestSkipped('Insert if not exist does not work with clob on oracle'); + } + $this->makeTestTable(); $categoryEntries = [ ['addressbookid' => 123, 'fullname' => null, 'expectedResult' => 1], @@ -236,13 +249,15 @@ class ConnectionTest extends \Test\TestCase { ['addressbookid' => 123, 'fullname' => 'test', 'expectedResult' => 1], ]; + $row = 0; foreach ($categoryEntries as $entry) { $result = $this->connection->insertIfNotExist('*PREFIX*table', [ 'integerfield_default' => $entry['addressbookid'], 'clobfield' => $entry['fullname'], - ]); - $this->assertEquals($entry['expectedResult'], $result); + 'integerfield' => $row++, + ], ['integerfield_default', 'clobfield']); + $this->assertEquals($entry['expectedResult'], $result, json_encode($entry)); } $query = $this->connection->prepare('SELECT * FROM `*PREFIX*table`'); @@ -252,6 +267,10 @@ class ConnectionTest extends \Test\TestCase { } public function testInsertIfNotExistDonTOverwrite() { + if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') { + self::markTestSkipped('Insert if not exist does not work with clob on oracle'); + } + $this->makeTestTable(); $fullName = 'fullname test'; $uri = 'uri_1'; @@ -288,6 +307,10 @@ class ConnectionTest extends \Test\TestCase { } public function testInsertIfNotExistsViolating() { + if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') { + self::markTestSkipped('Insert if not exist does not work with clob on oracle'); + } + $this->makeTestTable(); $result = $this->connection->insertIfNotExist('*PREFIX*table', [ @@ -318,6 +341,10 @@ class ConnectionTest extends \Test\TestCase { * @param array $compareKeys */ public function testInsertIfNotExistsViolatingUnique($compareKeys) { + if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') === 'oci') { + self::markTestSkipped('Insert if not exist does not work with clob on oracle'); + } + $this->makeTestTable(); $result = $this->connection->insertIfNotExist('*PREFIX*table', [ diff --git a/tests/lib/DB/MDB2SchemaReaderTest.php b/tests/lib/DB/MDB2SchemaReaderTest.php index c57b0f22b6f..b3dd98fd6b7 100644 --- a/tests/lib/DB/MDB2SchemaReaderTest.php +++ b/tests/lib/DB/MDB2SchemaReaderTest.php @@ -14,6 +14,10 @@ use Doctrine\DBAL\Schema\Schema; use OC\DB\MDB2SchemaReader; use OCP\IConfig; use Test\TestCase; +use Doctrine\DBAL\Types\IntegerType; +use Doctrine\DBAL\Types\TextType; +use Doctrine\DBAL\Types\StringType; +use Doctrine\DBAL\Types\BooleanType; /** * Class MDB2SchemaReaderTest @@ -51,13 +55,13 @@ class MDB2SchemaReaderTest extends TestCase { $this->assertCount(1, $schema->getTables()); $table = $schema->getTable('test_table'); - $this->assertCount(8, $table->getColumns()); + $this->assertCount(9, $table->getColumns()); - $this->assertEquals(4, $table->getColumn('integerfield')->getLength()); - $this->assertTrue($table->getColumn('integerfield')->getAutoincrement()); - $this->assertEquals(0, $table->getColumn('integerfield')->getDefault()); - $this->assertTrue($table->getColumn('integerfield')->getNotnull()); - $this->assertInstanceOf('Doctrine\DBAL\Types\IntegerType', $table->getColumn('integerfield')->getType()); + $this->assertEquals(4, $table->getColumn('id')->getLength()); + $this->assertTrue($table->getColumn('id')->getAutoincrement()); + $this->assertEquals(0, $table->getColumn('id')->getDefault()); + $this->assertTrue($table->getColumn('id')->getNotnull()); + $this->assertInstanceOf(IntegerType::class, $table->getColumn('id')->getType()); $this->assertSame(10, $table->getColumn('integerfield_default')->getDefault()); @@ -65,18 +69,19 @@ class MDB2SchemaReaderTest extends TestCase { $this->assertFalse($table->getColumn('textfield')->getAutoincrement()); $this->assertSame('foo', $table->getColumn('textfield')->getDefault()); $this->assertTrue($table->getColumn('textfield')->getNotnull()); - $this->assertInstanceOf('Doctrine\DBAL\Types\StringType', $table->getColumn('textfield')->getType()); + $this->assertInstanceOf(StringType::class, $table->getColumn('textfield')->getType()); $this->assertNull($table->getColumn('clobfield')->getLength()); $this->assertFalse($table->getColumn('clobfield')->getAutoincrement()); $this->assertNull($table->getColumn('clobfield')->getDefault()); $this->assertFalse($table->getColumn('clobfield')->getNotnull()); - $this->assertInstanceOf('Doctrine\DBAL\Types\TextType', $table->getColumn('clobfield')->getType()); + $this->assertInstanceOf(StringType::class, $table->getColumn('clobfield')->getType()); +// $this->assertInstanceOf(TextType::class, $table->getColumn('clobfield')->getType()); $this->assertNull($table->getColumn('booleanfield')->getLength()); $this->assertFalse($table->getColumn('booleanfield')->getAutoincrement()); $this->assertNull($table->getColumn('booleanfield')->getDefault()); - $this->assertInstanceOf('Doctrine\DBAL\Types\BooleanType', $table->getColumn('booleanfield')->getType()); + $this->assertInstanceOf(BooleanType::class, $table->getColumn('booleanfield')->getType()); $this->assertTrue($table->getColumn('booleanfield_true')->getDefault()); $this->assertFalse($table->getColumn('booleanfield_false')->getDefault()); @@ -84,10 +89,13 @@ class MDB2SchemaReaderTest extends TestCase { $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(['integerfield'], $table->getIndex('primary')->getUnquotedColumns()); + $this->assertCount(3, $table->getIndexes()); + $this->assertEquals(['id'], $table->getIndex('primary')->getUnquotedColumns()); $this->assertTrue($table->getIndex('primary')->isPrimary()); $this->assertTrue($table->getIndex('primary')->isUnique()); + $this->assertEquals(['integerfield'], $table->getIndex('index_integerfield')->getUnquotedColumns()); + $this->assertFalse($table->getIndex('index_integerfield')->isPrimary()); + $this->assertTrue($table->getIndex('index_integerfield')->isUnique()); $this->assertEquals(['booleanfield'], $table->getIndex('index_boolean')->getUnquotedColumns()); $this->assertFalse($table->getIndex('index_boolean')->isPrimary()); $this->assertFalse($table->getIndex('index_boolean')->isUnique()); diff --git a/tests/lib/DB/testschema.xml b/tests/lib/DB/testschema.xml index 5f449c936d9..a2b01d8259e 100644 --- a/tests/lib/DB/testschema.xml +++ b/tests/lib/DB/testschema.xml @@ -13,7 +13,7 @@ <declaration> <field> - <name>integerfield</name> + <name>id</name> <type>integer</type> <default>0</default> <notnull>true</notnull> @@ -22,6 +22,13 @@ <autoincrement>1</autoincrement> </field> <field> + <name>integerfield</name> + <type>integer</type> + <default>0</default> + <notnull>true</notnull> + <length>4</length> + </field> + <field> <name>integerfield_default</name> <type>integer</type> <default>10</default> @@ -37,7 +44,7 @@ </field> <field> <name>clobfield</name> - <type>clob</type> + <type>text</type> </field> <field> <name>booleanfield</name> @@ -65,6 +72,15 @@ <primary>true</primary> <unique>true</unique> <field> + <name>id</name> + <sorting>ascending</sorting> + </field> + </index> + + <index> + <name>index_integerfield</name> + <unique>true</unique> + <field> <name>integerfield</name> <sorting>ascending</sorting> </field> |