summaryrefslogtreecommitdiffstats
path: root/tests/lib/DB
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2018-07-18 10:42:32 +0200
committerJoas Schilling <coding@schilljs.com>2018-07-27 14:45:21 +0200
commit14682dfa7c1f846e3094b4f6bcd558681b8f5b9f (patch)
tree357aa878e03793de66768b2565c67e2d9fc6d7f7 /tests/lib/DB
parent8a45cb1d2030b4dfd6ff918fc251e12eb0f10445 (diff)
downloadnextcloud-server-14682dfa7c1f846e3094b4f6bcd558681b8f5b9f.tar.gz
nextcloud-server-14682dfa7c1f846e3094b4f6bcd558681b8f5b9f.zip
Add unit tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests/lib/DB')
-rw-r--r--tests/lib/DB/MigrationsTest.php294
1 files changed, 293 insertions, 1 deletions
diff --git a/tests/lib/DB/MigrationsTest.php b/tests/lib/DB/MigrationsTest.php
index 191164c7eed..35e1d9ce391 100644
--- a/tests/lib/DB/MigrationsTest.php
+++ b/tests/lib/DB/MigrationsTest.php
@@ -10,7 +10,12 @@
namespace Test\DB;
+use Doctrine\DBAL\Schema\Column;
+use Doctrine\DBAL\Schema\ForeignKeyConstraint;
+use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Schema;
+use Doctrine\DBAL\Schema\Sequence;
+use Doctrine\DBAL\Schema\Table;
use OC\DB\Connection;
use OC\DB\MigrationService;
use OC\DB\SchemaWrapper;
@@ -94,10 +99,18 @@ class MigrationsTest extends \Test\TestCase {
$this->db->expects($this->once())
->method('migrateToSchema');
+ $wrappedSchema = $this->createMock(Schema::class);
+ $wrappedSchema->expects($this->once())
+ ->method('getTables')
+ ->willReturn([]);
+ $wrappedSchema->expects($this->once())
+ ->method('getSequences')
+ ->willReturn([]);
+
$schemaResult = $this->createMock(SchemaWrapper::class);
$schemaResult->expects($this->once())
->method('getWrappedSchema')
- ->willReturn($this->createMock(Schema::class));
+ ->willReturn($wrappedSchema);
$step = $this->createMock(IMigrationStep::class);
$step->expects($this->at(0))
@@ -205,4 +218,283 @@ class MigrationsTest extends \Test\TestCase {
->withConsecutive(['20170130180002'], ['20170130180003']);
$this->migrationService->migrate();
}
+
+ public function testEnsureOracleIdentifierLengthLimitValid() {
+ $column = $this->createMock(Column::class);
+ $column->expects($this->once())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 30));
+
+ $index = $this->createMock(Index::class);
+ $index->expects($this->once())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 30));
+
+ $foreignKey = $this->createMock(ForeignKeyConstraint::class);
+ $foreignKey->expects($this->once())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 30));
+
+ $table = $this->createMock(Table::class);
+ $table->expects($this->once())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 30));
+
+ $sequence = $this->createMock(Sequence::class);
+ $sequence->expects($this->once())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 30));
+
+ $table->expects($this->once())
+ ->method('getColumns')
+ ->willReturn([$column]);
+ $table->expects($this->once())
+ ->method('getIndexes')
+ ->willReturn([$index]);
+ $table->expects($this->once())
+ ->method('getForeignKeys')
+ ->willReturn([$foreignKey]);
+ $table->expects($this->once())
+ ->method('getPrimaryKey')
+ ->willReturn(null);
+
+ $schema = $this->createMock(Schema::class);
+ $schema->expects($this->once())
+ ->method('getTables')
+ ->willReturn([$table]);
+ $schema->expects($this->once())
+ ->method('getSequences')
+ ->willReturn([$sequence]);
+
+ self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
+ }
+
+ public function testEnsureOracleIdentifierLengthLimitValidWithPrimaryKey() {
+ $index = $this->createMock(Index::class);
+ $index->expects($this->once())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 30));
+
+ $table = $this->createMock(Table::class);
+ $table->expects($this->exactly(2))
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 26));
+
+ $table->expects($this->once())
+ ->method('getColumns')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getIndexes')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getForeignKeys')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getPrimaryKey')
+ ->willReturn($index);
+
+ $schema = $this->createMock(Schema::class);
+ $schema->expects($this->once())
+ ->method('getTables')
+ ->willReturn([$table]);
+ $schema->expects($this->once())
+ ->method('getSequences')
+ ->willReturn([]);
+
+ self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testEnsureOracleIdentifierLengthLimitTooLongTableName() {
+ $table = $this->createMock(Table::class);
+ $table->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 31));
+
+ $schema = $this->createMock(Schema::class);
+ $schema->expects($this->once())
+ ->method('getTables')
+ ->willReturn([$table]);
+
+ self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithDefault() {
+ $index = $this->createMock(Index::class);
+ $index->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 30));
+
+ $table = $this->createMock(Table::class);
+ $table->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 27));
+
+ $table->expects($this->once())
+ ->method('getColumns')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getIndexes')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getForeignKeys')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getPrimaryKey')
+ ->willReturn($index);
+
+ $schema = $this->createMock(Schema::class);
+ $schema->expects($this->once())
+ ->method('getTables')
+ ->willReturn([$table]);
+
+ self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testEnsureOracleIdentifierLengthLimitTooLongPrimaryWithName() {
+ $index = $this->createMock(Index::class);
+ $index->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 31));
+
+ $table = $this->createMock(Table::class);
+ $table->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 26));
+
+ $table->expects($this->once())
+ ->method('getColumns')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getIndexes')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getForeignKeys')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getPrimaryKey')
+ ->willReturn($index);
+
+ $schema = $this->createMock(Schema::class);
+ $schema->expects($this->once())
+ ->method('getTables')
+ ->willReturn([$table]);
+
+ self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testEnsureOracleIdentifierLengthLimitTooLongColumnName() {
+ $column = $this->createMock(Column::class);
+ $column->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 31));
+
+ $table = $this->createMock(Table::class);
+ $table->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 30));
+
+ $table->expects($this->once())
+ ->method('getColumns')
+ ->willReturn([$column]);
+
+ $schema = $this->createMock(Schema::class);
+ $schema->expects($this->once())
+ ->method('getTables')
+ ->willReturn([$table]);
+
+ self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testEnsureOracleIdentifierLengthLimitTooLongIndexName() {
+ $index = $this->createMock(Index::class);
+ $index->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 31));
+
+ $table = $this->createMock(Table::class);
+ $table->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 30));
+
+ $table->expects($this->once())
+ ->method('getColumns')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getIndexes')
+ ->willReturn([$index]);
+
+ $schema = $this->createMock(Schema::class);
+ $schema->expects($this->once())
+ ->method('getTables')
+ ->willReturn([$table]);
+
+ self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testEnsureOracleIdentifierLengthLimitTooLongForeignKeyName() {
+ $foreignKey = $this->createMock(ForeignKeyConstraint::class);
+ $foreignKey->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 31));
+
+ $table = $this->createMock(Table::class);
+ $table->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 30));
+
+ $table->expects($this->once())
+ ->method('getColumns')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getIndexes')
+ ->willReturn([]);
+ $table->expects($this->once())
+ ->method('getForeignKeys')
+ ->willReturn([$foreignKey]);
+
+ $schema = $this->createMock(Schema::class);
+ $schema->expects($this->once())
+ ->method('getTables')
+ ->willReturn([$table]);
+
+ self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ public function testEnsureOracleIdentifierLengthLimitTooLongSequenceName() {
+ $sequence = $this->createMock(Sequence::class);
+ $sequence->expects($this->any())
+ ->method('getName')
+ ->willReturn(\str_repeat('a', 31));
+
+ $schema = $this->createMock(Schema::class);
+ $schema->expects($this->once())
+ ->method('getTables')
+ ->willReturn([]);
+ $schema->expects($this->once())
+ ->method('getSequences')
+ ->willReturn([$sequence]);
+
+ self::invokePrivate($this->migrationService, 'ensureOracleIdentifierLengthLimit', [$schema]);
+ }
}