aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorPiotr Mrowczynski <mrow4a@yahoo.com>2017-10-02 12:32:21 +0200
committerJoas Schilling <coding@schilljs.com>2017-10-30 18:57:19 +0100
commit6a51c1bc4fd0f2496103f901fef3b550688c2364 (patch)
treea8f0e105711148d4f76953ee383c9af870849e47 /tests/lib
parentd081a1a5adf007b383b0140c3ac469249d79878a (diff)
downloadnextcloud-server-6a51c1bc4fd0f2496103f901fef3b550688c2364.tar.gz
nextcloud-server-6a51c1bc4fd0f2496103f901fef3b550688c2364.zip
Add foreign key support to OC
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/DB/MigratorTest.php39
1 files changed, 37 insertions, 2 deletions
diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php
index e4f45c4bb86..ea718240c5e 100644
--- a/tests/lib/DB/MigratorTest.php
+++ b/tests/lib/DB/MigratorTest.php
@@ -41,6 +41,9 @@ class MigratorTest extends \Test\TestCase {
/** @var string */
private $tableName;
+ /** @var string */
+ private $tableNameTmp;
+
protected function setUp() {
parent::setUp();
@@ -50,11 +53,23 @@ class MigratorTest extends \Test\TestCase {
$this->markTestSkipped('DB migration tests are not supported on OCI');
}
$this->manager = new \OC\DB\MDB2SchemaManager($this->connection);
- $this->tableName = strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_') . 'test_'));
+ $this->tableName = $this->getUniqueTableName();
+ $this->tableNameTmp = $this->getUniqueTableName();
+ }
+
+ private function getUniqueTableName() {
+ return strtolower($this->getUniqueID($this->config->getSystemValue('dbtableprefix', 'oc_') . 'test_'));
}
protected function tearDown() {
- $this->connection->exec('DROP TABLE ' . $this->tableName);
+ // Try to delete if exists (IF EXISTS NOT SUPPORTED IN ORACLE)
+ try {
+ $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableNameTmp));
+ } catch (\Doctrine\DBAL\DBALException $e) {}
+
+ try {
+ $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableName));
+ } catch (\Doctrine\DBAL\DBALException $e) {}
parent::tearDown();
}
@@ -200,4 +215,24 @@ class MigratorTest extends \Test\TestCase {
$this->assertTrue(true);
}
+
+ public function testAddingForeignKey() {
+ $startSchema = new Schema([], [], $this->getSchemaConfig());
+ $table = $startSchema->createTable($this->tableName);
+ $table->addColumn('id', 'integer', ['autoincrement' => true]);
+ $table->addColumn('name', 'string');
+ $table->setPrimaryKey(['id']);
+
+ $fkName = "fkc";
+ $tableFk = $startSchema->createTable($this->tableNameTmp);
+ $tableFk->addColumn('fk_id', 'integer');
+ $tableFk->addColumn('name', 'string');
+ $tableFk->addForeignKeyConstraint($this->tableName, array('fk_id'), array('id'), array(), $fkName);
+
+ $migrator = $this->manager->getMigrator();
+ $migrator->migrate($startSchema);
+
+
+ $this->assertTrue($startSchema->getTable($this->tableNameTmp)->hasForeignKey($fkName));
+ }
}