aboutsummaryrefslogtreecommitdiffstats
path: root/apps/theming/tests/Settings/AdminSectionTest.php
blob: a73eca1cc5a429f6c4a75c1233c4d8a380934055 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
 * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\Theming\Tests\Settings;

use OCA\Theming\AppInfo\Application;
use OCA\Theming\Settings\AdminSection;
use OCP\IL10N;
use OCP\IURLGenerator;
use Test\TestCase;

class AdminSectionTest extends TestCase {
	/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
	private $url;
	/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
	private $l;
	/** @var AdminSection */
	private $section;

	protected function setUp(): void {
		parent::setUp();
		$this->url = $this->createMock(IURLGenerator::class);
		$this->l = $this->createMock(IL10N::class);

		$this->section = new AdminSection(
			Application::APP_ID,
			$this->url,
			$this->l
		);
	}

	public function testGetID(): void {
		$this->assertSame('theming', $this->section->getID());
	}

	public function testGetName(): void {
		$this->l
			->expects($this->once())
			->method('t')
			->with('Theming')
			->willReturn('Theming');

		$this->assertSame('Theming', $this->section->getName());
	}

	public function testGetPriority(): void {
		$this->assertSame(30, $this->section->getPriority());
	}

	public function testGetIcon(): void {
		$this->url->expects($this->once())
			->method('imagePath')
			->with('theming', 'app-dark.svg')
			->willReturn('icon');

		$this->assertSame('icon', $this->section->getIcon());
	}
}
pan class="na">class); $this->l10nFactory = $this->createMock(IL10NFactory::class); $this->l10nFactory->method('get') ->willReturn($this->l10n); $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->l10nFactory, $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], ]; } }