123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <?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.
- */
- namespace Test;
- use bantu\IniGetWrapper\IniGetWrapper;
- use OC\Installer;
- use OC\Setup;
- use OC\SystemConfig;
- use OCP\Defaults;
- use OCP\IL10N;
- use OCP\Security\ISecureRandom;
- use PHPUnit\Framework\MockObject\MockObject;
- use Psr\Log\LoggerInterface;
- class SetupTest extends \Test\TestCase {
- /** @var SystemConfig|MockObject */
- protected $config;
- /** @var \bantu\IniGetWrapper\IniGetWrapper|MockObject */
- private $iniWrapper;
- /** @var \OCP\IL10N|MockObject */
- private $l10n;
- /** @var Defaults|MockObject */
- private $defaults;
- /** @var \OC\Setup|MockObject */
- protected $setupClass;
- /** @var LoggerInterface|MockObject */
- protected $logger;
- /** @var \OCP\Security\ISecureRandom|MockObject */
- protected $random;
- /** @var Installer|MockObject */
- protected $installer;
- protected function setUp(): void {
- parent::setUp();
- $this->config = $this->createMock(SystemConfig::class);
- $this->iniWrapper = $this->createMock(IniGetWrapper::class);
- $this->l10n = $this->createMock(IL10N::class);
- $this->defaults = $this->createMock(Defaults::class);
- $this->logger = $this->createMock(LoggerInterface::class);
- $this->random = $this->createMock(ISecureRandom::class);
- $this->installer = $this->createMock(Installer::class);
- $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();
- }
- public function testGetSupportedDatabasesWithOneWorking() {
- $this->config
- ->expects($this->once())
- ->method('getValue')
- ->willReturn(
- ['sqlite', 'mysql', 'oci']
- );
- $this->setupClass
- ->expects($this->once())
- ->method('is_callable')
- ->willReturn(false);
- $this->setupClass
- ->expects($this->any())
- ->method('getAvailableDbDriversForPdo')
- ->willReturn(['sqlite']);
- $result = $this->setupClass->getSupportedDatabases();
- $expectedResult = [
- 'sqlite' => 'SQLite'
- ];
- $this->assertSame($expectedResult, $result);
- }
- public function testGetSupportedDatabasesWithNoWorking() {
- $this->config
- ->expects($this->once())
- ->method('getValue')
- ->willReturn(
- ['sqlite', 'mysql', 'oci', 'pgsql']
- );
- $this->setupClass
- ->expects($this->any())
- ->method('is_callable')
- ->willReturn(false);
- $this->setupClass
- ->expects($this->any())
- ->method('getAvailableDbDriversForPdo')
- ->willReturn([]);
- $result = $this->setupClass->getSupportedDatabases();
- $this->assertSame([], $result);
- }
- public function testGetSupportedDatabasesWithAllWorking() {
- $this->config
- ->expects($this->once())
- ->method('getValue')
- ->willReturn(
- ['sqlite', 'mysql', 'pgsql', 'oci']
- );
- $this->setupClass
- ->expects($this->any())
- ->method('is_callable')
- ->willReturn(true);
- $this->setupClass
- ->expects($this->any())
- ->method('getAvailableDbDriversForPdo')
- ->willReturn(['sqlite', 'mysql', 'pgsql']);
- $result = $this->setupClass->getSupportedDatabases();
- $expectedResult = [
- 'sqlite' => 'SQLite',
- 'mysql' => 'MySQL/MariaDB',
- 'pgsql' => 'PostgreSQL',
- 'oci' => 'Oracle'
- ];
- $this->assertSame($expectedResult, $result);
- }
- public function testGetSupportedDatabaseException() {
- $this->expectException(\Exception::class);
- $this->expectExceptionMessage('Supported databases are not properly configured.');
- $this->config
- ->expects($this->once())
- ->method('getValue')
- ->willReturn('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')
- ->willReturn($url);
- \OC::$CLI = true;
- try {
- $webRoot = self::invokePrivate($this->setupClass, 'findWebRoot', [$this->config]);
- } catch (\InvalidArgumentException $e) {
- $webRoot = false;
- }
- \OC::$CLI = $cliState;
- $this->assertSame($webRoot, $expected);
- }
- public function findWebRootProvider(): array {
- return [
- 'https://www.example.com/nextcloud/' => ['https://www.example.com/nextcloud/', '/nextcloud'],
- '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', ''],
- 'https://nctest13pgsql.lan/test123/' => ['https://nctest13pgsql.lan/test123/', '/test123'],
- 'https://nctest13pgsql.lan/test123' => ['https://nctest13pgsql.lan/test123', '/test123'],
- 'https://nctest13pgsql.lan/' => ['https://nctest13pgsql.lan/', ''],
- 'https://nctest13pgsql.lan' => ['https://nctest13pgsql.lan', ''],
- 'https://192.168.10.10/nc/' => ['https://192.168.10.10/nc/', '/nc'],
- 'https://192.168.10.10/nc' => ['https://192.168.10.10/nc', '/nc'],
- 'https://192.168.10.10/' => ['https://192.168.10.10/', ''],
- 'https://192.168.10.10' => ['https://192.168.10.10', ''],
- 'invalid' => ['invalid', false],
- 'empty' => ['', false],
- ];
- }
- }
|