diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2018-09-26 16:22:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-26 16:22:30 +0300 |
commit | ff55bcdad5c2c36375c41eb641b87bc70967e384 (patch) | |
tree | 3101462c038f9a38c4b22b4b5e664eef9268177d /tests | |
parent | fb17f1a26b3643744e09c89bf770bff5767b0ccb (diff) | |
parent | 3b7ac0c94d473b9458d39e4d0b1d4d33cd31c379 (diff) |
Merge pull request #11150 from nextcloud/feature/noid/unit-test-find-webroot
Extract logic for webroot into method and add test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/SetupTest.php | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/tests/lib/SetupTest.php b/tests/lib/SetupTest.php index e6e9fb5c56c..628f9393c15 100644 --- a/tests/lib/SetupTest.php +++ b/tests/lib/SetupTest.php @@ -10,6 +10,7 @@ namespace Test; use bantu\IniGetWrapper\IniGetWrapper; use OC\Installer; +use OC\Setup; use OC\SystemConfig; use OCP\Defaults; use OCP\IL10N; @@ -45,7 +46,7 @@ class SetupTest extends \Test\TestCase { $this->logger = $this->createMock(ILogger::class); $this->random = $this->createMock(ISecureRandom::class); $this->installer = $this->createMock(Installer::class); - $this->setupClass = $this->getMockBuilder('\OC\Setup') + $this->setupClass = $this->getMockBuilder(Setup::class) ->setMethods(['class_exists', 'is_callable', 'getAvailableDbDriversForPdo']) ->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random, $this->installer]) ->getMock(); @@ -56,7 +57,7 @@ class SetupTest extends \Test\TestCase { ->expects($this->once()) ->method('getValue') ->will($this->returnValue( - array('sqlite', 'mysql', 'oci') + ['sqlite', 'mysql', 'oci'] )); $this->setupClass ->expects($this->once()) @@ -67,9 +68,9 @@ class SetupTest extends \Test\TestCase { ->method('getAvailableDbDriversForPdo') ->will($this->returnValue(['sqlite'])); $result = $this->setupClass->getSupportedDatabases(); - $expectedResult = array( + $expectedResult = [ 'sqlite' => 'SQLite' - ); + ]; $this->assertSame($expectedResult, $result); } @@ -79,7 +80,7 @@ class SetupTest extends \Test\TestCase { ->expects($this->once()) ->method('getValue') ->will($this->returnValue( - array('sqlite', 'mysql', 'oci', 'pgsql') + ['sqlite', 'mysql', 'oci', 'pgsql'] )); $this->setupClass ->expects($this->any()) @@ -91,7 +92,7 @@ class SetupTest extends \Test\TestCase { ->will($this->returnValue([])); $result = $this->setupClass->getSupportedDatabases(); - $this->assertSame(array(), $result); + $this->assertSame([], $result); } public function testGetSupportedDatabasesWithAllWorking() { @@ -99,7 +100,7 @@ class SetupTest extends \Test\TestCase { ->expects($this->once()) ->method('getValue') ->will($this->returnValue( - array('sqlite', 'mysql', 'pgsql', 'oci') + ['sqlite', 'mysql', 'pgsql', 'oci'] )); $this->setupClass ->expects($this->any()) @@ -110,12 +111,12 @@ class SetupTest extends \Test\TestCase { ->method('getAvailableDbDriversForPdo') ->will($this->returnValue(['sqlite', 'mysql', 'pgsql'])); $result = $this->setupClass->getSupportedDatabases(); - $expectedResult = array( + $expectedResult = [ 'sqlite' => 'SQLite', 'mysql' => 'MySQL/MariaDB', 'pgsql' => 'PostgreSQL', 'oci' => 'Oracle' - ); + ]; $this->assertSame($expectedResult, $result); } @@ -130,4 +131,37 @@ class SetupTest extends \Test\TestCase { ->will($this->returnValue('NotAnArray')); $this->setupClass->getSupportedDatabases(); } + + /** + * @dataProvider findWebRootProvider + * @param $url + * @param $expected + */ + public function testFindWebRootCli($url, $expected) { + $cliState = \OC::$CLI; + + $this->config + ->expects($this->once()) + ->method('getValue') + ->will($this->returnValue($url)); + \OC::$CLI = true; + + try { + $webRoot = self::invokePrivate($this->setupClass, 'findWebRoot', [$this->config]); + } catch (\InvalidArgumentException $e) { + $webRoot = false; + } + + \OC::$CLI = $cliState; + $this->assertEquals($webRoot, $expected); + } + + public function findWebRootProvider(): array { + return [ + 'https://www.example.com/nextcloud' => ['https://www.example.com/nextcloud', '/nextcloud'], + 'https://www.example.com/' => ['https://www.example.com/', ''], + 'https://www.example.com' => ['https://www.example.com', false], + 'empty' => ['', false], + ]; + } } |