diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php | 4 | ||||
-rw-r--r-- | tests/lib/db/migrator.php | 44 | ||||
-rw-r--r-- | tests/lib/util.php | 68 |
3 files changed, 103 insertions, 13 deletions
diff --git a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php index 47556ca9542..74fc7907fb5 100644 --- a/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php +++ b/tests/lib/appframework/middleware/security/SecurityMiddlewareTest.php @@ -313,7 +313,8 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { public function testAfterExceptionReturnsRedirect(){ $this->request = new Request( array('server' => - array('HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8') + array('HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', + 'REQUEST_URI' => 'owncloud/index.php/apps/specialapp') ) ); $this->middleware = $this->getMiddleware(true, true); @@ -321,6 +322,7 @@ class SecurityMiddlewareTest extends \PHPUnit_Framework_TestCase { $this->secException); $this->assertTrue($response instanceof RedirectResponse); + $this->assertEquals('?redirect_url=owncloud%2Findex.php%2Fapps%2Fspecialapp', $response->getRedirectURL()); } diff --git a/tests/lib/db/migrator.php b/tests/lib/db/migrator.php index e94d550f836..2e49086bd63 100644 --- a/tests/lib/db/migrator.php +++ b/tests/lib/db/migrator.php @@ -19,6 +19,11 @@ class Migrator extends \PHPUnit_Framework_TestCase { */ private $connection; + /** + * @var \OC\DB\MDB2SchemaManager + */ + private $manager; + private $tableName; public function setUp() { @@ -26,6 +31,7 @@ class Migrator extends \PHPUnit_Framework_TestCase { if ($this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\OCI8\Driver) { $this->markTestSkipped('DB migration tests arent supported on OCI'); } + $this->manager = new \OC\DB\MDB2SchemaManager($this->connection); $this->tableName = 'test_' . uniqid(); } @@ -62,14 +68,6 @@ class Migrator extends \PHPUnit_Framework_TestCase { return $this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver; } - private function getMigrator() { - if ($this->isSQLite()) { - return new \OC\DB\SQLiteMigrator($this->connection); - } else { - return new \OC\DB\Migrator($this->connection); - } - } - /** * @expectedException \OC\DB\MigrationException */ @@ -78,7 +76,7 @@ class Migrator extends \PHPUnit_Framework_TestCase { $this->markTestSkipped('sqlite doesnt throw errors when creating a new key on existing data'); } list($startSchema, $endSchema) = $this->getDuplicateKeySchemas(); - $migrator = $this->getMigrator(); + $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo')); @@ -91,7 +89,7 @@ class Migrator extends \PHPUnit_Framework_TestCase { public function testUpgrade() { list($startSchema, $endSchema) = $this->getDuplicateKeySchemas(); - $migrator = $this->getMigrator(); + $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); $this->connection->insert($this->tableName, array('id' => 1, 'name' => 'foo')); @@ -105,7 +103,7 @@ class Migrator extends \PHPUnit_Framework_TestCase { public function testInsertAfterUpgrade() { list($startSchema, $endSchema) = $this->getDuplicateKeySchemas(); - $migrator = $this->getMigrator(); + $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); $migrator->migrate($endSchema); @@ -132,7 +130,29 @@ class Migrator extends \PHPUnit_Framework_TestCase { $table->addColumn('name', 'string'); $table->setPrimaryKey(array('id')); - $migrator = $this->getMigrator(); + $migrator = $this->manager->getMigrator(); + $migrator->migrate($startSchema); + + $migrator->checkMigrate($endSchema); + $migrator->migrate($endSchema); + + $this->assertTrue(true); + } + + public function testReservedKeywords() { + $startSchema = new Schema(array(), array(), $this->getSchemaConfig()); + $table = $startSchema->createTable($this->tableName); + $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table->addColumn('user', 'string', array('length' => 255)); + $table->setPrimaryKey(array('id')); + + $endSchema = new Schema(array(), array(), $this->getSchemaConfig()); + $table = $endSchema->createTable($this->tableName); + $table->addColumn('id', 'integer', array('autoincrement' => true)); + $table->addColumn('user', 'string', array('length' => 64)); + $table->setPrimaryKey(array('id')); + + $migrator = $this->manager->getMigrator(); $migrator->migrate($startSchema); $migrator->checkMigrate($endSchema); diff --git a/tests/lib/util.php b/tests/lib/util.php index aaa47f033de..c2bb99c3b2e 100644 --- a/tests/lib/util.php +++ b/tests/lib/util.php @@ -290,4 +290,72 @@ class Test_Util extends PHPUnit_Framework_TestCase { array(array('g1', 'g2', 'g3'), array('g1', 'g2'), array('g1', 'g2', 'g3'), true), ); } + + /** + * Test default apps + * + * @dataProvider defaultAppsProvider + */ + function testDefaultApps($defaultAppConfig, $expectedPath, $enabledApps) { + $oldDefaultApps = \OCP\Config::getSystemValue('core', 'defaultapp', ''); + // CLI is doing messy stuff with the webroot, so need to work it around + $oldWebRoot = \OC::$WEBROOT; + \OC::$WEBROOT = ''; + + Dummy_OC_App::setEnabledApps($enabledApps); + \OCP\Config::setSystemValue('defaultapp', $defaultAppConfig); + $this->assertEquals('http://localhost/' . $expectedPath, \OC_Util::getDefaultPageUrl()); + + // restore old state + \OC::$WEBROOT = $oldWebRoot; + Dummy_OC_App::restore(); + \OCP\Config::setSystemValue('defaultapp', $oldDefaultApps); + } + + function defaultAppsProvider() { + return array( + // none specified, default to files + array( + '', + 'index.php/apps/files/', + array('files'), + ), + // unexisting or inaccessible app specified, default to files + array( + 'unexist', + 'index.php/apps/files/', + array('files'), + ), + // non-standard app + array( + 'calendar', + 'index.php/apps/calendar/', + array('files', 'calendar'), + ), + // non-standard app with fallback + array( + 'contacts,calendar', + 'index.php/apps/calendar/', + array('files', 'calendar'), + ), + ); + } + +} + +/** + * Dummy OC Apps class to make it possible to override + * enabled apps + */ +class Dummy_OC_App extends OC_App { + private static $enabledAppsCacheBackup; + + public static function setEnabledApps($enabledApps) { + self::$enabledAppsCacheBackup = self::$enabledAppsCache; + self::$enabledAppsCache = $enabledApps; + } + + public static function restore() { + self::$enabledAppsCache = self::$enabledAppsCacheBackup; + } } |