diff options
Diffstat (limited to 'apps/updatenotification/tests/Settings/AdminTest.php')
-rw-r--r-- | apps/updatenotification/tests/Settings/AdminTest.php | 135 |
1 files changed, 78 insertions, 57 deletions
diff --git a/apps/updatenotification/tests/Settings/AdminTest.php b/apps/updatenotification/tests/Settings/AdminTest.php index ed0b12ab10f..0429c628049 100644 --- a/apps/updatenotification/tests/Settings/AdminTest.php +++ b/apps/updatenotification/tests/Settings/AdminTest.php @@ -4,10 +4,12 @@ declare(strict_types=1); /** * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCA\UpdateNotification\Tests\Settings; +use OCA\UpdateNotification\AppInfo\Application; use OCA\UpdateNotification\Settings\Admin; use OCA\UpdateNotification\UpdateChecker; use OCP\AppFramework\Http\TemplateResponse; @@ -20,34 +22,25 @@ use OCP\IGroupManager; use OCP\IUserManager; use OCP\L10N\IFactory; use OCP\L10N\ILanguageIterator; +use OCP\ServerVersion; use OCP\Support\Subscription\IRegistry; -use OCP\Util; +use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; use Test\TestCase; class AdminTest extends TestCase { - /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */ - protected $l10nFactory; - /** @var Admin */ - private $admin; - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ - private $config; - /** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */ - private $appConfig; - /** @var UpdateChecker|\PHPUnit\Framework\MockObject\MockObject */ - private $updateChecker; - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ - private $groupManager; - /** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */ - private $dateTimeFormatter; - /** @var IRegistry|\PHPUnit\Framework\MockObject\MockObject */ - private $subscriptionRegistry; - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ - private $userManager; - /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ - private $logger; - /** IInitialState|\PHPUnit\Framework\MockObject\MockObject */ - private $initialState; + private IFactory&MockObject $l10nFactory; + private IConfig&MockObject $config; + private IAppConfig&MockObject $appConfig; + private UpdateChecker&MockObject $updateChecker; + private IGroupManager&MockObject $groupManager; + private IDateTimeFormatter&MockObject $dateTimeFormatter; + private IRegistry&MockObject $subscriptionRegistry; + private IUserManager&MockObject $userManager; + private LoggerInterface&MockObject $logger; + private IInitialState&MockObject $initialState; + private ServerVersion&MockObject $serverVersion; + private Admin $admin; protected function setUp(): void { parent::setUp(); @@ -62,6 +55,7 @@ class AdminTest extends TestCase { $this->userManager = $this->createMock(IUserManager::class); $this->logger = $this->createMock(LoggerInterface::class); $this->initialState = $this->createMock(IInitialState::class); + $this->serverVersion = $this->createMock(ServerVersion::class); $this->admin = new Admin( $this->config, @@ -73,11 +67,15 @@ class AdminTest extends TestCase { $this->subscriptionRegistry, $this->userManager, $this->logger, - $this->initialState + $this->initialState, + $this->serverVersion, ); } public function testGetFormWithUpdate(): void { + $this->serverVersion->expects(self::atLeastOnce()) + ->method('getChannel') + ->willReturn('daily'); $this->userManager ->expects($this->once()) ->method('countUsersTotal') @@ -88,26 +86,27 @@ class AdminTest extends TestCase { 'stable', 'production', ]; - $currentChannel = Util::getChannel(); - if ($currentChannel === 'git') { - $channels[] = 'git'; - } $this->appConfig ->expects($this->once()) ->method('getValueInt') ->with('core', 'lastupdatedat', 0) ->willReturn(12345); - $this->config + $this->appConfig ->expects($this->once()) - ->method('getAppValue') - ->with('updatenotification', 'notify_groups', '["admin"]') - ->willReturn('["admin"]'); + ->method('getValueArray') + ->with(Application::APP_NAME, 'notify_groups', ['admin']) + ->willReturn(['admin']); $this->config ->method('getSystemValue') ->willReturnMap([ ['updater.server.url', 'https://updates.nextcloud.com/updater_server/', 'https://updates.nextcloud.com/updater_server/'], ['upgrade.disable-web', false, false], ]); + $this->config + ->expects(self::any()) + ->method('getSystemValueBool') + ->with('updatechecker', true) + ->willReturn(true); $this->dateTimeFormatter ->expects($this->once()) ->method('formatDateTime') @@ -149,7 +148,7 @@ class AdminTest extends TestCase { 'isNewVersionAvailable' => true, 'isUpdateChecked' => true, 'lastChecked' => 'LastCheckedReturnValue', - 'currentChannel' => Util::getChannel(), + 'currentChannel' => 'daily', 'channels' => $channels, 'newVersion' => '8.1.2', 'newVersionString' => 'Nextcloud 8.1.2', @@ -167,11 +166,14 @@ class AdminTest extends TestCase { 'hasValidSubscription' => true, ]); - $expected = new TemplateResponse('updatenotification', 'admin', [], ''); + $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], ''); $this->assertEquals($expected, $this->admin->getForm()); } public function testGetFormWithUpdateAndChangedUpdateServer(): void { + $this->serverVersion->expects(self::atLeastOnce()) + ->method('getChannel') + ->willReturn('beta'); $this->userManager ->expects($this->once()) ->method('countUsersTotal') @@ -182,10 +184,6 @@ class AdminTest extends TestCase { 'stable', 'production', ]; - $currentChannel = Util::getChannel(); - if ($currentChannel === 'git') { - $channels[] = 'git'; - } $this->appConfig ->expects($this->once()) @@ -193,10 +191,15 @@ class AdminTest extends TestCase { ->with('core', 'lastupdatedat', 0) ->willReturn(12345); $this->config + ->expects(self::any()) + ->method('getSystemValueBool') + ->with('updatechecker', true) + ->willReturn(true); + $this->appConfig ->expects($this->once()) - ->method('getAppValue') - ->with('updatenotification', 'notify_groups', '["admin"]') - ->willReturn('["admin"]'); + ->method('getValueArray') + ->with(Application::APP_NAME, 'notify_groups', ['admin']) + ->willReturn(['admin']); $this->config ->method('getSystemValue') ->willReturnMap([ @@ -244,7 +247,7 @@ class AdminTest extends TestCase { 'isNewVersionAvailable' => true, 'isUpdateChecked' => true, 'lastChecked' => 'LastCheckedReturnValue', - 'currentChannel' => Util::getChannel(), + 'currentChannel' => 'beta', 'channels' => $channels, 'newVersion' => '8.1.2', 'newVersionString' => 'Nextcloud 8.1.2', @@ -262,11 +265,14 @@ class AdminTest extends TestCase { 'hasValidSubscription' => true, ]); - $expected = new TemplateResponse('updatenotification', 'admin', [], ''); + $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], ''); $this->assertEquals($expected, $this->admin->getForm()); } public function testGetFormWithUpdateAndCustomersUpdateServer(): void { + $this->serverVersion->expects(self::atLeastOnce()) + ->method('getChannel') + ->willReturn('production'); $this->userManager ->expects($this->once()) ->method('countUsersTotal') @@ -277,10 +283,6 @@ class AdminTest extends TestCase { 'stable', 'production', ]; - $currentChannel = Util::getChannel(); - if ($currentChannel === 'git') { - $channels[] = 'git'; - } $this->appConfig ->expects($this->once()) @@ -288,10 +290,15 @@ class AdminTest extends TestCase { ->with('core', 'lastupdatedat', 0) ->willReturn(12345); $this->config - ->expects($this->once()) - ->method('getAppValue') - ->with('updatenotification', 'notify_groups', '["admin"]') - ->willReturn('["admin"]'); + ->expects(self::any()) + ->method('getSystemValueBool') + ->with('updatechecker', true) + ->willReturn(true); + $this->appConfig + ->expects(self::once()) + ->method('getValueArray') + ->with(Application::APP_NAME, 'notify_groups', ['admin']) + ->willReturn(['admin']); $this->config ->method('getSystemValue') ->willReturnMap([ @@ -339,7 +346,7 @@ class AdminTest extends TestCase { 'isNewVersionAvailable' => true, 'isUpdateChecked' => true, 'lastChecked' => 'LastCheckedReturnValue', - 'currentChannel' => Util::getChannel(), + 'currentChannel' => 'production', 'channels' => $channels, 'newVersion' => '8.1.2', 'newVersionString' => 'Nextcloud 8.1.2', @@ -357,20 +364,36 @@ class AdminTest extends TestCase { 'hasValidSubscription' => true, ]); - $expected = new TemplateResponse('updatenotification', 'admin', [], ''); + $expected = new TemplateResponse(Application::APP_NAME, 'admin', [], ''); $this->assertEquals($expected, $this->admin->getForm()); } public function testGetSection(): void { + $this->config + ->expects(self::atLeastOnce()) + ->method('getSystemValueBool') + ->with('updatechecker', true) + ->willReturn(true); + $this->assertSame('overview', $this->admin->getSection()); } + public function testGetSectionDisabled(): void { + $this->config + ->expects(self::atLeastOnce()) + ->method('getSystemValueBool') + ->with('updatechecker', true) + ->willReturn(false); + + $this->assertNull($this->admin->getSection()); + } + public function testGetPriority(): void { $this->assertSame(11, $this->admin->getPriority()); } - public function changesProvider() { + public static function changesProvider(): array { return [ [ #0, all info, en [ @@ -425,9 +448,7 @@ class AdminTest extends TestCase { ]; } - /** - * @dataProvider changesProvider - */ + #[\PHPUnit\Framework\Attributes\DataProvider('changesProvider')] public function testFilterChanges($changes, $userLang, $expectation): void { $iterator = $this->createMock(ILanguageIterator::class); $iterator->expects($this->any()) |