2016-02-09 13:58:29 -05:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-01-17 07:42:02 -05:00
|
|
|
declare(strict_types=1);
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2016-02-09 13:58:29 -05:00
|
|
|
/**
|
2024-05-30 14:13:41 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2016-02-09 13:58:29 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCA\UpdateNotification\Tests\Controller;
|
|
|
|
|
|
2024-03-04 17:14:09 -05:00
|
|
|
use OCA\UpdateNotification\BackgroundJob\ResetToken;
|
2016-02-09 13:58:29 -05:00
|
|
|
use OCA\UpdateNotification\Controller\AdminController;
|
|
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
|
|
|
use OCP\BackgroundJob\IJobList;
|
2024-03-04 17:14:09 -05:00
|
|
|
use OCP\IAppConfig;
|
2016-02-09 13:58:29 -05:00
|
|
|
use OCP\IConfig;
|
2016-03-04 07:56:13 -05:00
|
|
|
use OCP\IL10N;
|
2016-02-09 13:58:29 -05:00
|
|
|
use OCP\IRequest;
|
|
|
|
|
use OCP\Security\ISecureRandom;
|
2024-03-04 17:14:09 -05:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2016-02-09 13:58:29 -05:00
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class AdminControllerTest extends TestCase {
|
2024-03-04 17:14:09 -05:00
|
|
|
private IRequest|MockObject $request;
|
|
|
|
|
private IJobList|MockObject $jobList;
|
|
|
|
|
private ISecureRandom|MockObject $secureRandom;
|
|
|
|
|
private IConfig|MockObject $config;
|
|
|
|
|
private ITimeFactory|MockObject $timeFactory;
|
|
|
|
|
private IL10N|MockObject $l10n;
|
|
|
|
|
private IAppConfig|MockObject $appConfig;
|
|
|
|
|
|
|
|
|
|
private AdminController $adminController;
|
2016-02-09 13:58:29 -05:00
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function setUp(): void {
|
2016-02-09 13:58:29 -05:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2018-01-11 05:38:26 -05:00
|
|
|
$this->request = $this->createMock(IRequest::class);
|
|
|
|
|
$this->jobList = $this->createMock(IJobList::class);
|
|
|
|
|
$this->secureRandom = $this->createMock(ISecureRandom::class);
|
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2024-03-04 17:14:09 -05:00
|
|
|
$this->appConfig = $this->createMock(IAppConfig::class);
|
2018-01-11 05:38:26 -05:00
|
|
|
$this->timeFactory = $this->createMock(ITimeFactory::class);
|
|
|
|
|
$this->l10n = $this->createMock(IL10N::class);
|
2016-02-09 13:58:29 -05:00
|
|
|
|
|
|
|
|
$this->adminController = new AdminController(
|
|
|
|
|
'updatenotification',
|
|
|
|
|
$this->request,
|
|
|
|
|
$this->jobList,
|
|
|
|
|
$this->secureRandom,
|
|
|
|
|
$this->config,
|
2024-03-04 17:14:09 -05:00
|
|
|
$this->appConfig,
|
2016-03-04 07:56:13 -05:00
|
|
|
$this->timeFactory,
|
2018-01-15 06:06:03 -05:00
|
|
|
$this->l10n
|
2016-02-09 13:58:29 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCreateCredentials(): void {
|
|
|
|
|
$this->jobList
|
|
|
|
|
->expects($this->once())
|
|
|
|
|
->method('add')
|
2024-03-04 17:14:09 -05:00
|
|
|
->with(ResetToken::class);
|
2016-02-09 13:58:29 -05:00
|
|
|
$this->secureRandom
|
|
|
|
|
->expects($this->once())
|
|
|
|
|
->method('generate')
|
2016-02-10 08:41:47 -05:00
|
|
|
->with(64)
|
2016-02-09 13:58:29 -05:00
|
|
|
->willReturn('MyGeneratedToken');
|
|
|
|
|
$this->config
|
|
|
|
|
->expects($this->once())
|
|
|
|
|
->method('setSystemValue')
|
2016-02-10 08:41:47 -05:00
|
|
|
->with('updater.secret');
|
2016-02-09 13:58:29 -05:00
|
|
|
$this->timeFactory
|
|
|
|
|
->expects($this->once())
|
|
|
|
|
->method('getTime')
|
|
|
|
|
->willReturn(12345);
|
2024-03-07 19:35:04 -05:00
|
|
|
$this->appConfig
|
2016-02-09 13:58:29 -05:00
|
|
|
->expects($this->once())
|
2024-03-07 19:35:04 -05:00
|
|
|
->method('setValueInt')
|
2016-02-09 13:58:29 -05:00
|
|
|
->with('core', 'updater.secret.created', 12345);
|
|
|
|
|
|
|
|
|
|
$expected = new DataResponse('MyGeneratedToken');
|
|
|
|
|
$this->assertEquals($expected, $this->adminController->createCredentials());
|
|
|
|
|
}
|
|
|
|
|
}
|