diff options
Diffstat (limited to 'apps/encryption/tests/Controller/StatusControllerTest.php')
-rw-r--r-- | apps/encryption/tests/Controller/StatusControllerTest.php | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/apps/encryption/tests/Controller/StatusControllerTest.php b/apps/encryption/tests/Controller/StatusControllerTest.php new file mode 100644 index 00000000000..1bbcad77411 --- /dev/null +++ b/apps/encryption/tests/Controller/StatusControllerTest.php @@ -0,0 +1,74 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only + */ +namespace OCA\Encryption\Tests\Controller; + +use OCA\Encryption\Controller\StatusController; +use OCA\Encryption\Session; +use OCP\Encryption\IManager; +use OCP\IL10N; +use OCP\IRequest; +use PHPUnit\Framework\MockObject\MockObject; +use Test\TestCase; + +class StatusControllerTest extends TestCase { + + protected IRequest&MockObject $requestMock; + protected IL10N&MockObject $l10nMock; + protected Session&MockObject $sessionMock; + protected IManager&MockObject $encryptionManagerMock; + + protected StatusController $controller; + + protected function setUp(): void { + parent::setUp(); + + $this->sessionMock = $this->getMockBuilder(Session::class) + ->disableOriginalConstructor()->getMock(); + $this->requestMock = $this->createMock(IRequest::class); + + $this->l10nMock = $this->getMockBuilder(IL10N::class) + ->disableOriginalConstructor()->getMock(); + $this->l10nMock->expects($this->any()) + ->method('t') + ->willReturnCallback(function ($message) { + return $message; + }); + $this->encryptionManagerMock = $this->createMock(IManager::class); + + $this->controller = new StatusController('encryptionTest', + $this->requestMock, + $this->l10nMock, + $this->sessionMock, + $this->encryptionManagerMock); + } + + /** + * + * @param string $status + * @param string $expectedStatus + */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataTestGetStatus')] + public function testGetStatus($status, $expectedStatus): void { + $this->sessionMock->expects($this->once()) + ->method('getStatus')->willReturn($status); + $result = $this->controller->getStatus(); + $data = $result->getData(); + $this->assertSame($expectedStatus, $data['status']); + } + + public static function dataTestGetStatus(): array { + return [ + [Session::INIT_EXECUTED, 'interactionNeeded'], + [Session::INIT_SUCCESSFUL, 'success'], + [Session::NOT_INITIALIZED, 'interactionNeeded'], + ['unknown', 'error'], + ]; + } +} |