2017-01-16 05:48:28 -05:00
|
|
|
<?php
|
2021-04-14 11:05:19 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-01-16 05:48:28 -05:00
|
|
|
/**
|
2024-05-30 14:13:41 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2017-01-16 05:48:28 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCA\TwoFactorBackupCodes\Test\Unit\Activity;
|
|
|
|
|
|
|
|
|
|
use OCA\TwoFactorBackupCodes\Activity\Provider;
|
2024-09-18 10:16:58 -04:00
|
|
|
use OCP\Activity\Exceptions\UnknownActivityException;
|
2017-01-16 05:48:28 -05:00
|
|
|
use OCP\Activity\IEvent;
|
2017-06-20 08:25:24 -04:00
|
|
|
use OCP\Activity\IManager;
|
2017-01-16 05:48:28 -05:00
|
|
|
use OCP\IL10N;
|
|
|
|
|
use OCP\IURLGenerator;
|
|
|
|
|
use OCP\L10N\IFactory;
|
2025-05-13 16:23:39 -04:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2017-01-16 05:48:28 -05:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class ProviderTest extends TestCase {
|
2025-05-13 16:23:39 -04:00
|
|
|
private IFactory&MockObject $l10n;
|
|
|
|
|
private IURLGenerator&MockObject $urlGenerator;
|
|
|
|
|
private IManager&MockObject $activityManager;
|
|
|
|
|
private Provider $provider;
|
2017-01-16 05:48:28 -05:00
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2017-01-16 05:48:28 -05:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->l10n = $this->createMock(IFactory::class);
|
|
|
|
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
2017-06-20 08:25:24 -04:00
|
|
|
$this->activityManager = $this->createMock(IManager::class);
|
2017-01-16 05:48:28 -05:00
|
|
|
|
2017-06-20 08:25:24 -04:00
|
|
|
$this->provider = new Provider($this->l10n, $this->urlGenerator, $this->activityManager);
|
2017-01-16 05:48:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testParseUnrelated(): void {
|
|
|
|
|
$lang = 'ru';
|
|
|
|
|
$event = $this->createMock(IEvent::class);
|
|
|
|
|
$event->expects($this->once())
|
2017-01-16 06:48:09 -05:00
|
|
|
->method('getApp')
|
2017-01-16 05:48:28 -05:00
|
|
|
->willReturn('comments');
|
2024-09-18 10:16:58 -04:00
|
|
|
$this->expectException(UnknownActivityException::class);
|
2017-01-16 05:48:28 -05:00
|
|
|
|
|
|
|
|
$this->provider->parse($lang, $event);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-13 16:23:39 -04:00
|
|
|
public static function subjectData(): array {
|
2017-01-16 05:48:28 -05:00
|
|
|
return [
|
|
|
|
|
['codes_generated'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-07 08:21:48 -05:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'subjectData')]
|
2025-05-13 16:23:39 -04:00
|
|
|
public function testParse(string $subject): void {
|
2017-01-16 05:48:28 -05:00
|
|
|
$lang = 'ru';
|
|
|
|
|
$event = $this->createMock(IEvent::class);
|
|
|
|
|
$l = $this->createMock(IL10N::class);
|
|
|
|
|
|
|
|
|
|
$event->expects($this->once())
|
|
|
|
|
->method('getApp')
|
|
|
|
|
->willReturn('twofactor_backupcodes');
|
|
|
|
|
$this->l10n->expects($this->once())
|
|
|
|
|
->method('get')
|
|
|
|
|
->with('twofactor_backupcodes', $lang)
|
|
|
|
|
->willReturn($l);
|
|
|
|
|
$this->urlGenerator->expects($this->once())
|
|
|
|
|
->method('imagePath')
|
|
|
|
|
->with('core', 'actions/password.svg')
|
|
|
|
|
->willReturn('path/to/image');
|
|
|
|
|
$this->urlGenerator->expects($this->once())
|
|
|
|
|
->method('getAbsoluteURL')
|
|
|
|
|
->with('path/to/image')
|
|
|
|
|
->willReturn('absolute/path/to/image');
|
|
|
|
|
$event->expects($this->once())
|
|
|
|
|
->method('setIcon')
|
|
|
|
|
->with('absolute/path/to/image');
|
|
|
|
|
$event->expects($this->once())
|
|
|
|
|
->method('getSubject')
|
|
|
|
|
->willReturn($subject);
|
|
|
|
|
$event->expects($this->once())
|
|
|
|
|
->method('setParsedSubject');
|
|
|
|
|
|
|
|
|
|
$this->provider->parse($lang, $event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testParseInvalidSubject(): void {
|
|
|
|
|
$lang = 'ru';
|
|
|
|
|
$l = $this->createMock(IL10N::class);
|
|
|
|
|
$event = $this->createMock(IEvent::class);
|
|
|
|
|
|
|
|
|
|
$event->expects($this->once())
|
|
|
|
|
->method('getApp')
|
|
|
|
|
->willReturn('twofactor_backupcodes');
|
|
|
|
|
$this->l10n->expects($this->once())
|
|
|
|
|
->method('get')
|
|
|
|
|
->with('twofactor_backupcodes', $lang)
|
|
|
|
|
->willReturn($l);
|
|
|
|
|
$event->expects($this->once())
|
|
|
|
|
->method('getSubject')
|
|
|
|
|
->willReturn('unrelated');
|
|
|
|
|
|
2024-09-18 10:16:58 -04:00
|
|
|
$this->expectException(UnknownActivityException::class);
|
2017-01-16 05:48:28 -05:00
|
|
|
$this->provider->parse($lang, $event);
|
|
|
|
|
}
|
|
|
|
|
}
|