From ab48d5e8cbb653767070a286650b87ae97461f37 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 24 Mar 2021 20:27:39 +0100 Subject: Cleanup unneeded code around database.xml Signed-off-by: Morris Jobke --- tests/data/db_structure.xml | 311 ------ tests/data/db_structure2.xml | 137 --- tests/lib/DB/ConnectionTest.php | 375 ------- tests/lib/DB/DBSchemaTest.php | 106 -- tests/lib/DB/LegacyDBTest.php | 323 ------ tests/lib/DB/MDB2SchemaManagerTest.php | 49 - tests/lib/DB/MDB2SchemaReaderTest.php | 103 -- tests/lib/DB/MigratorTest.php | 41 +- tests/lib/DB/MySqlMigrationTest.php | 48 - tests/lib/DB/SchemaDiffTest.php | 108 --- tests/lib/DB/SqliteMigrationTest.php | 48 - tests/lib/DB/schemDiffData/autoincrement.xml | 16 - tests/lib/DB/schemDiffData/clob.xml | 14 - tests/lib/DB/schemDiffData/core.xml | 1347 -------------------------- tests/lib/DB/schemDiffData/default-1.xml | 51 - tests/lib/DB/schemDiffData/unsigned.xml | 68 -- tests/lib/DB/testschema.xml | 99 -- tests/lib/DB/ts-autoincrement-after.xml | 32 - tests/lib/DB/ts-autoincrement-before.xml | 24 - 19 files changed, 29 insertions(+), 3271 deletions(-) delete mode 100644 tests/data/db_structure.xml delete mode 100644 tests/data/db_structure2.xml delete mode 100644 tests/lib/DB/ConnectionTest.php delete mode 100644 tests/lib/DB/DBSchemaTest.php delete mode 100644 tests/lib/DB/LegacyDBTest.php delete mode 100644 tests/lib/DB/MDB2SchemaManagerTest.php delete mode 100644 tests/lib/DB/MDB2SchemaReaderTest.php delete mode 100644 tests/lib/DB/MySqlMigrationTest.php delete mode 100644 tests/lib/DB/SchemaDiffTest.php delete mode 100644 tests/lib/DB/SqliteMigrationTest.php delete mode 100644 tests/lib/DB/schemDiffData/autoincrement.xml delete mode 100644 tests/lib/DB/schemDiffData/clob.xml delete mode 100644 tests/lib/DB/schemDiffData/core.xml delete mode 100644 tests/lib/DB/schemDiffData/default-1.xml delete mode 100644 tests/lib/DB/schemDiffData/unsigned.xml delete mode 100644 tests/lib/DB/testschema.xml delete mode 100644 tests/lib/DB/ts-autoincrement-after.xml delete mode 100644 tests/lib/DB/ts-autoincrement-before.xml (limited to 'tests') diff --git a/tests/data/db_structure.xml b/tests/data/db_structure.xml deleted file mode 100644 index b155114f2ed..00000000000 --- a/tests/data/db_structure.xml +++ /dev/null @@ -1,311 +0,0 @@ - - - - *dbname* - false - false - - utf8 - - - - *dbprefix*cntcts_addrsbks - - - - - id - integer - 0 - true - 1 - true - 4 - This is the id - - - - userid - text - - true - 255 - - - - displayname - text - - false - 255 - - - - uri - text - - false - 200 - - - - description - text - false - 255 - - - - ctag - integer - 1 - true - true - 4 - - - - active - integer - 1 - true - 4 - - - - -
- - - - *dbprefix*cntcts_cards - - - - - id - integer - 0 - true - 1 - true - 4 - - - - addressbookid - integer - - true - true - 4 - - - - fullname - text - - false - 255 - - - - carddata - clob - false - - - - uri - text - - false - 200 - - - - lastmodified - integer - - false - true - 4 - - - - -
- - - - *dbprefix*vcategory - - - - - id - integer - 0 - true - 1 - true - 4 - - - - uid - text - - true - 64 - - - - type - text - - true - 64 - - - - category - text - - true - 255 - - - -
- - - *dbprefix*timestamp - - - id - 1 - integer - 0 - true - 4 - - - - timestamptest - timestamp - - false - - -
- - - *dbprefix*decimal - - - id - 1 - integer - 0 - true - 4 - - - - decimaltest - decimal - - true - 12 - 2 - - -
- - - *dbprefix*migratekeyword - - - - - select - text - - true - 255 - - -
- - - *dbprefix*uniconst - - - - id - integer - 0 - true - 1 - 4 - - - - - storage - integer - - true - 4 - - - - path_hash - text - - true - 32 - - - - etag - text - - false - 40 - - - - - true - - storage - ascending - - - path_hash - ascending - - - - - -
- - - - *dbprefix*text_table - - - - textfield - text - false - 255 - - - -
- -
diff --git a/tests/data/db_structure2.xml b/tests/data/db_structure2.xml deleted file mode 100644 index 568d90ab0a9..00000000000 --- a/tests/data/db_structure2.xml +++ /dev/null @@ -1,137 +0,0 @@ - - - - *dbname* - true - false - - utf8 - - - - *dbprefix*cntcts_addrsbks - - - - - id - integer - 0 - true - 1 - true - 4 - - - - userid - text - - true - 255 - - - - displayname - text - - false - 255 - - - - uri - text - - true - 200 - - - - description - text - false - 1024 - - - - ctag - integer - 1 - true - true - 4 - - - - active - integer - 1 - true - 1 - - - - -
- - - *dbprefix*timestamp - - - id - 1 - integer - 0 - true - 4 - - - - timestamptest - timestamp - - false - - -
- - - *dbprefix*decimal - - - id - 1 - integer - 0 - true - 4 - - - - decimaltest - decimal - - true - 12 - 2 - - -
- - - *dbprefix*migratekeyword - - - - - select - text - - false - 255 - - -
- -
diff --git a/tests/lib/DB/ConnectionTest.php b/tests/lib/DB/ConnectionTest.php deleted file mode 100644 index d628d9814e0..00000000000 --- a/tests/lib/DB/ConnectionTest.php +++ /dev/null @@ -1,375 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test\DB; - -use Doctrine\DBAL\Platforms\SqlitePlatform; -use OC\DB\MDB2SchemaManager; -use OCP\DB\QueryBuilder\IQueryBuilder; - -/** - * Class Connection - * - * @group DB - * - * @package Test\DB - */ -class ConnectionTest extends \Test\TestCase { - /** - * @var \OCP\IDBConnection - */ - private $connection; - - public static function setUpBeforeClass(): void { - self::dropTestTable(); - parent::setUpBeforeClass(); - } - - public static function tearDownAfterClass(): void { - self::dropTestTable(); - parent::tearDownAfterClass(); - } - - protected static function dropTestTable() { - if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') !== 'oci') { - \OC::$server->getDatabaseConnection()->dropTable('table'); - } - } - - protected function setUp(): void { - parent::setUp(); - $this->connection = \OC::$server->get(\OC\DB\Connection::class); - } - - protected function tearDown(): void { - parent::tearDown(); - $this->connection->dropTable('table'); - } - - /** - * @param string $table - */ - public function assertTableExist($table) { - if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { - // sqlite removes the tables after closing the DB - $this->addToAssertionCount(1); - } else { - $this->assertTrue($this->connection->tableExists($table), 'Table ' . $table . ' exists.'); - } - } - - /** - * @param string $table - */ - public function assertTableNotExist($table) { - if ($this->connection->getDatabasePlatform() instanceof SqlitePlatform) { - // sqlite removes the tables after closing the DB - $this->addToAssertionCount(1); - } else { - $this->assertFalse($this->connection->tableExists($table), 'Table ' . $table . " doesn't exist."); - } - } - - private function makeTestTable() { - $schemaManager = new MDB2SchemaManager($this->connection); - $schemaManager->createDbFromStructure(__DIR__ . '/testschema.xml'); - } - - public function testTableExists() { - $this->assertTableNotExist('table'); - $this->makeTestTable(); - $this->assertTableExist('table'); - } - - /** - * @depends testTableExists - */ - public function testDropTable() { - $this->makeTestTable(); - $this->assertTableExist('table'); - $this->connection->dropTable('table'); - $this->assertTableNotExist('table'); - } - - private function getTextValueByIntegerField($integerField) { - $builder = $this->connection->getQueryBuilder(); - $query = $builder->select('*') - ->from('table') - ->where($builder->expr()->eq('integerfield', $builder->createNamedParameter($integerField, IQueryBuilder::PARAM_INT))); - - $result = $query->execute(); - $row = $result->fetch(); - $result->closeCursor(); - - return $row['textfield'] ?? null; - } - - public function testSetValues() { - $this->makeTestTable(); - $this->connection->setValues('table', [ - 'integerfield' => 1 - ], [ - 'textfield' => 'foo', - 'clobfield' => 'not_null' - ]); - - $this->assertEquals('foo', $this->getTextValueByIntegerField(1)); - } - - public function testSetValuesOverWrite() { - $this->makeTestTable(); - $this->connection->setValues('table', [ - 'integerfield' => 1 - ], [ - 'textfield' => 'foo' - ]); - - $this->connection->setValues('table', [ - 'integerfield' => 1 - ], [ - 'textfield' => 'bar' - ]); - - $this->assertEquals('bar', $this->getTextValueByIntegerField(1)); - } - - public function testSetValuesOverWritePrecondition() { - $this->makeTestTable(); - $this->connection->setValues('table', [ - 'integerfield' => 1 - ], [ - 'textfield' => 'foo', - 'booleanfield' => true, - 'clobfield' => 'not_null' - ]); - - $this->connection->setValues('table', [ - 'integerfield' => 1 - ], [ - 'textfield' => 'bar' - ], [ - 'booleanfield' => true - ]); - - $this->assertEquals('bar', $this->getTextValueByIntegerField(1)); - } - - - public function testSetValuesOverWritePreconditionFailed() { - $this->expectException(\OCP\PreConditionNotMetException::class); - - $this->makeTestTable(); - $this->connection->setValues('table', [ - 'integerfield' => 1 - ], [ - 'textfield' => 'foo', - 'booleanfield' => true, - 'clobfield' => 'not_null' - ]); - - $this->connection->setValues('table', [ - 'integerfield' => 1 - ], [ - 'textfield' => 'bar' - ], [ - 'booleanfield' => false - ]); - } - - public function testSetValuesSameNoError() { - $this->makeTestTable(); - $this->connection->setValues('table', [ - 'integerfield' => 1 - ], [ - 'textfield' => 'foo', - 'clobfield' => 'not_null' - ]); - - // this will result in 'no affected rows' on certain optimizing DBs - // ensure the PreConditionNotMetException isn't thrown - $this->connection->setValues('table', [ - 'integerfield' => 1 - ], [ - 'textfield' => 'foo' - ]); - - $this->addToAssertionCount(1); - } - - 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], - ['user' => 'test', 'category' => 'Friends', 'expectedResult' => 1], - ['user' => 'test', 'category' => 'Coworkers', 'expectedResult' => 1], - ['user' => 'test', 'category' => 'Coworkers', 'expectedResult' => 0], - ['user' => 'test', 'category' => 'School', 'expectedResult' => 1], - ['user' => 'test2', 'category' => 'Coworkers2', 'expectedResult' => 1], - ['user' => 'test2', 'category' => 'Coworkers2', 'expectedResult' => 0], - ['user' => 'test2', 'category' => 'School2', 'expectedResult' => 1], - ['user' => 'test2', 'category' => 'Coworkers', 'expectedResult' => 1], - ]; - - $row = 0; - foreach ($categoryEntries as $entry) { - $result = $this->connection->insertIfNotExist('*PREFIX*table', - [ - 'textfield' => $entry['user'], - 'clobfield' => $entry['category'], - 'integerfield' => $row++, - ], ['textfield', 'clobfield']); - $this->assertEquals($entry['expectedResult'], $result, json_encode($entry)); - } - - $query = $this->connection->prepare('SELECT * FROM `*PREFIX*table`'); - $result = $query->execute(); - $this->assertTrue((bool)$result); - $this->assertEquals(7, count($result->fetchAll())); - } - - 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], - ['addressbookid' => 123, 'fullname' => null, 'expectedResult' => 0], - ['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'], - 'integerfield' => $row++, - ], ['integerfield_default', 'clobfield']); - $this->assertEquals($entry['expectedResult'], $result, json_encode($entry)); - } - - $query = $this->connection->prepare('SELECT * FROM `*PREFIX*table`'); - $result = $query->execute(); - $this->assertTrue((bool)$result); - $this->assertEquals(2, count($result->fetchAll())); - } - - 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'; - - // Normal test to have same known data inserted. - $query = $this->connection->prepare('INSERT INTO `*PREFIX*table` (`textfield`, `clobfield`) VALUES (?, ?)'); - $result = $query->execute([$fullName, $uri]); - $this->assertEquals(1, $result->rowCount()); - $query = $this->connection->prepare('SELECT `textfield`, `clobfield` FROM `*PREFIX*table` WHERE `clobfield` = ?'); - $result = $query->execute([$uri]); - $rowset = $result->fetchAll(); - $this->assertEquals(1, count($rowset)); - $this->assertArrayHasKey('textfield', $rowset[0]); - $this->assertEquals($fullName, $rowset[0]['textfield']); - - // Try to insert a new row - $result = $this->connection->insertIfNotExist('*PREFIX*table', - [ - 'textfield' => $fullName, - 'clobfield' => $uri, - ]); - $this->assertEquals(0, $result); - - $query = $this->connection->prepare('SELECT `textfield`, `clobfield` FROM `*PREFIX*table` WHERE `clobfield` = ?'); - $result = $query->execute([$uri]); - // Test that previously inserted data isn't overwritten - // And that a new row hasn't been inserted. - $rowset = $result->fetchAll(); - $this->assertEquals(1, count($rowset)); - $this->assertArrayHasKey('textfield', $rowset[0]); - $this->assertEquals($fullName, $rowset[0]['textfield']); - } - - 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', - [ - 'textfield' => md5('welcome.txt'), - 'clobfield' => $this->getUniqueID() - ]); - $this->assertEquals(1, $result); - - $result = $this->connection->insertIfNotExist('*PREFIX*table', - [ - 'textfield' => md5('welcome.txt'), - 'clobfield' => $this->getUniqueID() - ],['textfield']); - - $this->assertEquals(0, $result); - } - - public function insertIfNotExistsViolatingThrows() { - return [ - [null], - [['clobfield']], - ]; - } - - /** - * @dataProvider insertIfNotExistsViolatingThrows - * - * @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', - [ - 'integerfield' => 1, - 'clobfield' => $this->getUniqueID() - ]); - $this->assertEquals(1, $result); - - $result = $this->connection->insertIfNotExist('*PREFIX*table', - [ - 'integerfield' => 1, - 'clobfield' => $this->getUniqueID() - ], $compareKeys); - - $this->assertEquals(0, $result); - } - - - public function testUniqueConstraintViolating() { - $this->expectException(\Doctrine\DBAL\Exception\UniqueConstraintViolationException::class); - - $this->makeTestTable(); - - $testQuery = 'INSERT INTO `*PREFIX*table` (`integerfield`, `textfield`) VALUES(?, ?)'; - $testParams = [1, 'hello']; - - $this->connection->executeUpdate($testQuery, $testParams); - $this->connection->executeUpdate($testQuery, $testParams); - } -} diff --git a/tests/lib/DB/DBSchemaTest.php b/tests/lib/DB/DBSchemaTest.php deleted file mode 100644 index 4f24c3f67aa..00000000000 --- a/tests/lib/DB/DBSchemaTest.php +++ /dev/null @@ -1,106 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test\DB; - -use Doctrine\DBAL\Platforms\SqlitePlatform; -use OC_DB; -use OCP\ITempManager; -use OCP\Security\ISecureRandom; -use Test\TestCase; - -/** - * Class DBSchemaTest - * - * @group DB - */ -class DBSchemaTest extends TestCase { - protected $schema_file; - protected $schema_file2; - protected $table1; - protected $table2; - /** @var ITempManager */ - protected $tempManager; - - protected function setUp(): void { - parent::setUp(); - - $this->tempManager = \OC::$server->getTempManager(); - $this->schema_file = $this->tempManager->getTemporaryFile(); - $this->schema_file2 = $this->tempManager->getTemporaryFile(); - - $dbfile = \OC::$SERVERROOT.'/tests/data/db_structure.xml'; - $dbfile2 = \OC::$SERVERROOT.'/tests/data/db_structure2.xml'; - - $r = '_' . \OC::$server->getSecureRandom()-> - generate(4, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS) . '_'; - $content = file_get_contents($dbfile); - $content = str_replace('*dbprefix*', '*dbprefix*'.$r, $content); - file_put_contents($this->schema_file, $content); - $content = file_get_contents($dbfile2); - $content = str_replace('*dbprefix*', '*dbprefix*'.$r, $content); - file_put_contents($this->schema_file2, $content); - - $this->table1 = $r.'cntcts_addrsbks'; - $this->table2 = $r.'cntcts_cards'; - } - - protected function tearDown(): void { - unlink($this->schema_file); - unlink($this->schema_file2); - - parent::tearDown(); - } - - // everything in one test, they depend on each other - /** - * @medium - */ - public function testSchema() { - $this->doTestSchemaCreating(); - $this->doTestSchemaChanging(); - $this->doTestSchemaRemoving(); - } - - public function doTestSchemaCreating() { - OC_DB::createDbFromStructure($this->schema_file); - $this->assertTableExist($this->table1); - $this->assertTableExist($this->table2); - } - - public function doTestSchemaChanging() { - OC_DB::updateDbFromStructure($this->schema_file2); - $this->assertTableExist($this->table2); - } - - public function doTestSchemaRemoving() { - OC_DB::removeDBStructure($this->schema_file); - $this->assertTableNotExist($this->table1); - $this->assertTableNotExist($this->table2); - } - - /** - * @param string $table - */ - public function assertTableExist($table) { - $this->assertTrue(OC_DB::tableExists($table), 'Table ' . $table . ' does not exist'); - } - - /** - * @param string $table - */ - public function assertTableNotExist($table) { - $platform = \OC::$server->getDatabaseConnection()->getDatabasePlatform(); - if ($platform instanceof SqlitePlatform) { - // sqlite removes the tables after closing the DB - $this->addToAssertionCount(1); - } else { - $this->assertFalse(OC_DB::tableExists($table), 'Table ' . $table . ' exists.'); - } - } -} diff --git a/tests/lib/DB/LegacyDBTest.php b/tests/lib/DB/LegacyDBTest.php deleted file mode 100644 index d4913cbe6f5..00000000000 --- a/tests/lib/DB/LegacyDBTest.php +++ /dev/null @@ -1,323 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test\DB; - -use OC_DB; - -/** - * Class LegacyDBTest - * - * @group DB - */ -class LegacyDBTest extends \Test\TestCase { - protected $backupGlobals = false; - - protected static $schema_file; - protected $test_prefix; - - public static function setUpBeforeClass(): void { - self::$schema_file = \OC::$server->getTempManager()->getTemporaryFile(); - } - - - /** - * @var string - */ - private $table1; - - /** - * @var string - */ - private $table2; - - /** - * @var string - */ - private $table3; - - /** - * @var string - */ - private $table4; - - /** - * @var string - */ - private $table5; - - /** - * @var string - */ - private $text_table; - - protected function setUp(): void { - parent::setUp(); - - $dbFile = \OC::$SERVERROOT.'/tests/data/db_structure.xml'; - - $r = $this->getUniqueID('_', 4).'_'; - $content = file_get_contents($dbFile); - $content = str_replace('*dbprefix*', '*dbprefix*'.$r, $content); - file_put_contents(self::$schema_file, $content); - OC_DB::createDbFromStructure(self::$schema_file); - - $this->test_prefix = $r; - $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'; - $this->table5 = $this->test_prefix.'uniconst'; - $this->text_table = $this->test_prefix.'text_table'; - } - - protected function tearDown(): void { - OC_DB::removeDBStructure(self::$schema_file); - unlink(self::$schema_file); - - parent::tearDown(); - } - - public function testQuotes() { - $query = OC_DB::prepare('SELECT `fullname` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); - $result = $query->execute(['uri_1']); - $this->assertTrue((bool)$result); - $row = $result->fetchRow(); - $this->assertFalse($row); - $result->closeCursor(); - - $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); - $result = $query->execute(['fullname test', 'uri_1']); - $this->assertEquals(1, $result); - $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); - $result = $query->execute(['uri_1']); - $this->assertTrue((bool)$result); - $row = $result->fetchRow(); - $this->assertArrayHasKey('fullname', $row); - $this->assertEquals($row['fullname'], 'fullname test'); - $row = $result->fetchRow(); - $this->assertFalse((bool)$row); //PDO returns false, MDB2 returns null - $result->closeCursor(); - } - - /** - * @medium - */ - public function testNOW() { - $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (NOW(),?)'); - $result = $query->execute(['uri_2']); - $this->assertEquals(1, $result); - $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); - $result = $query->execute(['uri_2']); - $this->assertTrue((bool)$result); - $result->closeCursor(); - } - - public function testUNIX_TIMESTAMP() { - $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (UNIX_TIMESTAMP(),?)'); - $result = $query->execute(['uri_3']); - $this->assertEquals(1, $result); - $query = OC_DB::prepare('SELECT `fullname`,`uri` FROM `*PREFIX*'.$this->table2.'` WHERE `uri` = ?'); - $result = $query->execute(['uri_3']); - $this->assertTrue((bool)$result); - $result->closeCursor(); - } - - public function testLastInsertId() { - $query = OC_DB::prepare('INSERT INTO `*PREFIX*'.$this->table2.'` (`fullname`,`uri`) VALUES (?,?)'); - $result1 = OC_DB::executeAudited($query, ['insertid 1','uri_1']); - $id1 = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*'.$this->table2); - - // we don't know the id we should expect, so insert another row - $result2 = OC_DB::executeAudited($query, ['insertid 2','uri_2']); - $id2 = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*'.$this->table2); - // now we can check if the two ids are in correct order - $this->assertGreaterThan($id1, $id2); - } - - public function testUtf8Data() { - $table = "*PREFIX*{$this->table2}"; - $expected = "Ћö雙喜\xE2\x80\xA2"; - - $query = OC_DB::prepare("INSERT INTO `$table` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"); - $result = $query->execute([$expected, 'uri_1', 'This is a vCard']); - $this->assertEquals(1, $result); - - $query = OC_DB::prepare("SELECT `fullname` FROM `$table`"); - - $result = $query->execute(); - $actual = $result->fetchOne(); - $result->closeCursor(); - - $this->assertSame($expected, $actual); - } - - /** - * Insert, select and delete decimal(12,2) values - * @dataProvider decimalData - */ - public function XtestDecimal($insert, $expect) { - $table = "*PREFIX*" . $this->table4; - $rowname = 'decimaltest'; - - $query = OC_DB::prepare('INSERT INTO `' . $table . '` (`' . $rowname . '`) VALUES (?)'); - $result = $query->execute([$insert]); - $this->assertEquals(1, $result); - $query = OC_DB::prepare('SELECT `' . $rowname . '` FROM `' . $table . '`'); - $result = $query->execute(); - $this->assertTrue((bool)$result); - $row = $result->fetchRow(); - $result->closeCursor(); - $this->assertArrayHasKey($rowname, $row); - $this->assertEquals($expect, $row[$rowname]); - $query = OC_DB::prepare('DELETE FROM `' . $table . '`'); - $result = $query->execute(); - $this->assertTrue((bool)$result); - } - - public function decimalData() { - return [ - ['1337133713.37', '1337133713.37'], - ['1234567890', '1234567890.00'], - ]; - } - - public function testUpdateAffectedRowsNoMatch() { - $this->insertCardData('fullname1', 'uri1'); - // The WHERE clause does not match any rows - $this->assertSame(0, $this->updateCardData('fullname3', 'uri2')); - } - - public function testUpdateAffectedRowsDifferent() { - $this->insertCardData('fullname1', 'uri1'); - // The WHERE clause matches a single row and the value we are updating - // is different from the one already present. - $this->assertSame(1, $this->updateCardData('fullname1', 'uri2')); - } - - public function testUpdateAffectedRowsSame() { - $this->insertCardData('fullname1', 'uri1'); - // The WHERE clause matches a single row and the value we are updating - // to is the same as the one already present. MySQL reports 0 here when - // the PDO::MYSQL_ATTR_FOUND_ROWS flag is not specified. - $this->assertSame(1, $this->updateCardData('fullname1', 'uri1')); - } - - public function testUpdateAffectedRowsMultiple() { - $this->insertCardData('fullname1', 'uri1'); - $this->insertCardData('fullname2', 'uri2'); - // The WHERE clause matches two rows. One row contains a value that - // needs to be updated, the other one already contains the value we are - // updating to. MySQL reports 1 here when the PDO::MYSQL_ATTR_FOUND_ROWS - // flag is not specified. - $query = OC_DB::prepare("UPDATE `*PREFIX*{$this->table2}` SET `uri` = ?"); - $this->assertSame(2, $query->execute(['uri1'])); - } - - protected function insertCardData($fullname, $uri) { - $query = OC_DB::prepare("INSERT INTO `*PREFIX*{$this->table2}` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"); - $this->assertSame(1, $query->execute([$fullname, $uri, $this->getUniqueID()])); - } - - protected function updateCardData($fullname, $uri) { - $query = OC_DB::prepare("UPDATE `*PREFIX*{$this->table2}` SET `uri` = ? WHERE `fullname` = ?"); - return $query->execute([$uri, $fullname]); - } - - public function testILIKE() { - $table = "*PREFIX*{$this->table2}"; - - $query = OC_DB::prepare("INSERT INTO `$table` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"); - $query->execute(['fooBAR', 'foo', 'bar']); - - $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); - $result = $query->execute(['foobar']); - $this->assertCount(0, $result->fetchAll()); - $result->closeCursor(); - - $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); - $result = $query->execute(['foobar']); - $this->assertCount(1, $result->fetchAll()); - $result->closeCursor(); - - $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); - $result = $query->execute(['foo']); - $this->assertCount(0, $result->fetchAll()); - $result->closeCursor(); - } - - public function testILIKEWildcard() { - $table = "*PREFIX*{$this->table2}"; - - $query = OC_DB::prepare("INSERT INTO `$table` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"); - $query->execute(['FooBAR', 'foo', 'bar']); - - $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); - $result = $query->execute(['%bar']); - $this->assertCount(0, $result->fetchAll()); - $result->closeCursor(); - - $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); - $result = $query->execute(['foo%']); - $this->assertCount(0, $result->fetchAll()); - $result->closeCursor(); - - $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` LIKE ?"); - $result = $query->execute(['%ba%']); - $this->assertCount(0, $result->fetchAll()); - $result->closeCursor(); - - $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); - $result = $query->execute(['%bar']); - $this->assertCount(1, $result->fetchAll()); - $result->closeCursor(); - - $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); - $result = $query->execute(['foo%']); - $this->assertCount(1, $result->fetchAll()); - $result->closeCursor(); - - $query = OC_DB::prepare("SELECT * FROM `$table` WHERE `fullname` ILIKE ?"); - $result = $query->execute(['%ba%']); - $this->assertCount(1, $result->fetchAll()); - $result->closeCursor(); - } - - /** - * @dataProvider insertAndSelectDataProvider - */ - public function testInsertAndSelectData($expected, $throwsOnMysqlWithoutUTF8MB4) { - $table = "*PREFIX*{$this->text_table}"; - $config = \OC::$server->getConfig(); - - $query = OC_DB::prepare("INSERT INTO `$table` (`textfield`) VALUES (?)"); - if ($throwsOnMysqlWithoutUTF8MB4 && $config->getSystemValue('dbtype', 'sqlite') === 'mysql' && $config->getSystemValue('mysql.utf8mb4', false) === false) { - $this->markTestSkipped('MySQL requires UTF8mb4 to store value: ' . $expected); - } - $result = $query->execute([$expected]); - $this->assertEquals(1, $result); - - $query = OC_DB::prepare("SELECT `textfield` FROM `$table`"); - - $result = $query->execute(); - $actual = $result->fetchOne(); - $result->closeCursor(); - $this->assertSame($expected, $actual); - } - - public function insertAndSelectDataProvider() { - return [ - ['abcdefghijklmnopqrstuvwxyzABCDEFGHIKLMNOPQRSTUVWXYZ', false], - ['0123456789', false], - ['äöüÄÖÜß!"§$%&/()=?#\'+*~°^`´', false], - ['²³¼½¬{[]}\\', false], - ['♡⚗', false], - ['💩', true], # :hankey: on github - ]; - } -} diff --git a/tests/lib/DB/MDB2SchemaManagerTest.php b/tests/lib/DB/MDB2SchemaManagerTest.php deleted file mode 100644 index 693de746b5e..00000000000 --- a/tests/lib/DB/MDB2SchemaManagerTest.php +++ /dev/null @@ -1,49 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test\DB; - -use Doctrine\DBAL\Platforms\OraclePlatform; - -/** - * Class MDB2SchemaManager - * - * @group DB - * - * @package Test\DB - */ -class MDB2SchemaManagerTest extends \Test\TestCase { - protected function tearDown(): void { - // do not drop the table for Oracle as it will create a bogus transaction - // that will break the following test suites requiring transactions - if (\OC::$server->getConfig()->getSystemValue('dbtype', 'sqlite') !== 'oci') { - \OC::$server->getDatabaseConnection()->dropTable('table'); - } - - parent::tearDown(); - } - - public function testAutoIncrement() { - $connection = \OC::$server->get(\OC\DB\Connection::class); - if ($connection->getDatabasePlatform() instanceof OraclePlatform) { - $this->markTestSkipped('Adding auto increment columns in Oracle is not supported.'); - } - - $manager = new \OC\DB\MDB2SchemaManager($connection); - - $manager->createDbFromStructure(__DIR__ . '/ts-autoincrement-before.xml'); - $connection->executeUpdate('insert into `*PREFIX*table` values (?)', ['abc']); - $connection->executeUpdate('insert into `*PREFIX*table` values (?)', ['abc']); - $connection->executeUpdate('insert into `*PREFIX*table` values (?)', ['123']); - $connection->executeUpdate('insert into `*PREFIX*table` values (?)', ['123']); - $manager->updateDbFromStructure(__DIR__ . '/ts-autoincrement-after.xml'); - - $this->addToAssertionCount(1); - } -} diff --git a/tests/lib/DB/MDB2SchemaReaderTest.php b/tests/lib/DB/MDB2SchemaReaderTest.php deleted file mode 100644 index 1e7d3a20b7c..00000000000 --- a/tests/lib/DB/MDB2SchemaReaderTest.php +++ /dev/null @@ -1,103 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test\DB; - -use Doctrine\DBAL\Platforms\MySQLPlatform; -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 - * - * @group DB - * - * @package Test\DB - */ -class MDB2SchemaReaderTest extends TestCase { - /** - * @var MDB2SchemaReader $reader - */ - protected $reader; - - /** - * @return IConfig - */ - protected function getConfig() { - /** @var IConfig | \PHPUnit\Framework\MockObject\MockObject $config */ - $config = $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $config->expects($this->any()) - ->method('getSystemValue') - ->willReturnMap([ - ['dbname', 'owncloud', 'testDB'], - ['dbtableprefix', 'oc_', 'test_'] - ]); - return $config; - } - - public function testRead() { - $reader = new MDB2SchemaReader($this->getConfig(), new MySQLPlatform()); - $schema = $reader->loadSchemaFromFile(__DIR__ . '/testschema.xml', new Schema()); - $this->assertCount(1, $schema->getTables()); - - $table = $schema->getTable('test_table'); - $this->assertCount(9, $table->getColumns()); - - $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()); - - $this->assertEquals(32, $table->getColumn('textfield')->getLength()); - $this->assertFalse($table->getColumn('textfield')->getAutoincrement()); - $this->assertSame('foo', $table->getColumn('textfield')->getDefault()); - $this->assertTrue($table->getColumn('textfield')->getNotnull()); - $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(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(BooleanType::class, $table->getColumn('booleanfield')->getType()); - - $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(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/MigratorTest.php b/tests/lib/DB/MigratorTest.php index 12ff3bd0749..1d2afaa405e 100644 --- a/tests/lib/DB/MigratorTest.php +++ b/tests/lib/DB/MigratorTest.php @@ -12,9 +12,15 @@ namespace Test\DB; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\MySQLPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; +use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaConfig; +use OC\DB\Migrator; +use OC\DB\MySQLMigrator; +use OC\DB\OracleMigrator; +use OC\DB\PostgreSqlMigrator; +use OC\DB\SQLiteMigrator; use OCP\IConfig; /** @@ -30,11 +36,6 @@ class MigratorTest extends \Test\TestCase { */ private $connection; - /** - * @var \OC\DB\MDB2SchemaManager - */ - private $manager; - /** * @var IConfig **/ @@ -54,11 +55,27 @@ class MigratorTest extends \Test\TestCase { if ($this->connection->getDatabasePlatform() instanceof OraclePlatform) { $this->markTestSkipped('DB migration tests are not supported on OCI'); } - $this->manager = new \OC\DB\MDB2SchemaManager($this->connection); + $this->tableName = $this->getUniqueTableName(); $this->tableNameTmp = $this->getUniqueTableName(); } + private function getMigrator(): Migrator { + $platform = $this->connection->getDatabasePlatform(); + $random = \OC::$server->getSecureRandom(); + $dispatcher = \OC::$server->getEventDispatcher(); + if ($platform instanceof SqlitePlatform) { + return new SQLiteMigrator($this->connection, $this->config, $dispatcher); + } elseif ($platform instanceof OraclePlatform) { + return new OracleMigrator($this->connection, $this->config, $dispatcher); + } elseif ($platform instanceof MySQLPlatform) { + return new MySQLMigrator($this->connection, $this->config, $dispatcher); + } elseif ($platform instanceof PostgreSQL94Platform) { + return new PostgreSqlMigrator($this->connection, $this->config, $dispatcher); + } + return new Migrator($this->connection, $this->config, $dispatcher); + } + private function getUniqueTableName() { return strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_') . 'test_')); } @@ -132,7 +149,7 @@ class MigratorTest extends \Test\TestCase { public function testUpgrade() { [$startSchema, $endSchema] = $this->getDuplicateKeySchemas(); - $migrator = $this->manager->getMigrator(); + $migrator = $this->getMigrator(); $migrator->migrate($startSchema); $this->connection->insert($this->tableName, ['id' => 1, 'name' => 'foo']); @@ -150,7 +167,7 @@ class MigratorTest extends \Test\TestCase { $this->tableName = strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix') . 'test_')); [$startSchema, $endSchema] = $this->getDuplicateKeySchemas(); - $migrator = $this->manager->getMigrator(); + $migrator = $this->getMigrator(); $migrator->migrate($startSchema); $this->connection->insert($this->tableName, ['id' => 1, 'name' => 'foo']); @@ -165,7 +182,7 @@ class MigratorTest extends \Test\TestCase { public function testInsertAfterUpgrade() { [$startSchema, $endSchema] = $this->getDuplicateKeySchemas(); - $migrator = $this->manager->getMigrator(); + $migrator = $this->getMigrator(); $migrator->migrate($startSchema); $migrator->migrate($endSchema); @@ -192,7 +209,7 @@ class MigratorTest extends \Test\TestCase { $table->addColumn('name', 'string'); $table->setPrimaryKey(['id']); - $migrator = $this->manager->getMigrator(); + $migrator = $this->getMigrator(); $migrator->migrate($startSchema); $migrator->migrate($endSchema); @@ -213,7 +230,7 @@ class MigratorTest extends \Test\TestCase { $table->addColumn('user', 'string', ['length' => 64]); $table->setPrimaryKey(['id']); - $migrator = $this->manager->getMigrator(); + $migrator = $this->getMigrator(); $migrator->migrate($startSchema); $migrator->migrate($endSchema); @@ -234,7 +251,7 @@ class MigratorTest extends \Test\TestCase { $tableFk->addColumn('name', 'string'); $tableFk->addForeignKeyConstraint($this->tableName, ['fk_id'], ['id'], [], $fkName); - $migrator = $this->manager->getMigrator(); + $migrator = $this->getMigrator(); $migrator->migrate($startSchema); diff --git a/tests/lib/DB/MySqlMigrationTest.php b/tests/lib/DB/MySqlMigrationTest.php deleted file mode 100644 index 38cb64916ec..00000000000 --- a/tests/lib/DB/MySqlMigrationTest.php +++ /dev/null @@ -1,48 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test\DB; - -/** - * Class MySqlMigration - * - * @group DB - */ -class MySqlMigrationTest extends \Test\TestCase { - - /** @var \Doctrine\DBAL\Connection */ - private $connection; - - /** @var string */ - private $tableName; - - protected function setUp(): void { - parent::setUp(); - - $this->connection = \OC::$server->get(\OC\DB\Connection::class); - if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\MySqlPlatform) { - $this->markTestSkipped("Test only relevant on MySql"); - } - - $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix"); - $this->tableName = $this->getUniqueID($dbPrefix . '_enum_bit_test'); - $this->connection->exec("CREATE TABLE $this->tableName(b BIT, e ENUM('1','2','3','4'))"); - } - - protected function tearDown(): void { - $this->connection->getSchemaManager()->dropTable($this->tableName); - parent::tearDown(); - } - - public function testNonOCTables() { - $manager = new \OC\DB\MDB2SchemaManager($this->connection); - $manager->updateDbFromStructure(__DIR__ . '/testschema.xml'); - - $this->addToAssertionCount(1); - } -} diff --git a/tests/lib/DB/SchemaDiffTest.php b/tests/lib/DB/SchemaDiffTest.php deleted file mode 100644 index 0e5612e3b3b..00000000000 --- a/tests/lib/DB/SchemaDiffTest.php +++ /dev/null @@ -1,108 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -namespace Test\DB; - -use Doctrine\DBAL\Schema\Schema; -use Doctrine\DBAL\Schema\SchemaDiff; -use OC\DB\MDB2SchemaManager; -use OC\DB\MDB2SchemaReader; -use OCP\IConfig; -use OCP\IDBConnection; -use Test\TestCase; - -/** - * Class MigratorTest - * - * @group DB - * - * @package Test\DB - */ -class SchemaDiffTest extends TestCase { - /** @var IDBConnection $connection */ - private $connection; - /** @var \Doctrine\DBAL\Connection $connection */ - private $internalConnection; - - /** @var MDB2SchemaManager */ - private $manager; - - /** @var IConfig */ - private $config; - - /** @var string */ - private $testPrefix; - - private $schemaFile; - - protected function setUp(): void { - parent::setUp(); - - $this->schemaFile = \OC::$server->getTempManager()->getTemporaryFile(); - - $this->config = \OC::$server->getConfig(); - $this->connection = \OC::$server->getDatabaseConnection(); - $this->internalConnection = \OC::$server->get(\OC\DB\Connection::class); - $this->manager = new MDB2SchemaManager($this->internalConnection); - $this->testPrefix = strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_'), 3)); - } - - protected function tearDown(): void { - $this->manager->removeDBStructure($this->schemaFile); - parent::tearDown(); - } - - /** - * @dataProvider providesSchemaFiles - * @param string $xml - */ - public function testZeroChangeOnSchemaMigrations($xml) { - $xml = str_replace('*dbprefix*', $this->testPrefix, $xml); - $schemaFile = $this->schemaFile; - file_put_contents($schemaFile, $xml); - - // apply schema - $this->manager->createDbFromStructure($schemaFile); - - $schemaReader = new MDB2SchemaReader($this->config, $this->connection->getDatabasePlatform()); - $toSchema = new Schema([], [], $this->internalConnection->getSchemaManager()->createSchemaConfig()); - $endSchema = $schemaReader->loadSchemaFromFile($schemaFile, $toSchema); - - // get the diff - /** @var SchemaDiff $diff */ - $migrator = $this->manager->getMigrator(); - $diff = $this->invokePrivate($migrator, 'getDiff', [$endSchema, $this->internalConnection]); - - // no sql statement is expected - $sqls = $diff->toSql($this->connection->getDatabasePlatform()); - $this->assertEmpty($sqls); - } - - public function providesSchemaFiles() { - return [ - 'explicit test on autoincrement' => [file_get_contents(__DIR__ . '/schemDiffData/autoincrement.xml')], - 'explicit test on clob' => [file_get_contents(__DIR__ . '/schemDiffData/clob.xml')], - 'explicit test on unsigned' => [file_get_contents(__DIR__ . '/schemDiffData/unsigned.xml')], - 'explicit test on default -1' => [file_get_contents(__DIR__ . '/schemDiffData/default-1.xml')], - 'testing core schema' => [file_get_contents(__DIR__ . '/schemDiffData/core.xml')], - ]; - } -} diff --git a/tests/lib/DB/SqliteMigrationTest.php b/tests/lib/DB/SqliteMigrationTest.php deleted file mode 100644 index b0bf39b4035..00000000000 --- a/tests/lib/DB/SqliteMigrationTest.php +++ /dev/null @@ -1,48 +0,0 @@ - - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -namespace Test\DB; - -/** - * Class SqliteMigration - * - * @group DB - */ -class SqliteMigrationTest extends \Test\TestCase { - - /** @var \Doctrine\DBAL\Connection */ - private $connection; - - /** @var string */ - private $tableName; - - protected function setUp(): void { - parent::setUp(); - - $this->connection = \OC::$server->get(\OC\DB\Connection::class); - if (!$this->connection->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { - $this->markTestSkipped("Test only relevant on Sqlite"); - } - - $dbPrefix = \OC::$server->getConfig()->getSystemValue("dbtableprefix"); - $this->tableName = $this->getUniqueID($dbPrefix . '_enum_bit_test'); - $this->connection->prepare("CREATE TABLE $this->tableName(t0 tinyint unsigned, t1 tinyint)")->execute(); - } - - protected function tearDown(): void { - $this->connection->getSchemaManager()->dropTable($this->tableName); - parent::tearDown(); - } - - public function testNonOCTables() { - $manager = new \OC\DB\MDB2SchemaManager($this->connection); - $manager->updateDbFromStructure(__DIR__ . '/testschema.xml'); - - $this->addToAssertionCount(1); - } -} diff --git a/tests/lib/DB/schemDiffData/autoincrement.xml b/tests/lib/DB/schemDiffData/autoincrement.xml deleted file mode 100644 index 458c5d8166f..00000000000 --- a/tests/lib/DB/schemDiffData/autoincrement.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - *dbprefix*external_config - - - config_id - integer - 0 - true - 1 - 6 - - -
-
diff --git a/tests/lib/DB/schemDiffData/clob.xml b/tests/lib/DB/schemDiffData/clob.xml deleted file mode 100644 index 08aef18c31d..00000000000 --- a/tests/lib/DB/schemDiffData/clob.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - *dbprefix*external_config - - - value - text - true - 100000 - - -
-
diff --git a/tests/lib/DB/schemDiffData/core.xml b/tests/lib/DB/schemDiffData/core.xml deleted file mode 100644 index d7edc7dc73e..00000000000 --- a/tests/lib/DB/schemDiffData/core.xml +++ /dev/null @@ -1,1347 +0,0 @@ - - - - - - - *dbprefix*appconfig - - - - - appid - text - - true - 32 - - - - configkey - text - - true - 64 - - - - configvalue - clob - false - - - -
- - - - - *dbprefix*storages - - - - - id - text - - false - 64 - - - - numeric_id - integer - 0 - true - 1 - 4 - - - - available - integer - 1 - true - - - - last_checked - integer - - - -
- - - - - *dbprefix*mounts - - - - - id - integer - 0 - true - 1 - 4 - - - - storage_id - integer - true - - - - - root_id - integer - true - - - - user_id - text - true - 64 - - - - mount_point - text - true - 4000 - - - - - -
- - - - - *dbprefix*mimetypes - - - - - id - integer - 0 - true - 1 - 4 - - - - mimetype - text - - true - 255 - - - - -
- - - - - *dbprefix*filecache - - - - - fileid - integer - 0 - true - 1 - 4 - - - - - storage - integer - - true - 4 - - - - path - text - - false - 4000 - - - - path_hash - text - - true - 32 - - - - - parent - integer - - true - 4 - - - - name - text - - false - 250 - - - - - mimetype - integer - - true - 4 - - - - - mimepart - integer - - true - 4 - - - - size - integer - - true - 8 - - - - mtime - integer - - true - 4 - - - - storage_mtime - integer - - true - 4 - - - - encrypted - integer - 0 - true - 4 - - - - unencrypted_size - integer - 0 - true - 8 - - - - etag - text - - false - 40 - - - - permissions - integer - 0 - false - 4 - - - - checksum - text - - false - 255 - - - - - - -
- - - - - *dbprefix*group_user - - - - - - gid - text - - true - 64 - - - - - uid - text - - true - 64 - - - - -
- - - - - *dbprefix*group_admin - - - - - - gid - text - - true - 64 - - - - - uid - text - - true - 64 - - - - -
- - - - - *dbprefix*groups - - - - - gid - text - - true - 64 - - - - -
- - - - - *dbprefix*preferences - - - - - - userid - text - - true - 64 - - - - appid - text - - true - 32 - - - - configkey - text - - true - 64 - - - - configvalue - clob - false - - - - -
- - - - - *dbprefix*properties - - - - - id - 1 - integer - 0 - true - 4 - - - - - userid - text - - true - 64 - - - - propertypath - text - - true - 255 - - - - propertyname - text - - true - 255 - - - - propertyvalue - text - true - 255 - - - - -
- - - - - *dbprefix*share - - - - - id - 1 - integer - 0 - true - 4 - - - - - share_type - integer - 0 - true - 1 - - - - - share_with - text - - false - 255 - - - - - - uid_owner - text - - true - 64 - - - - - - uid_initiator - text - - false - 64 - - - - - - - parent - integer - false - 4 - - - - - item_type - text - - true - 64 - - - - - item_source - text - - false - 255 - - - - item_target - text - - false - 255 - - - - - file_source - integer - false - 4 - - - - file_target - text - - false - 512 - - - - - permissions - integer - 0 - true - 1 - - - - - stime - integer - 0 - true - 8 - - - - - accepted - integer - 0 - true - 1 - - - - - expiration - timestamp - - false - - - - token - text - - false - 32 - - - - mail_send - integer - 0 - true - 1 - - - - -
- - - - - *dbprefix*jobs - - - - - id - integer - 0 - true - 1 - true - 4 - - - - class - text - - true - 255 - - - - argument - text - - true - 4000 - - - - - last_run - integer - - false - - - - - last_checked - integer - - false - - - - - reserved_at - integer - - false - - - - -
- - - - - *dbprefix*users - - - - - uid - text - - true - 64 - - - - displayname - text - - 64 - - - - password - text - - true - 255 - - - - - -
- - - *dbprefix*authtoken - - - - - id - integer - 0 - true - 1 - true - 4 - - - - - uid - text - - true - 64 - - - - login_name - text - - true - 64 - - - - password - clob - - false - - - - name - clob - - true - - - - token - text - - true - 200 - - - - type - integer - 0 - true - true - 2 - - - - last_activity - integer - 0 - true - true - 4 - - - -
- - - - - *dbprefix*vcategory - - - - - id - integer - 0 - true - 1 - true - 4 - - - - - uid - text - - true - 64 - - - - type - text - - true - 64 - - - - category - text - - true - 255 - - - -
- - - - - *dbprefix*vcategory_to_object - - - - - objid - integer - 0 - true - true - 4 - - - - - categoryid - integer - 0 - true - true - 4 - - - - type - text - - true - 64 - - - - -
- - - - *dbprefix*systemtag - - - - - id - integer - 0 - true - 1 - true - 4 - - - - - name - text - - true - 64 - - - - - visibility - integer - 1 - true - 1 - - - - - editable - integer - 1 - true - 1 - - - -
- - - - - *dbprefix*systemtag_object_mapping - - - - - - objectid - text - - true - 64 - - - - - objecttype - text - - true - 64 - - - - - systemtagid - integer - 0 - true - true - 4 - - - - - -
- - - - - *dbprefix*systemtag_group - - - - - - systemtagid - integer - 0 - true - true - 4 - - - - gid - string - true - - - - -
- - - - - *dbprefix*privatedata - - - - - keyid - integer - 0 - true - true - 4 - 1 - - - - - user - text - - true - 64 - - - - app - text - - true - 255 - - - - key - text - - true - 255 - - - - value - text - - true - 255 - - - - -
- - - - - *dbprefix*file_locks - - - - - id - integer - 0 - true - true - 4 - 1 - - - - lock - integer - 0 - true - 4 - - - - key - text - true - 64 - - - - ttl - integer - -1 - true - 4 - - - - -
- - - - *dbprefix*comments - - - - - id - integer - 0 - true - true - 4 - 1 - - - - parent_id - integer - 0 - true - true - 4 - - - - topmost_parent_id - integer - 0 - true - true - 4 - - - - children_count - integer - 0 - true - true - 4 - - - - actor_type - text - - true - 64 - - - - actor_id - text - - true - 64 - - - - message - clob - - false - - - - verb - text - - false - 64 - - - - creation_timestamp - timestamp - - false - - - - latest_child_timestamp - timestamp - - false - - - - object_type - text - - true - 64 - - - - object_id - text - - true - 64 - - - - -
- - - - *dbprefix*comments_read_markers - - - - - user_id - text - - true - 64 - - - - marker_datetime - timestamp - - false - - - - object_type - text - - true - 64 - - - - object_id - text - - true - 64 - - - - -
- - - - *dbprefix*credentials - - - - - user - text - - false - 64 - - - - identifier - text - true - 64 - - - - credentials - clob - false - - - - -
- -
diff --git a/tests/lib/DB/schemDiffData/default-1.xml b/tests/lib/DB/schemDiffData/default-1.xml deleted file mode 100644 index 39b95a1f273..00000000000 --- a/tests/lib/DB/schemDiffData/default-1.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - *dbprefix*file_locks - - - - - id - integer - 0 - true - true - 4 - 1 - - - - lock - integer - 0 - true - 4 - - - - key - text - true - (stupid text) - 64 - - - - ttl - integer - -1 - true - 4 - - - - -
- -
diff --git a/tests/lib/DB/schemDiffData/unsigned.xml b/tests/lib/DB/schemDiffData/unsigned.xml deleted file mode 100644 index e89fd6a5d4e..00000000000 --- a/tests/lib/DB/schemDiffData/unsigned.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - *dbprefix*jobs - - - - - id - integer - 0 - true - 1 - true - 4 - - - - class - text - - true - 255 - - - - argument - text - - true - 4000 - - - - - last_run - integer - - false - - - - - last_checked - integer - - false - - - - - reserved_at - integer - - false - - - - -
- -
diff --git a/tests/lib/DB/testschema.xml b/tests/lib/DB/testschema.xml deleted file mode 100644 index a2b01d8259e..00000000000 --- a/tests/lib/DB/testschema.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - - *dbname* - true - false - - utf8 - - - - *dbprefix*table - - - - id - integer - 0 - true - true - 4 - 1 - - - integerfield - integer - 0 - true - 4 - - - integerfield_default - integer - 10 - true - 4 - - - textfield - text - foo - true - 32 - - - clobfield - text - - - booleanfield - boolean - - - booleanfield_true - boolean - true - - - booleanfield_false - boolean - false - - - decimalfield_precision_scale - decimal - 12 - 2 - - - - index_primary - true - true - - id - ascending - - - - - index_integerfield - true - - integerfield - ascending - - - - - index_boolean - false - - booleanfield - ascending - - - -
-
diff --git a/tests/lib/DB/ts-autoincrement-after.xml b/tests/lib/DB/ts-autoincrement-after.xml deleted file mode 100644 index d4445f1e247..00000000000 --- a/tests/lib/DB/ts-autoincrement-after.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - *dbname* - true - false - - utf8 - - - - *dbprefix*table - - - - auto_id - integer - 0 - true - 1 - 4 - - - textfield - text - foo - true - 32 - - -
-
diff --git a/tests/lib/DB/ts-autoincrement-before.xml b/tests/lib/DB/ts-autoincrement-before.xml deleted file mode 100644 index 412739e9a71..00000000000 --- a/tests/lib/DB/ts-autoincrement-before.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - *dbname* - true - false - - utf8 - - - - *dbprefix*table - - - - textfield - text - foo - true - 32 - - -
-
-- cgit v1.2.3