2015-05-27 11:10:06 +02:00
|
|
|
<?php
|
2024-05-28 16:42:42 +02:00
|
|
|
|
2015-05-27 11:10:06 +02:00
|
|
|
/**
|
2024-05-28 16:42:42 +02: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 11:10:06 +02:00
|
|
|
*/
|
|
|
|
namespace OCA\Encryption\Tests\Controller;
|
|
|
|
|
|
|
|
use OCA\Encryption\Controller\StatusController;
|
|
|
|
use OCA\Encryption\Session;
|
2017-05-30 13:22:27 +02:00
|
|
|
use OCP\Encryption\IManager;
|
2017-10-24 15:26:53 +02:00
|
|
|
use OCP\IL10N;
|
2016-09-02 10:29:05 +02:00
|
|
|
use OCP\IRequest;
|
2015-05-27 11:10:06 +02:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class StatusControllerTest extends TestCase {
|
|
|
|
|
2024-10-18 12:04:22 +02:00
|
|
|
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-12 09:42:19 +02:00
|
|
|
private $requestMock;
|
2015-05-27 11:10:06 +02:00
|
|
|
|
2024-10-18 12:04:22 +02:00
|
|
|
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
2016-05-12 09:42:19 +02:00
|
|
|
private $l10nMock;
|
2015-05-27 11:10:06 +02:00
|
|
|
|
2024-10-10 12:40:31 +02:00
|
|
|
/** @var Session|\PHPUnit\Framework\MockObject\MockObject */
|
2015-05-27 11:10:06 +02:00
|
|
|
protected $sessionMock;
|
|
|
|
|
2020-08-11 21:32:18 +02:00
|
|
|
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
|
2017-05-30 13:22:27 +02:00
|
|
|
protected $encryptionManagerMock;
|
|
|
|
|
2015-05-27 11:10:06 +02:00
|
|
|
/** @var StatusController */
|
|
|
|
protected $controller;
|
|
|
|
|
2019-11-21 16:40:38 +01:00
|
|
|
protected function setUp(): void {
|
2015-05-27 11:10:06 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
2017-10-26 13:46:16 +02:00
|
|
|
$this->sessionMock = $this->getMockBuilder(Session::class)
|
2015-05-27 11:10:06 +02:00
|
|
|
->disableOriginalConstructor()->getMock();
|
2016-09-02 10:29:05 +02:00
|
|
|
$this->requestMock = $this->createMock(IRequest::class);
|
2015-05-27 11:10:06 +02:00
|
|
|
|
2017-10-24 15:26:53 +02:00
|
|
|
$this->l10nMock = $this->getMockBuilder(IL10N::class)
|
2015-05-27 11:10:06 +02:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$this->l10nMock->expects($this->any())
|
|
|
|
->method('t')
|
2020-04-09 13:53:40 +02:00
|
|
|
->willReturnCallback(function ($message) {
|
2015-05-27 11:10:06 +02:00
|
|
|
return $message;
|
2020-03-25 22:21:27 +01:00
|
|
|
});
|
2017-05-30 13:22:27 +02:00
|
|
|
$this->encryptionManagerMock = $this->createMock(IManager::class);
|
2015-05-27 11:10:06 +02:00
|
|
|
|
|
|
|
$this->controller = new StatusController('encryptionTest',
|
|
|
|
$this->requestMock,
|
|
|
|
$this->l10nMock,
|
2017-05-30 13:22:27 +02:00
|
|
|
$this->sessionMock,
|
|
|
|
$this->encryptionManagerMock);
|
2015-05-27 11:10:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataTestGetStatus
|
|
|
|
*
|
|
|
|
* @param string $status
|
|
|
|
* @param string $expectedStatus
|
|
|
|
*/
|
|
|
|
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 function dataTestGetStatus() {
|
2018-03-01 15:23:17 +01:00
|
|
|
return [
|
|
|
|
[Session::INIT_EXECUTED, 'interactionNeeded'],
|
|
|
|
[Session::INIT_SUCCESSFUL, 'success'],
|
|
|
|
[Session::NOT_INITIALIZED, 'interactionNeeded'],
|
|
|
|
['unknown', 'error'],
|
|
|
|
];
|
2015-05-27 11:10:06 +02:00
|
|
|
}
|
|
|
|
}
|