aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/tests/Activity/SecurityFilterTest.php
blob: b07c1e825b430c887c0b8365c71a11b13488519f (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
61
62
63
64
<?php

/**
 * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\Settings\Tests;

use OCA\Settings\Activity\SecurityFilter;
use OCP\IL10N;
use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class SecurityFilterTest extends TestCase {
	private IURLGenerator&MockObject $urlGenerator;
	private IL10N&MockObject $l10n;
	private SecurityFilter $filter;

	protected function setUp(): void {
		parent::setUp();

		$this->urlGenerator = $this->createMock(IURLGenerator::class);
		$this->l10n = $this->createMock(IL10N::class);

		$this->filter = new SecurityFilter($this->urlGenerator, $this->l10n);
	}

	public function testAllowedApps(): void {
		$this->assertEquals([], $this->filter->allowedApps());
	}

	public function testFilterTypes(): void {
		$this->assertEquals(['security'], $this->filter->filterTypes(['comments', 'security']));
	}

	public function testGetIcon(): void {
		$this->urlGenerator->expects($this->once())
			->method('imagePath')
			->with('core', 'actions/password.svg')
			->willReturn('path/to/icon.svg');
		$this->urlGenerator->expects($this->once())
			->method('getAbsoluteURL')
			->with('path/to/icon.svg')
			->willReturn('abs/path/to/icon.svg');
		$this->assertEquals('abs/path/to/icon.svg', $this->filter->getIcon());
	}

	public function testGetIdentifier(): void {
		$this->assertEquals('security', $this->filter->getIdentifier());
	}

	public function testGetName(): void {
		$this->l10n->expects($this->once())
			->method('t')
			->with('Security')
			->willReturn('translated');
		$this->assertEquals('translated', $this->filter->getName());
	}

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