2015-05-27 05:10:06 -04:00
|
|
|
<?php
|
2024-05-28 10:42:42 -04:00
|
|
|
|
2025-05-28 04:59:55 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2015-05-27 05:10:06 -04:00
|
|
|
/**
|
2024-05-28 10:42:42 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-05-27 05:10:06 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Encryption\Tests\Controller;
|
|
|
|
|
|
|
|
|
|
use OCA\Encryption\Controller\StatusController;
|
|
|
|
|
use OCA\Encryption\Session;
|
2017-05-30 07:22:27 -04:00
|
|
|
use OCP\Encryption\IManager;
|
2017-10-24 09:26:53 -04:00
|
|
|
use OCP\IL10N;
|
2016-09-02 04:29:05 -04:00
|
|
|
use OCP\IRequest;
|
2025-05-28 04:59:55 -04:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2015-05-27 05:10:06 -04:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class StatusControllerTest extends TestCase {
|
|
|
|
|
|
2025-05-28 04:59:55 -04:00
|
|
|
protected IRequest&MockObject $requestMock;
|
|
|
|
|
protected IL10N&MockObject $l10nMock;
|
|
|
|
|
protected Session&MockObject $sessionMock;
|
|
|
|
|
protected IManager&MockObject $encryptionManagerMock;
|
2017-05-30 07:22:27 -04:00
|
|
|
|
2025-05-28 04:59:55 -04:00
|
|
|
protected StatusController $controller;
|
2015-05-27 05:10:06 -04:00
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2015-05-27 05:10:06 -04:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2017-10-26 07:46:16 -04:00
|
|
|
$this->sessionMock = $this->getMockBuilder(Session::class)
|
2015-05-27 05:10:06 -04:00
|
|
|
->disableOriginalConstructor()->getMock();
|
2016-09-02 04:29:05 -04:00
|
|
|
$this->requestMock = $this->createMock(IRequest::class);
|
2015-05-27 05:10:06 -04:00
|
|
|
|
2017-10-24 09:26:53 -04:00
|
|
|
$this->l10nMock = $this->getMockBuilder(IL10N::class)
|
2015-05-27 05:10:06 -04:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
$this->l10nMock->expects($this->any())
|
|
|
|
|
->method('t')
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($message) {
|
2015-05-27 05:10:06 -04:00
|
|
|
return $message;
|
2020-03-25 17:21:27 -04:00
|
|
|
});
|
2017-05-30 07:22:27 -04:00
|
|
|
$this->encryptionManagerMock = $this->createMock(IManager::class);
|
2015-05-27 05:10:06 -04:00
|
|
|
|
|
|
|
|
$this->controller = new StatusController('encryptionTest',
|
|
|
|
|
$this->requestMock,
|
|
|
|
|
$this->l10nMock,
|
2017-05-30 07:22:27 -04:00
|
|
|
$this->sessionMock,
|
|
|
|
|
$this->encryptionManagerMock);
|
2015-05-27 05:10:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param string $status
|
|
|
|
|
* @param string $expectedStatus
|
|
|
|
|
*/
|
2026-01-07 08:21:48 -05:00
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestGetStatus')]
|
2024-09-15 16:32:31 -04:00
|
|
|
public function testGetStatus($status, $expectedStatus): void {
|
2026-01-13 08:44:53 -05:00
|
|
|
$this->sessionMock->expects($this->atLeastOnce())
|
2015-05-27 05:10:06 -04:00
|
|
|
->method('getStatus')->willReturn($status);
|
|
|
|
|
$result = $this->controller->getStatus();
|
|
|
|
|
$data = $result->getData();
|
|
|
|
|
$this->assertSame($expectedStatus, $data['status']);
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-28 04:59:55 -04:00
|
|
|
public static function dataTestGetStatus(): array {
|
2018-03-01 09:23:17 -05:00
|
|
|
return [
|
|
|
|
|
[Session::INIT_EXECUTED, 'interactionNeeded'],
|
|
|
|
|
[Session::INIT_SUCCESSFUL, 'success'],
|
|
|
|
|
[Session::NOT_INITIALIZED, 'interactionNeeded'],
|
|
|
|
|
['unknown', 'error'],
|
|
|
|
|
];
|
2015-05-27 05:10:06 -04:00
|
|
|
}
|
|
|
|
|
}
|