diff options
Diffstat (limited to 'apps/updatenotification/tests/UpdateCheckerTest.php')
-rw-r--r-- | apps/updatenotification/tests/UpdateCheckerTest.php | 75 |
1 files changed, 42 insertions, 33 deletions
diff --git a/apps/updatenotification/tests/UpdateCheckerTest.php b/apps/updatenotification/tests/UpdateCheckerTest.php index 778b747e1fc..cffdc25d3e4 100644 --- a/apps/updatenotification/tests/UpdateCheckerTest.php +++ b/apps/updatenotification/tests/UpdateCheckerTest.php @@ -3,54 +3,39 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ namespace OCA\UpdateNotification\Tests; use OC\Updater\ChangesCheck; use OC\Updater\VersionCheck; use OCA\UpdateNotification\UpdateChecker; +use OCP\AppFramework\Services\IInitialState; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class UpdateCheckerTest extends TestCase { - /** @var ChangesCheck|\PHPUnit\Framework\MockObject\MockObject */ - protected $changesChecker; - /** @var VersionCheck|\PHPUnit\Framework\MockObject\MockObject */ - private $updater; - /** @var UpdateChecker */ - private $updateChecker; + + private ChangesCheck&MockObject $changesChecker; + private VersionCheck&MockObject $updater; + private IInitialState&MockObject $initialState; + private UpdateChecker $updateChecker; protected function setUp(): void { parent::setUp(); $this->updater = $this->createMock(VersionCheck::class); $this->changesChecker = $this->createMock(ChangesCheck::class); - $this->updateChecker = new UpdateChecker($this->updater, $this->changesChecker); + $this->initialState = $this->createMock(IInitialState::class); + $this->updateChecker = new UpdateChecker( + $this->updater, + $this->changesChecker, + $this->initialState, + ); } - public function testGetUpdateStateWithUpdateAndInvalidLink() { + public function testGetUpdateStateWithUpdateAndInvalidLink(): void { $this->updater ->expects($this->once()) ->method('check') @@ -74,7 +59,7 @@ class UpdateCheckerTest extends TestCase { $this->assertSame($expected, $this->updateChecker->getUpdateState()); } - public function testGetUpdateStateWithUpdateAndValidLink() { + public function testGetUpdateStateWithUpdateAndValidLink(): void { $changes = [ 'changelog' => 'https://nextcloud.com/changelog/#123-0-0', 'whatsNew' => [ @@ -122,7 +107,7 @@ class UpdateCheckerTest extends TestCase { $this->assertSame($expected, $this->updateChecker->getUpdateState()); } - public function testGetUpdateStateWithoutUpdate() { + public function testGetUpdateStateWithoutUpdate(): void { $this->updater ->expects($this->once()) ->method('check') @@ -131,4 +116,28 @@ class UpdateCheckerTest extends TestCase { $expected = []; $this->assertSame($expected, $this->updateChecker->getUpdateState()); } + + public function testSetInitialState(): void { + $this->updater + ->expects($this->once()) + ->method('check') + ->willReturn([ + 'version' => '1.2.3', + 'versionstring' => 'Nextcloud 1.2.3', + 'web' => 'https://docs.nextcloud.com/myUrl', + 'url' => 'https://downloads.nextcloud.org/server', + 'changes' => 'https://updates.nextcloud.com/changelog_server/?version=123.0.0', + 'autoupdater' => '1', + 'eol' => '0', + ]); + + $this->initialState->expects(self::once()) + ->method('provideInitialState') + ->with('updateState', [ + 'updateVersion' => 'Nextcloud 1.2.3', + 'updateLink' => 'https://docs.nextcloud.com/myUrl', + ]); + + $this->updateChecker->setInitialState(); + } } |