diff options
author | Lukas Reschke <lukas@owncloud.com> | 2014-10-27 22:24:16 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2014-10-27 22:24:16 +0100 |
commit | d6380a53955e4de1a69e0a645821a7424e44135e (patch) | |
tree | 8529f9c75f1fd5e931fd0fb29366522d34ce27e3 /tests | |
parent | a00712aa65169b248cac8e541dfe69fd82082609 (diff) | |
parent | 79778d6a5118f3d024d1d4c1e001fba8fba13423 (diff) | |
download | nextcloud-server-d6380a53955e4de1a69e0a645821a7424e44135e.tar.gz nextcloud-server-d6380a53955e4de1a69e0a645821a7424e44135e.zip |
Merge pull request #11786 from owncloud/MakeSupportedDBsConfigurable
Make supported DBs configurable within config.php
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/setup.php | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/tests/lib/setup.php b/tests/lib/setup.php new file mode 100644 index 00000000000..2c1569dd800 --- /dev/null +++ b/tests/lib/setup.php @@ -0,0 +1,103 @@ +<?php +/** + * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +use OCP\IConfig; + +class Test_OC_Setup extends PHPUnit_Framework_TestCase { + + /** @var IConfig */ + protected $config; + /** @var \OC_Setup */ + protected $setupClass; + + public function setUp() { + $this->config = $this->getMock('\OCP\IConfig'); + $this->setupClass = $this->getMock('\OC_Setup', array('class_exists', 'is_callable'), array($this->config)); + } + + public function testGetSupportedDatabasesWithOneWorking() { + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->will($this->returnValue( + array('sqlite', 'mysql', 'oci') + )); + $this->setupClass + ->expects($this->once()) + ->method('class_exists') + ->will($this->returnValue(true)); + $this->setupClass + ->expects($this->exactly(2)) + ->method('is_callable') + ->will($this->returnValue(false)); + $result = $this->setupClass->getSupportedDatabases(); + $expectedResult = array( + 'sqlite' => 'SQLite' + ); + + $this->assertSame($expectedResult, $result); + } + + public function testGetSupportedDatabasesWithNoWorking() { + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->will($this->returnValue( + array('sqlite', 'mysql', 'oci', 'pgsql') + )); + $this->setupClass + ->expects($this->once()) + ->method('class_exists') + ->will($this->returnValue(false)); + $this->setupClass + ->expects($this->exactly(3)) + ->method('is_callable') + ->will($this->returnValue(false)); + $result = $this->setupClass->getSupportedDatabases(); + + $this->assertSame(array(), $result); + } + + public function testGetSupportedDatabasesWitAllWorking() { + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->will($this->returnValue( + array('sqlite', 'mysql', 'pgsql', 'oci', 'mssql') + )); + $this->setupClass + ->expects($this->once()) + ->method('class_exists') + ->will($this->returnValue(true)); + $this->setupClass + ->expects($this->exactly(4)) + ->method('is_callable') + ->will($this->returnValue(true)); + $result = $this->setupClass->getSupportedDatabases(); + $expectedResult = array( + 'sqlite' => 'SQLite', + 'mysql' => 'MySQL/MariaDB', + 'pgsql' => 'PostgreSQL', + 'oci' => 'Oracle', + 'mssql' => 'MS SQL' + ); + $this->assertSame($expectedResult, $result); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Supported databases are not properly configured. + */ + public function testGetSupportedDatabaseException() { + $this->config + ->expects($this->once()) + ->method('getSystemValue') + ->will($this->returnValue('NotAnArray')); + $this->setupClass->getSupportedDatabases(); + } +}
\ No newline at end of file |