mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 14:50:17 -04:00
test: Migrate theming and sharebymail to PHPUnit10
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
913026047c
commit
bcf46ab575
21 changed files with 372 additions and 447 deletions
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -9,25 +11,18 @@ use OCA\ShareByMail\Capabilities;
|
|||
use OCA\ShareByMail\Settings\SettingsManager;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\Share\IManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class CapabilitiesTest extends TestCase {
|
||||
/** @var Capabilities */
|
||||
private $capabilities;
|
||||
|
||||
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $manager;
|
||||
|
||||
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $settingsManager;
|
||||
|
||||
/** @var IAppManager | \PHPUnit\Framework\MockObject\MockObject */
|
||||
private $appManager;
|
||||
private IManager&MockObject $manager;
|
||||
private SettingsManager&MockObject $settingsManager;
|
||||
private IAppManager&MockObject $appManager;
|
||||
private Capabilities $capabilities;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
|
||||
$this->manager = $this::createMock(IManager::class);
|
||||
$this->settingsManager = $this::createMock(SettingsManager::class);
|
||||
$this->appManager = $this::createMock(IAppManager::class);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -47,7 +49,7 @@ use Test\TestCase;
|
|||
* @group DB
|
||||
*/
|
||||
class ShareByMailProviderTest extends TestCase {
|
||||
|
||||
|
||||
private IDBConnection $connection;
|
||||
|
||||
private IL10N&MockObject $l;
|
||||
|
|
@ -71,25 +73,25 @@ class ShareByMailProviderTest extends TestCase {
|
|||
|
||||
$this->connection = Server::get(IDBConnection::class);
|
||||
|
||||
$this->l = $this->getMockBuilder(IL10N::class)->getMock();
|
||||
$this->l = $this->createMock(IL10N::class);
|
||||
$this->l->method('t')
|
||||
->willReturnCallback(function ($text, $parameters = []) {
|
||||
return vsprintf($text, $parameters);
|
||||
});
|
||||
$this->config = $this->getMockBuilder(IConfig::class)->getMock();
|
||||
$this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
|
||||
$this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock();
|
||||
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
|
||||
$this->secureRandom = $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock();
|
||||
$this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer')->getMock();
|
||||
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
|
||||
$this->share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$this->activityManager = $this->getMockBuilder('OCP\Activity\IManager')->getMock();
|
||||
$this->settingsManager = $this->getMockBuilder(SettingsManager::class)->disableOriginalConstructor()->getMock();
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->rootFolder = $this->createMock('OCP\Files\IRootFolder');
|
||||
$this->userManager = $this->createMock(IUserManager::class);
|
||||
$this->secureRandom = $this->createMock('\OCP\Security\ISecureRandom');
|
||||
$this->mailer = $this->createMock('\OCP\Mail\IMailer');
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->share = $this->createMock(IShare::class);
|
||||
$this->activityManager = $this->createMock('OCP\Activity\IManager');
|
||||
$this->settingsManager = $this->createMock(SettingsManager::class);
|
||||
$this->defaults = $this->createMock(Defaults::class);
|
||||
$this->hasher = $this->getMockBuilder(IHasher::class)->getMock();
|
||||
$this->eventDispatcher = $this->getMockBuilder(IEventDispatcher::class)->getMock();
|
||||
$this->shareManager = $this->getMockBuilder(IManager::class)->getMock();
|
||||
$this->hasher = $this->createMock(IHasher::class);
|
||||
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$this->shareManager = $this->createMock(IManager::class);
|
||||
|
||||
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
|
||||
$this->config->expects($this->any())->method('getAppValue')->with('core', 'enforce_strict_email_check')->willReturn('yes');
|
||||
|
|
@ -103,7 +105,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
*/
|
||||
private function getInstance(array $mockedMethods = []) {
|
||||
if (!empty($mockedMethods)) {
|
||||
return $this->getMockBuilder('OCA\ShareByMail\ShareByMailProvider')
|
||||
return $this->getMockBuilder(ShareByMailProvider::class)
|
||||
->setConstructorArgs([
|
||||
$this->config,
|
||||
$this->connection,
|
||||
|
|
@ -119,9 +121,9 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$this->defaults,
|
||||
$this->hasher,
|
||||
$this->eventDispatcher,
|
||||
$this->shareManager
|
||||
$this->shareManager,
|
||||
])
|
||||
->setMethods($mockedMethods)
|
||||
->onlyMethods($mockedMethods)
|
||||
->getMock();
|
||||
}
|
||||
|
||||
|
|
@ -140,7 +142,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$this->defaults,
|
||||
$this->hasher,
|
||||
$this->eventDispatcher,
|
||||
$this->shareManager
|
||||
$this->shareManager,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -156,10 +158,10 @@ class ShareByMailProviderTest extends TestCase {
|
|||
public function testCreate(): void {
|
||||
$expectedShare = $this->createMock(IShare::class);
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('user1');
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||
|
||||
$instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'sendEmail', 'sendPassword']);
|
||||
|
|
@ -185,10 +187,10 @@ class ShareByMailProviderTest extends TestCase {
|
|||
public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection(): void {
|
||||
$expectedShare = $this->createMock(IShare::class);
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@examplelölöl.com');
|
||||
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');
|
||||
|
|
@ -227,10 +229,10 @@ class ShareByMailProviderTest extends TestCase {
|
|||
public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithPermanentPassword(): void {
|
||||
$expectedShare = $this->createMock(IShare::class);
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');
|
||||
|
|
@ -273,10 +275,10 @@ class ShareByMailProviderTest extends TestCase {
|
|||
public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithoutPermanentPassword(): void {
|
||||
$expectedShare = $this->createMock(IShare::class);
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');
|
||||
|
|
@ -326,10 +328,10 @@ class ShareByMailProviderTest extends TestCase {
|
|||
public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPermanentPassword(): void {
|
||||
$expectedShare = $this->createMock(IShare::class);
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');
|
||||
|
|
@ -374,26 +376,36 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$message = $this->createMock(IMessage::class);
|
||||
$message->expects($this->exactly(2))->method('setTo')->with(['receiver@example.com']);
|
||||
$this->mailer->expects($this->exactly(2))->method('createMessage')->willReturn($message);
|
||||
$this->mailer->expects($this->exactly(2))->method('createEMailTemplate')
|
||||
->withConsecutive([
|
||||
'sharebymail.RecipientNotification', [
|
||||
$calls = [
|
||||
[
|
||||
'sharebymail.RecipientNotification',
|
||||
[
|
||||
'filename' => 'filename',
|
||||
'link' => 'https://example.com/file.txt',
|
||||
'initiator' => 'owner',
|
||||
'expiration' => null,
|
||||
'shareWith' => 'receiver@example.com',
|
||||
'note' => ''
|
||||
]
|
||||
'note' => '',
|
||||
],
|
||||
],
|
||||
[
|
||||
'sharebymail.RecipientPasswordNotification',
|
||||
[
|
||||
'sharebymail.RecipientPasswordNotification', [
|
||||
'filename' => 'filename',
|
||||
'password' => 'autogeneratedPassword',
|
||||
'initiator' => 'owner',
|
||||
'initiatorEmail' => null,
|
||||
'shareWith' => 'receiver@example.com',
|
||||
]
|
||||
]);
|
||||
'filename' => 'filename',
|
||||
'password' => 'autogeneratedPassword',
|
||||
'initiator' => 'owner',
|
||||
'initiatorEmail' => null,
|
||||
'shareWith' => 'receiver@example.com',
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->mailer->expects($this->exactly(2))
|
||||
->method('createEMailTemplate')
|
||||
->willReturnCallback(function () use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertEquals($expected, func_get_args());
|
||||
return $this->createMock(IEMailTemplate::class);
|
||||
});
|
||||
|
||||
// Main email notification is sent as well as the password
|
||||
// to the recipient because shareApiLinkEnforcePassword is enabled.
|
||||
|
|
@ -407,10 +419,10 @@ class ShareByMailProviderTest extends TestCase {
|
|||
public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordProtectionWithPermanentPassword(): void {
|
||||
$expectedShare = $this->createMock(IShare::class);
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');
|
||||
|
|
@ -448,26 +460,37 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$message = $this->createMock(IMessage::class);
|
||||
$message->expects($this->exactly(2))->method('setTo')->with(['receiver@example.com']);
|
||||
$this->mailer->expects($this->exactly(2))->method('createMessage')->willReturn($message);
|
||||
$this->mailer->expects($this->exactly(2))->method('createEMailTemplate')
|
||||
->withConsecutive([
|
||||
'sharebymail.RecipientNotification', [
|
||||
|
||||
$calls = [
|
||||
[
|
||||
'sharebymail.RecipientNotification',
|
||||
[
|
||||
'filename' => 'filename',
|
||||
'link' => 'https://example.com/file.txt',
|
||||
'initiator' => 'owner',
|
||||
'expiration' => null,
|
||||
'shareWith' => 'receiver@example.com',
|
||||
'note' => ''
|
||||
]
|
||||
'note' => '',
|
||||
],
|
||||
],
|
||||
[
|
||||
'sharebymail.RecipientPasswordNotification',
|
||||
[
|
||||
'sharebymail.RecipientPasswordNotification', [
|
||||
'filename' => 'filename',
|
||||
'password' => 'password',
|
||||
'initiator' => 'owner',
|
||||
'initiatorEmail' => null,
|
||||
'shareWith' => 'receiver@example.com',
|
||||
]
|
||||
]);
|
||||
'filename' => 'filename',
|
||||
'password' => 'password',
|
||||
'initiator' => 'owner',
|
||||
'initiatorEmail' => null,
|
||||
'shareWith' => 'receiver@example.com',
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->mailer->expects($this->exactly(2))
|
||||
->method('createEMailTemplate')
|
||||
->willReturnCallback(function () use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertEquals($expected, func_get_args());
|
||||
return $this->createMock(IEMailTemplate::class);
|
||||
});
|
||||
|
||||
// Main email notification is sent as well as the password
|
||||
// to the recipient because the password is set.
|
||||
|
|
@ -482,15 +505,15 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$expectedShare = $this->createMock(IShare::class);
|
||||
|
||||
// The owner of the share.
|
||||
$owner = $this->getMockBuilder(IUser::class)->getMock();
|
||||
$owner = $this->createMock(IUser::class);
|
||||
$this->userManager->expects($this->any())->method('get')->with('owner')->willReturn($owner);
|
||||
$owner->expects($this->any())->method('getEMailAddress')->willReturn('owner@example.com');
|
||||
$owner->expects($this->any())->method('getDisplayName')->willReturn('owner');
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(true);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');
|
||||
|
|
@ -525,28 +548,49 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword');
|
||||
|
||||
$message = $this->createMock(IMessage::class);
|
||||
$message->expects($this->exactly(2))->method('setTo')->withConsecutive([['receiver@example.com']], [['owner@example.com' => 'owner']]);
|
||||
$setToCalls = [
|
||||
[['receiver@example.com']],
|
||||
[['owner@example.com' => 'owner']],
|
||||
];
|
||||
$message->expects($this->exactly(2))
|
||||
->method('setTo')
|
||||
->willReturnCallback(function () use (&$setToCalls, $message) {
|
||||
$expected = array_shift($setToCalls);
|
||||
$this->assertEquals($expected, func_get_args());
|
||||
return $message;
|
||||
});
|
||||
$this->mailer->expects($this->exactly(2))->method('createMessage')->willReturn($message);
|
||||
$this->mailer->expects($this->exactly(2))->method('createEMailTemplate')
|
||||
->withConsecutive([
|
||||
'sharebymail.RecipientNotification', [
|
||||
|
||||
$calls = [
|
||||
[
|
||||
'sharebymail.RecipientNotification',
|
||||
[
|
||||
'filename' => 'filename',
|
||||
'link' => 'https://example.com/file.txt',
|
||||
'initiator' => 'owner',
|
||||
'expiration' => null,
|
||||
'shareWith' => 'receiver@example.com',
|
||||
'note' => ''
|
||||
]
|
||||
'note' => '',
|
||||
],
|
||||
],
|
||||
[
|
||||
'sharebymail.OwnerPasswordNotification',
|
||||
[
|
||||
'sharebymail.OwnerPasswordNotification', [
|
||||
'filename' => 'filename',
|
||||
'password' => 'autogeneratedPassword',
|
||||
'initiator' => 'owner',
|
||||
'initiatorEmail' => 'owner@example.com',
|
||||
'shareWith' => 'receiver@example.com',
|
||||
]
|
||||
]);
|
||||
'filename' => 'filename',
|
||||
'password' => 'autogeneratedPassword',
|
||||
'initiator' => 'owner',
|
||||
'initiatorEmail' => 'owner@example.com',
|
||||
'shareWith' => 'receiver@example.com',
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->mailer->expects($this->exactly(2))
|
||||
->method('createEMailTemplate')
|
||||
->willReturnCallback(function () use (&$calls) {
|
||||
$expected = array_shift($calls);
|
||||
$this->assertEquals($expected, func_get_args());
|
||||
return $this->createMock(IEMailTemplate::class);
|
||||
});
|
||||
|
||||
// Main email notification is sent as well as the password to owner
|
||||
// because the password is set and SendPasswordByTalk is enabled.
|
||||
|
|
@ -560,10 +604,10 @@ class ShareByMailProviderTest extends TestCase {
|
|||
public function sendNotificationToMultipleEmails() {
|
||||
$expectedShare = $this->createMock(IShare::class);
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('');
|
||||
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('owner');
|
||||
|
|
@ -572,7 +616,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$share->expects($this->any())->method('getNote')->willReturn('');
|
||||
$share->expects($this->any())->method('getToken')->willReturn('token');
|
||||
|
||||
$attributes = $this->getMockBuilder(IAttributes::class)->getMock();
|
||||
$attributes = $this->createMock(IAttributes::class);
|
||||
$share->expects($this->any())->method('getAttributes')->willReturn($attributes);
|
||||
$attributes->expects($this->any())->method('getAttribute')->with('shareWith', 'emails')->willReturn([
|
||||
'receiver1@example.com',
|
||||
|
|
@ -607,8 +651,8 @@ class ShareByMailProviderTest extends TestCase {
|
|||
->with($share, ['receiver1@example.com', 'receiver2@example.com', 'receiver3@example.com']);
|
||||
$instance->expects($this->once())->method('sendPassword')->with($share, 'password');
|
||||
$instance->expects($this->never())->method('sendPasswordToOwner');
|
||||
|
||||
|
||||
|
||||
|
||||
$message = $this->createMock(IMessage::class);
|
||||
$message->expects($this->never())->method('setTo');
|
||||
$message->expects($this->exactly(2))->method('setBcc')->with(['receiver1@example.com', 'receiver2@example.com', 'receiver3@example.com']);
|
||||
|
|
@ -626,7 +670,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$this->expectException(\Exception::class);
|
||||
|
||||
$this->share->expects($this->once())->method('getSharedWith')->willReturn('user1');
|
||||
$node = $this->getMockBuilder('OCP\Files\Node')->getMock();
|
||||
$node = $this->createMock('OCP\Files\Node');
|
||||
$node->expects($this->any())->method('getName')->willReturn('fileName');
|
||||
$this->share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
||||
|
|
@ -650,7 +694,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$this->share->expects($this->any())->method('getNote')->willReturn('Check this!');
|
||||
$this->share->expects($this->any())->method('getMailSend')->willReturn(true);
|
||||
|
||||
$node = $this->getMockBuilder('OCP\Files\Node')->getMock();
|
||||
$node = $this->createMock('OCP\Files\Node');
|
||||
$node->expects($this->any())->method('getName')->willReturn('fileName');
|
||||
$this->share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
||||
|
|
@ -788,7 +832,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$this->assertSame($note, $result[0]['note']);
|
||||
}
|
||||
|
||||
public function dataUpdateSendPassword() {
|
||||
public static function dataUpdateSendPassword(): array {
|
||||
return [
|
||||
['password', 'hashed', 'hashed new', false, false, true],
|
||||
['', 'hashed', 'hashed new', false, false, false],
|
||||
|
|
@ -802,28 +846,21 @@ class ShareByMailProviderTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataUpdateSendPassword
|
||||
*
|
||||
* @param string|null plainTextPassword
|
||||
* @param string originalPassword
|
||||
* @param string newPassword
|
||||
* @param string originalSendPasswordByTalk
|
||||
* @param string newSendPasswordByTalk
|
||||
* @param bool sendMail
|
||||
*/
|
||||
public function testUpdateSendPassword($plainTextPassword, string $originalPassword, string $newPassword, $originalSendPasswordByTalk, $newSendPasswordByTalk, bool $sendMail): void {
|
||||
public function testUpdateSendPassword(?string $plainTextPassword, string $originalPassword, string $newPassword, bool $originalSendPasswordByTalk, bool $newSendPasswordByTalk, bool $sendMail): void {
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('filename');
|
||||
|
||||
$this->settingsManager->method('sendPasswordByMail')->willReturn(true);
|
||||
|
||||
$originalShare = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$originalShare = $this->createMock(IShare::class);
|
||||
$originalShare->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||
$originalShare->expects($this->any())->method('getNode')->willReturn($node);
|
||||
$originalShare->expects($this->any())->method('getId')->willReturn(42);
|
||||
$originalShare->expects($this->any())->method('getPassword')->willReturn($originalPassword);
|
||||
$originalShare->expects($this->any())->method('getSendPasswordByTalk')->willReturn($originalSendPasswordByTalk);
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com');
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
$share->expects($this->any())->method('getId')->willReturn(42);
|
||||
|
|
@ -1155,8 +1192,8 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$provider = $this->getInstance(['sendMailNotification', 'createShareActivity']);
|
||||
$this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true);
|
||||
|
||||
$u1 = $userManager->createUser('testFed', md5(time()));
|
||||
$u2 = $userManager->createUser('testFed2', md5(time()));
|
||||
$u1 = $userManager->createUser('testFed', md5((string)time()));
|
||||
$u2 = $userManager->createUser('testFed2', md5((string)time()));
|
||||
|
||||
$folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');
|
||||
$file1 = $folder1->newFile('bar1');
|
||||
|
|
@ -1202,8 +1239,8 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$provider = $this->getInstance(['sendMailNotification', 'createShareActivity']);
|
||||
$this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true);
|
||||
|
||||
$u1 = $userManager->createUser('testFed', md5(time()));
|
||||
$u2 = $userManager->createUser('testFed2', md5(time()));
|
||||
$u1 = $userManager->createUser('testFed', md5((string)time()));
|
||||
$u2 = $userManager->createUser('testFed2', md5((string)time()));
|
||||
|
||||
$folder = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');
|
||||
|
||||
|
|
@ -1347,17 +1384,17 @@ class ShareByMailProviderTest extends TestCase {
|
|||
->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
|
||||
->willReturn('https://example.com/file.txt');
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('file.txt');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser');
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
$share->expects($this->any())->method('getId')->willReturn(42);
|
||||
$share->expects($this->any())->method('getNote')->willReturn('');
|
||||
$share->expects($this->any())->method('getToken')->willReturn('token');
|
||||
|
||||
|
||||
self::invokePrivate(
|
||||
$provider,
|
||||
'sendMailNotification',
|
||||
|
|
@ -1469,17 +1506,17 @@ class ShareByMailProviderTest extends TestCase {
|
|||
->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
|
||||
->willReturn('https://example.com/file.txt');
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('file.txt');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser');
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
$share->expects($this->any())->method('getId')->willReturn(42);
|
||||
$share->expects($this->any())->method('getNote')->willReturn('This is a note to the recipient');
|
||||
$share->expects($this->any())->method('getToken')->willReturn('token');
|
||||
|
||||
|
||||
self::invokePrivate(
|
||||
$provider,
|
||||
'sendMailNotification',
|
||||
|
|
@ -1596,10 +1633,10 @@ class ShareByMailProviderTest extends TestCase {
|
|||
->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
|
||||
->willReturn('https://example.com/file.txt');
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('file.txt');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser');
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
|
@ -1607,7 +1644,7 @@ class ShareByMailProviderTest extends TestCase {
|
|||
$share->expects($this->any())->method('getNote')->willReturn('');
|
||||
$share->expects($this->any())->method('getExpirationDate')->willReturn($expiration);
|
||||
$share->expects($this->any())->method('getToken')->willReturn('token');
|
||||
|
||||
|
||||
self::invokePrivate(
|
||||
$provider,
|
||||
'sendMailNotification',
|
||||
|
|
@ -1694,10 +1731,10 @@ class ShareByMailProviderTest extends TestCase {
|
|||
->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
|
||||
->willReturn('https://example.com/file.txt');
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('file.txt');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('InitiatorUser');
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
|
@ -1795,10 +1832,10 @@ class ShareByMailProviderTest extends TestCase {
|
|||
->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
|
||||
->willReturn('https://example.com/file.txt');
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('file.txt');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('OwnerUser');
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
|
@ -1892,10 +1929,10 @@ class ShareByMailProviderTest extends TestCase {
|
|||
->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
|
||||
->willReturn('https://example.com/file.txt');
|
||||
|
||||
$node = $this->getMockBuilder(File::class)->getMock();
|
||||
$node = $this->createMock(File::class);
|
||||
$node->expects($this->any())->method('getName')->willReturn('file.txt');
|
||||
|
||||
$share = $this->getMockBuilder(IShare::class)->getMock();
|
||||
$share = $this->createMock(IShare::class);
|
||||
$share->expects($this->any())->method('getSharedBy')->willReturn('InitiatorUser');
|
||||
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
|
||||
$share->expects($this->any())->method('getNode')->willReturn($node);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -24,22 +26,12 @@ use Test\TestCase;
|
|||
* @package OCA\Theming\Tests
|
||||
*/
|
||||
class CapabilitiesTest extends TestCase {
|
||||
/** @var ThemingDefaults|MockObject */
|
||||
protected $theming;
|
||||
|
||||
/** @var IURLGenerator|MockObject */
|
||||
protected $url;
|
||||
|
||||
/** @var IConfig|MockObject */
|
||||
protected $config;
|
||||
|
||||
/** @var Util|MockObject */
|
||||
protected $util;
|
||||
|
||||
protected ThemingDefaults&MockObject $theming;
|
||||
protected IURLGenerator&MockObject $url;
|
||||
protected IConfig&MockObject $config;
|
||||
protected Util&MockObject $util;
|
||||
protected IUserSession $userSession;
|
||||
|
||||
/** @var Capabilities */
|
||||
protected $capabilities;
|
||||
protected Capabilities $capabilities;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -58,7 +50,7 @@ class CapabilitiesTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public function dataGetCapabilities() {
|
||||
public static function dataGetCapabilities(): array {
|
||||
return [
|
||||
['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', '#fff', '#000', 'http://absolute/', true, [
|
||||
'name' => 'name',
|
||||
|
|
@ -133,18 +125,9 @@ class CapabilitiesTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataGetCapabilities
|
||||
* @param string $name
|
||||
* @param string $url
|
||||
* @param string $slogan
|
||||
* @param string $color
|
||||
* @param string $textColor
|
||||
* @param string $logo
|
||||
* @param string $background
|
||||
* @param string $baseUrl
|
||||
* @param bool $backgroundThemed
|
||||
* @param string[] $expected
|
||||
* @param non-empty-array<string, string> $expected
|
||||
*/
|
||||
public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $logo, $background, $backgroundColor, $backgroundTextColor, $baseUrl, $backgroundThemed, array $expected): void {
|
||||
public function testGetCapabilities(string $name, string $url, string $slogan, string $color, string $textColor, string $logo, string $background, string $backgroundColor, string $backgroundTextColor, string $baseUrl, bool $backgroundThemed, array $expected): void {
|
||||
$this->config->expects($this->once())
|
||||
->method('getAppValue')
|
||||
->willReturn($background);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -17,29 +19,19 @@ use OCP\AppFramework\Http\DataDisplayResponse;
|
|||
use OCP\AppFramework\Http\FileDisplayResponse;
|
||||
use OCP\AppFramework\Utility\ITimeFactory;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class IconControllerTest extends TestCase {
|
||||
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $request;
|
||||
/** @var ThemingDefaults|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $themingDefaults;
|
||||
/** @var ITimeFactory */
|
||||
private $timeFactory;
|
||||
/** @var IconController|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $iconController;
|
||||
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $config;
|
||||
/** @var IconBuilder|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $iconBuilder;
|
||||
/** @var FileAccessHelper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $fileAccessHelper;
|
||||
/** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $appManager;
|
||||
/** @var ImageManager */
|
||||
private $imageManager;
|
||||
private IRequest&MockObject $request;
|
||||
private ThemingDefaults&MockObject $themingDefaults;
|
||||
private ITimeFactory&MockObject $timeFactory;
|
||||
private IconBuilder&MockObject $iconBuilder;
|
||||
private FileAccessHelper&MockObject $fileAccessHelper;
|
||||
private IAppManager&MockObject $appManager;
|
||||
private ImageManager&MockObject $imageManager;
|
||||
private IconController $iconController;
|
||||
|
||||
protected function setUp(): void {
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -82,7 +84,7 @@ class ThemingControllerTest extends TestCase {
|
|||
parent::setUp();
|
||||
}
|
||||
|
||||
public function dataUpdateStylesheetSuccess() {
|
||||
public static function dataUpdateStylesheetSuccess(): array {
|
||||
return [
|
||||
['name', str_repeat('a', 250), 'Saved'],
|
||||
['url', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'],
|
||||
|
|
@ -97,12 +99,8 @@ class ThemingControllerTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataUpdateStylesheetSuccess
|
||||
*
|
||||
* @param string $setting
|
||||
* @param string $value
|
||||
* @param string $message
|
||||
*/
|
||||
public function testUpdateStylesheetSuccess($setting, $value, $message): void {
|
||||
public function testUpdateStylesheetSuccess(string $setting, string $value, string $message): void {
|
||||
$this->themingDefaults
|
||||
->expects($this->once())
|
||||
->method('set')
|
||||
|
|
@ -126,7 +124,7 @@ class ThemingControllerTest extends TestCase {
|
|||
$this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value));
|
||||
}
|
||||
|
||||
public function dataUpdateStylesheetError() {
|
||||
public static function dataUpdateStylesheetError(): array {
|
||||
$urls = [
|
||||
'url' => 'web address',
|
||||
'imprintUrl' => 'legal notice address',
|
||||
|
|
@ -159,12 +157,8 @@ class ThemingControllerTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataUpdateStylesheetError
|
||||
*
|
||||
* @param string $setting
|
||||
* @param string $value
|
||||
* @param string $message
|
||||
*/
|
||||
public function testUpdateStylesheetError($setting, $value, $message): void {
|
||||
public function testUpdateStylesheetError(string $setting, string $value, string $message): void {
|
||||
$this->themingDefaults
|
||||
->expects($this->never())
|
||||
->method('set')
|
||||
|
|
@ -254,9 +248,6 @@ class ThemingControllerTest extends TestCase {
|
|||
/**
|
||||
* Checks that trying to upload an SVG favicon without imagemagick
|
||||
* results in an unsupported media type response.
|
||||
*
|
||||
* @test
|
||||
* @return void
|
||||
*/
|
||||
public function testUploadSVGFaviconWithoutImagemagick(): void {
|
||||
$this->imageManager
|
||||
|
|
@ -344,7 +335,7 @@ class ThemingControllerTest extends TestCase {
|
|||
$this->assertEquals($expected, $this->themingController->uploadImage());
|
||||
}
|
||||
|
||||
public function dataUpdateImages() {
|
||||
public static function dataUpdateImages(): array {
|
||||
return [
|
||||
['image/jpeg', false],
|
||||
['image/jpeg', true],
|
||||
|
|
@ -355,8 +346,10 @@ class ThemingControllerTest extends TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
/** @dataProvider dataUpdateImages */
|
||||
public function testUpdateLogoNormalLogoUpload($mimeType, $folderExists = true): void {
|
||||
/**
|
||||
* @dataProvider dataUpdateImages
|
||||
*/
|
||||
public function testUpdateLogoNormalLogoUpload(string $mimeType, bool $folderExists = true): void {
|
||||
$tmpLogo = Server::get(ITempManager::class)->getTemporaryFolder() . '/logo.svg';
|
||||
$destination = Server::get(ITempManager::class)->getTemporaryFolder();
|
||||
|
||||
|
|
@ -407,8 +400,7 @@ class ThemingControllerTest extends TestCase {
|
|||
$this->assertEquals($expected, $this->themingController->uploadImage());
|
||||
}
|
||||
|
||||
/** @dataProvider dataUpdateImages */
|
||||
public function testUpdateLogoLoginScreenUpload($folderExists): void {
|
||||
public function testUpdateLogoLoginScreenUpload(): void {
|
||||
$tmpLogo = Server::get(ITempManager::class)->getTemporaryFolder() . 'logo.png';
|
||||
|
||||
touch($tmpLogo);
|
||||
|
|
@ -500,7 +492,7 @@ class ThemingControllerTest extends TestCase {
|
|||
$this->assertEquals($expected, $this->themingController->uploadImage());
|
||||
}
|
||||
|
||||
public function dataPhpUploadErrors() {
|
||||
public static function dataPhpUploadErrors(): array {
|
||||
return [
|
||||
[UPLOAD_ERR_INI_SIZE, 'The uploaded file exceeds the upload_max_filesize directive in php.ini'],
|
||||
[UPLOAD_ERR_FORM_SIZE, 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'],
|
||||
|
|
@ -515,7 +507,7 @@ class ThemingControllerTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataPhpUploadErrors
|
||||
*/
|
||||
public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload($error, $expectedErrorMessage): void {
|
||||
public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload(int $error, string $expectedErrorMessage): void {
|
||||
$this->request
|
||||
->expects($this->once())
|
||||
->method('getParam')
|
||||
|
|
@ -615,15 +607,17 @@ class ThemingControllerTest extends TestCase {
|
|||
$this->assertEquals($expected, $this->themingController->undo('MySetting'));
|
||||
}
|
||||
|
||||
public function dataUndoDelete() {
|
||||
public static function dataUndoDelete(): array {
|
||||
return [
|
||||
[ 'backgroundMime', 'background' ],
|
||||
[ 'logoMime', 'logo' ]
|
||||
];
|
||||
}
|
||||
|
||||
/** @dataProvider dataUndoDelete */
|
||||
public function testUndoDelete($value, $filename): void {
|
||||
/**
|
||||
* @dataProvider dataUndoDelete
|
||||
*/
|
||||
public function testUndoDelete(string $value, string $filename): void {
|
||||
$this->l10n
|
||||
->expects($this->once())
|
||||
->method('t')
|
||||
|
|
@ -722,7 +716,9 @@ class ThemingControllerTest extends TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
/** @dataProvider dataGetManifest */
|
||||
/**
|
||||
* @dataProvider dataGetManifest
|
||||
*/
|
||||
public function testGetManifest(bool $standalone): void {
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -27,25 +29,17 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|||
use Test\TestCase;
|
||||
|
||||
class UserThemeControllerTest extends TestCase {
|
||||
/** @var UserThemeController */
|
||||
private $userThemeController;
|
||||
|
||||
/** @var IRequest|MockObject */
|
||||
private $request;
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
/** @var IUserSession|MockObject */
|
||||
private $userSession;
|
||||
/** @var ThemeService|MockObject */
|
||||
private $themesService;
|
||||
/** @var ThemingDefaults */
|
||||
private $themingDefaults;
|
||||
/** @var BackgroundService|MockObject */
|
||||
private $backgroundService;
|
||||
private IRequest&MockObject $request;
|
||||
private IConfig&MockObject $config;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private ThemesService&MockObject $themesService;
|
||||
private ThemingDefaults&MockObject $themingDefaults;
|
||||
private BackgroundService&MockObject $backgroundService;
|
||||
private UserThemeController $userThemeController;
|
||||
|
||||
|
||||
/** @var ITheme[] */
|
||||
private $themes;
|
||||
private array $themes;
|
||||
|
||||
protected function setUp(): void {
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
|
|
@ -85,7 +79,7 @@ class UserThemeControllerTest extends TestCase {
|
|||
parent::setUp();
|
||||
}
|
||||
|
||||
public function dataTestThemes() {
|
||||
public static function dataTestThemes(): array {
|
||||
return [
|
||||
['default'],
|
||||
['light'],
|
||||
|
|
@ -100,11 +94,8 @@ class UserThemeControllerTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataTestThemes
|
||||
*
|
||||
* @param string $themeId
|
||||
* @param string $exception
|
||||
*/
|
||||
public function testEnableTheme($themeId, ?string $exception = null): void {
|
||||
public function testEnableTheme(string $themeId, ?string $exception = null): void {
|
||||
$this->themesService
|
||||
->expects($this->any())
|
||||
->method('getThemes')
|
||||
|
|
@ -120,11 +111,8 @@ class UserThemeControllerTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataTestThemes
|
||||
*
|
||||
* @param string $themeId
|
||||
* @param string $exception
|
||||
*/
|
||||
public function testDisableTheme($themeId, ?string $exception = null): void {
|
||||
public function testDisableTheme(string $themeId, ?string $exception = null): void {
|
||||
$this->themesService
|
||||
->expects($this->any())
|
||||
->method('getThemes')
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -14,24 +16,17 @@ use OCP\App\IAppManager;
|
|||
use OCP\Files\NotFoundException;
|
||||
use OCP\IConfig;
|
||||
use OCP\ServerVersion;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class IconBuilderTest extends TestCase {
|
||||
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
/** @var AppData */
|
||||
protected $appData;
|
||||
/** @var ThemingDefaults */
|
||||
protected $themingDefaults;
|
||||
/** @var Util */
|
||||
protected $util;
|
||||
/** @var ImageManager */
|
||||
protected $imageManager;
|
||||
/** @var IconBuilder */
|
||||
protected $iconBuilder;
|
||||
/** @var IAppManager */
|
||||
protected $appManager;
|
||||
protected IConfig&MockObject $config;
|
||||
protected AppData&MockObject $appData;
|
||||
protected ThemingDefaults&MockObject $themingDefaults;
|
||||
protected ImageManager&MockObject $imageManager;
|
||||
protected IAppManager&MockObject $appManager;
|
||||
protected Util $util;
|
||||
protected IconBuilder $iconBuilder;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -58,7 +53,7 @@ class IconBuilderTest extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function dataRenderAppIcon() {
|
||||
public static function dataRenderAppIcon(): array {
|
||||
return [
|
||||
['core', '#0082c9', 'touch-original.png'],
|
||||
['core', '#FF0000', 'touch-core-red.png'],
|
||||
|
|
@ -70,11 +65,8 @@ class IconBuilderTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataRenderAppIcon
|
||||
* @param $app
|
||||
* @param $color
|
||||
* @param $file
|
||||
*/
|
||||
public function testRenderAppIcon($app, $color, $file): void {
|
||||
public function testRenderAppIcon(string $app, string $color, string $file): void {
|
||||
$this->checkImagick();
|
||||
$this->themingDefaults->expects($this->once())
|
||||
->method('getColorPrimary')
|
||||
|
|
@ -99,11 +91,8 @@ class IconBuilderTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataRenderAppIcon
|
||||
* @param $app
|
||||
* @param $color
|
||||
* @param $file
|
||||
*/
|
||||
public function testGetTouchIcon($app, $color, $file): void {
|
||||
public function testGetTouchIcon(string $app, string $color, string $file): void {
|
||||
$this->checkImagick();
|
||||
$this->themingDefaults->expects($this->once())
|
||||
->method('getColorPrimary')
|
||||
|
|
@ -129,11 +118,8 @@ class IconBuilderTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider dataRenderAppIcon
|
||||
* @param $app
|
||||
* @param $color
|
||||
* @param $file
|
||||
*/
|
||||
public function testGetFavicon($app, $color, $file): void {
|
||||
public function testGetFavicon(string $app, string $color, string $file): void {
|
||||
$this->checkImagick();
|
||||
$this->imageManager->expects($this->once())
|
||||
->method('shouldReplaceIcons')
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -20,24 +22,14 @@ use Psr\Log\LoggerInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class ImageManagerTest extends TestCase {
|
||||
/** @var IConfig|MockObject */
|
||||
protected $config;
|
||||
/** @var IAppData|MockObject */
|
||||
protected $appData;
|
||||
/** @var ImageManager */
|
||||
protected $imageManager;
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
/** @var ICacheFactory|MockObject */
|
||||
private $cacheFactory;
|
||||
/** @var LoggerInterface|MockObject */
|
||||
private $logger;
|
||||
/** @var ITempManager|MockObject */
|
||||
private $tempManager;
|
||||
/** @var ISimpleFolder|MockObject */
|
||||
private $rootFolder;
|
||||
/** @var BackgroundService|MockObject */
|
||||
private $backgroundService;
|
||||
protected IConfig&MockObject $config;
|
||||
protected IAppData&MockObject $appData;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private ICacheFactory&MockObject $cacheFactory;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
private ITempManager&MockObject $tempManager;
|
||||
private ISimpleFolder&MockObject $rootFolder;
|
||||
protected ImageManager $imageManager;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -48,7 +40,7 @@ class ImageManagerTest extends TestCase {
|
|||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->tempManager = $this->createMock(ITempManager::class);
|
||||
$this->rootFolder = $this->createMock(ISimpleFolder::class);
|
||||
$this->backgroundService = $this->createMock(BackgroundService::class);
|
||||
$backgroundService = $this->createMock(BackgroundService::class);
|
||||
$this->imageManager = new ImageManager(
|
||||
$this->config,
|
||||
$this->appData,
|
||||
|
|
@ -56,7 +48,7 @@ class ImageManagerTest extends TestCase {
|
|||
$this->cacheFactory,
|
||||
$this->logger,
|
||||
$this->tempManager,
|
||||
$this->backgroundService,
|
||||
$backgroundService,
|
||||
);
|
||||
$this->appData
|
||||
->expects($this->any())
|
||||
|
|
@ -309,7 +301,7 @@ class ImageManagerTest extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public function dataUpdateImage() {
|
||||
public static function dataUpdateImage(): array {
|
||||
return [
|
||||
['background', __DIR__ . '/../../../tests/data/testimage.png', true, false],
|
||||
['background', __DIR__ . '/../../../tests/data/testimage.png', false, false],
|
||||
|
|
@ -324,7 +316,7 @@ class ImageManagerTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataUpdateImage
|
||||
*/
|
||||
public function testUpdateImage($key, $tmpFile, $folderExists, $shouldConvert): void {
|
||||
public function testUpdateImage(string $key, string $tmpFile, bool $folderExists, bool $shouldConvert): void {
|
||||
$file = $this->createMock(ISimpleFile::class);
|
||||
$folder = $this->createMock(ISimpleFolder::class);
|
||||
$oldFile = $this->createMock(ISimpleFile::class);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -28,21 +30,15 @@ use Psr\Log\LoggerInterface;
|
|||
use Test\TestCase;
|
||||
|
||||
class ThemesServiceTest extends TestCase {
|
||||
/** @var ThemesService */
|
||||
private $themesService;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private IConfig&MockObject $config;
|
||||
private LoggerInterface&MockObject $logger;
|
||||
|
||||
/** @var IUserSession|MockObject */
|
||||
private $userSession;
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
/** @var LoggerInterface|MockObject */
|
||||
private $logger;
|
||||
|
||||
/** @var ThemingDefaults|MockObject */
|
||||
private $themingDefaults;
|
||||
private ThemingDefaults&MockObject $themingDefaults;
|
||||
private ThemesService $themesService;
|
||||
|
||||
/** @var ITheme[] */
|
||||
private $themes;
|
||||
private array $themes;
|
||||
|
||||
protected function setUp(): void {
|
||||
$this->userSession = $this->createMock(IUserSession::class);
|
||||
|
|
@ -119,7 +115,7 @@ class ThemesServiceTest extends TestCase {
|
|||
$this->assertEquals($expected, array_keys($this->themesService->getThemes()));
|
||||
}
|
||||
|
||||
public function dataTestEnableTheme() {
|
||||
public static function dataTestEnableTheme(): array {
|
||||
return [
|
||||
['default', ['default'], ['default']],
|
||||
['dark', ['default'], ['dark']],
|
||||
|
|
@ -132,7 +128,6 @@ class ThemesServiceTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataTestEnableTheme
|
||||
*
|
||||
* @param string $toEnable
|
||||
* @param string[] $enabledThemes
|
||||
* @param string[] $expectedEnabled
|
||||
*/
|
||||
|
|
@ -154,7 +149,7 @@ class ThemesServiceTest extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public function dataTestDisableTheme() {
|
||||
public static function dataTestDisableTheme(): array {
|
||||
return [
|
||||
['dark', ['default'], ['default']],
|
||||
['dark', ['dark'], []],
|
||||
|
|
@ -166,7 +161,6 @@ class ThemesServiceTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataTestDisableTheme
|
||||
*
|
||||
* @param string $toEnable
|
||||
* @param string[] $enabledThemes
|
||||
* @param string[] $expectedEnabled
|
||||
*/
|
||||
|
|
@ -189,7 +183,7 @@ class ThemesServiceTest extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public function dataTestIsEnabled() {
|
||||
public static function dataTestIsEnabled(): array {
|
||||
return [
|
||||
['dark', [], false],
|
||||
['dark', ['dark'], true],
|
||||
|
|
@ -201,10 +195,9 @@ class ThemesServiceTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataTestIsEnabled
|
||||
*
|
||||
* @param string $toEnable
|
||||
* @param string[] $enabledThemes
|
||||
*/
|
||||
public function testIsEnabled(string $themeId, array $enabledThemes, $expected): void {
|
||||
public function testIsEnabled(string $themeId, array $enabledThemes, bool $expected): void {
|
||||
$user = $this->createMock(IUser::class);
|
||||
$this->userSession->expects($this->any())
|
||||
->method('getUser')
|
||||
|
|
@ -267,7 +260,7 @@ class ThemesServiceTest extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
public function dataTestSetEnabledThemes() {
|
||||
public static function dataTestSetEnabledThemes(): array {
|
||||
return [
|
||||
[[], []],
|
||||
[['light'], ['light']],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -26,11 +28,9 @@ use Test\TestCase;
|
|||
* @package OCA\Theming\Tests
|
||||
*/
|
||||
class ServicesTest extends TestCase {
|
||||
/** @var \OCA\Activity\AppInfo\Application */
|
||||
protected $app;
|
||||
protected App $app;
|
||||
|
||||
/** @var IAppContainer */
|
||||
protected $container;
|
||||
protected IAppContainer $container;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -38,7 +38,7 @@ class ServicesTest extends TestCase {
|
|||
$this->container = $this->app->getContainer();
|
||||
}
|
||||
|
||||
public function queryData() {
|
||||
public static function queryData(): array {
|
||||
return [
|
||||
[IL10N::class],
|
||||
|
||||
|
|
@ -62,13 +62,11 @@ class ServicesTest extends TestCase {
|
|||
|
||||
/**
|
||||
* @dataProvider queryData
|
||||
* @param string $service
|
||||
* @param string $expected
|
||||
*/
|
||||
public function testContainerQuery($service, $expected = null): void {
|
||||
public function testContainerQuery(string $service, ?string $expected = null): void {
|
||||
if ($expected === null) {
|
||||
$expected = $service;
|
||||
}
|
||||
$this->assertTrue($this->container->query($service) instanceof $expected);
|
||||
$this->assertInstanceOf($expected, $this->container->query($service));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -9,15 +11,13 @@ use OCA\Theming\AppInfo\Application;
|
|||
use OCA\Theming\Settings\AdminSection;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminSectionTest extends TestCase {
|
||||
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $url;
|
||||
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $l;
|
||||
/** @var AdminSection */
|
||||
private $section;
|
||||
private IURLGenerator&MockObject $url;
|
||||
private IL10N&MockObject $l;
|
||||
private AdminSection $section;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -15,17 +17,18 @@ use OCP\IConfig;
|
|||
use OCP\IL10N;
|
||||
use OCP\INavigationManager;
|
||||
use OCP\IURLGenerator;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class AdminTest extends TestCase {
|
||||
private Admin $admin;
|
||||
private IConfig $config;
|
||||
private ThemingDefaults $themingDefaults;
|
||||
private IInitialState $initialState;
|
||||
private IURLGenerator $urlGenerator;
|
||||
private ImageManager $imageManager;
|
||||
private IL10N $l10n;
|
||||
private INavigationManager $navigationManager;
|
||||
private IConfig&MockObject $config;
|
||||
private ThemingDefaults&MockObject $themingDefaults;
|
||||
private IInitialState&MockObject $initialState;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private ImageManager&MockObject $imageManager;
|
||||
private IL10N&MockObject $l10n;
|
||||
private INavigationManager&MockObject $navigationManager;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -39,7 +41,7 @@ class PersonalTest extends TestCase {
|
|||
private Personal $admin;
|
||||
|
||||
/** @var ITheme[] */
|
||||
private $themes;
|
||||
private array $themes;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -67,8 +69,7 @@ class PersonalTest extends TestCase {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
public function dataTestGetForm() {
|
||||
public function dataTestGetForm(): array {
|
||||
return [
|
||||
['', [
|
||||
$this->formatThemeForm('default'),
|
||||
|
|
@ -88,10 +89,9 @@ class PersonalTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataTestGetForm
|
||||
*
|
||||
* @param string $toEnable
|
||||
* @param string[] $enabledThemes
|
||||
*/
|
||||
public function testGetForm(string $enforcedTheme, $themesState): void {
|
||||
public function testGetForm(string $enforcedTheme, array $themesState): void {
|
||||
$this->config->expects($this->once())
|
||||
->method('getSystemValueString')
|
||||
->with('enforce_theme', '')
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -16,10 +18,10 @@ class AccessibleThemeTestCase extends TestCase {
|
|||
/**
|
||||
* Set to true to check for WCAG AAA level accessibility
|
||||
*/
|
||||
protected bool $WCAGaaa = false;
|
||||
protected static bool $WCAGaaa = false;
|
||||
|
||||
public function dataAccessibilityPairs() {
|
||||
$textContrast = $this->WCAGaaa ? 7.0 : 4.5;
|
||||
public static function dataAccessibilityPairs(): array {
|
||||
$textContrast = self::$WCAGaaa ? 7.0 : 4.5;
|
||||
$elementContrast = 3.0;
|
||||
|
||||
return [
|
||||
|
|
@ -148,7 +150,7 @@ class AccessibleThemeTestCase extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataAccessibilityPairs
|
||||
*/
|
||||
public function testAccessibilityOfVariables($mainColors, $backgroundColors, $minContrast): void {
|
||||
public function testAccessibilityOfVariables(array $mainColors, array $backgroundColors, float $minContrast): void {
|
||||
if (!isset($this->theme)) {
|
||||
$this->markTestSkipped('You need to setup $this->theme in your setUp function');
|
||||
} elseif (!isset($this->util)) {
|
||||
|
|
|
|||
|
|
@ -22,23 +22,16 @@ use OCP\ServerVersion;
|
|||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class DarkHighContrastThemeTest extends AccessibleThemeTestCase {
|
||||
/** @var ThemingDefaults|MockObject */
|
||||
private $themingDefaults;
|
||||
/** @var IUserSession|MockObject */
|
||||
private $userSession;
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
/** @var ImageManager|MockObject */
|
||||
private $imageManager;
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
/** @var IL10N|MockObject */
|
||||
private $l10n;
|
||||
/** @var IAppManager|MockObject */
|
||||
private $appManager;
|
||||
private ThemingDefaults&MockObject $themingDefaults;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private ImageManager&MockObject $imageManager;
|
||||
private IConfig&MockObject $config;
|
||||
private IL10N&MockObject $l10n;
|
||||
private IAppManager&MockObject $appManager;
|
||||
|
||||
// !! important: Enable WCAG AAA tests
|
||||
protected bool $WCAGaaa = true;
|
||||
protected static bool $WCAGaaa = true;
|
||||
|
||||
protected function setUp(): void {
|
||||
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -22,20 +24,13 @@ use OCP\ServerVersion;
|
|||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class DarkThemeTest extends AccessibleThemeTestCase {
|
||||
/** @var ThemingDefaults|MockObject */
|
||||
private $themingDefaults;
|
||||
/** @var IUserSession|MockObject */
|
||||
private $userSession;
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
/** @var ImageManager|MockObject */
|
||||
private $imageManager;
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
/** @var IL10N|MockObject */
|
||||
private $l10n;
|
||||
/** @var IAppManager|MockObject */
|
||||
private $appManager;
|
||||
private ThemingDefaults&MockObject $themingDefaults;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private ImageManager&MockObject $imageManager;
|
||||
private IConfig&MockObject $config;
|
||||
private IL10N&MockObject $l10n;
|
||||
private IAppManager&MockObject $appManager;
|
||||
|
||||
protected function setUp(): void {
|
||||
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -22,20 +24,13 @@ use OCP\ServerVersion;
|
|||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class DefaultThemeTest extends AccessibleThemeTestCase {
|
||||
/** @var ThemingDefaults|MockObject */
|
||||
private $themingDefaults;
|
||||
/** @var IUserSession|MockObject */
|
||||
private $userSession;
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
/** @var ImageManager|MockObject */
|
||||
private $imageManager;
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
/** @var IL10N|MockObject */
|
||||
private $l10n;
|
||||
/** @var IAppManager|MockObject */
|
||||
private $appManager;
|
||||
private ThemingDefaults&MockObject $themingDefaults;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private ImageManager&MockObject $imageManager;
|
||||
private IConfig&MockObject $config;
|
||||
private IL10N&MockObject $l10n;
|
||||
private IAppManager&MockObject $appManager;
|
||||
|
||||
protected function setUp(): void {
|
||||
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -25,20 +27,13 @@ use PHPUnit\Framework\MockObject\MockObject;
|
|||
use Test\TestCase;
|
||||
|
||||
class DyslexiaFontTest extends TestCase {
|
||||
/** @var ThemingDefaults|MockObject */
|
||||
private $themingDefaults;
|
||||
/** @var IUserSession|MockObject */
|
||||
private $userSession;
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
/** @var ImageManager|MockObject */
|
||||
private $imageManager;
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
/** @var IL10N|MockObject */
|
||||
private $l10n;
|
||||
/** @var IAppManager|MockObject */
|
||||
private $appManager;
|
||||
private ThemingDefaults&MockObject $themingDefaults;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private IURLGenerator $urlGenerator;
|
||||
private ImageManager&MockObject $imageManager;
|
||||
private IConfig&MockObject $config;
|
||||
private IL10N&MockObject $l10n;
|
||||
private IAppManager&MockObject $appManager;
|
||||
|
||||
private DyslexiaFont $dyslexiaFont;
|
||||
|
||||
|
|
@ -141,7 +136,7 @@ class DyslexiaFontTest extends TestCase {
|
|||
$this->assertStringStartsWith('OpenDyslexic', $this->dyslexiaFont->getCSSVariables()['--font-face']);
|
||||
}
|
||||
|
||||
public function dataTestGetCustomCss() {
|
||||
public static function dataTestGetCustomCss(): array {
|
||||
return [
|
||||
['', true],
|
||||
['', false],
|
||||
|
|
@ -155,11 +150,8 @@ class DyslexiaFontTest extends TestCase {
|
|||
*
|
||||
* Ensure the fonts are always loaded from the web root
|
||||
* despite having url rewriting enabled or not
|
||||
*
|
||||
* @param string $webRoot
|
||||
* @param bool $prettyUrlsEnabled
|
||||
*/
|
||||
public function testGetCustomCss($webRoot, $prettyUrlsEnabled): void {
|
||||
public function testGetCustomCss(string $webRoot, bool $prettyUrlsEnabled): void {
|
||||
\OC::$WEBROOT = $webRoot;
|
||||
$this->config->expects($this->any())
|
||||
->method('getSystemValue')
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -22,23 +24,16 @@ use OCP\ServerVersion;
|
|||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class HighContrastThemeTest extends AccessibleThemeTestCase {
|
||||
/** @var ThemingDefaults|MockObject */
|
||||
private $themingDefaults;
|
||||
/** @var IUserSession|MockObject */
|
||||
private $userSession;
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
/** @var ImageManager|MockObject */
|
||||
private $imageManager;
|
||||
/** @var IConfig|MockObject */
|
||||
private $config;
|
||||
/** @var IL10N|MockObject */
|
||||
private $l10n;
|
||||
/** @var IAppManager|MockObject */
|
||||
private $appManager;
|
||||
private ThemingDefaults&MockObject $themingDefaults;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private ImageManager&MockObject $imageManager;
|
||||
private IConfig&MockObject $config;
|
||||
private IL10N&MockObject $l10n;
|
||||
private IAppManager&MockObject $appManager;
|
||||
|
||||
// !! important: Enable WCAG AAA tests
|
||||
protected bool $WCAGaaa = true;
|
||||
protected static bool $WCAGaaa = true;
|
||||
|
||||
protected function setUp(): void {
|
||||
$this->themingDefaults = $this->createMock(ThemingDefaults::class);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -27,29 +29,17 @@ class ThemingDefaultsTest extends TestCase {
|
|||
private IAppConfig&MockObject $appConfig;
|
||||
private IConfig&MockObject $config;
|
||||
private \OC_Defaults $defaults;
|
||||
|
||||
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $l10n;
|
||||
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $userSession;
|
||||
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $urlGenerator;
|
||||
/** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $cacheFactory;
|
||||
/** @var ThemingDefaults */
|
||||
private $template;
|
||||
/** @var Util|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $util;
|
||||
/** @var ICache|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $cache;
|
||||
/** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $appManager;
|
||||
/** @var ImageManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $imageManager;
|
||||
/** @var INavigationManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $navigationManager;
|
||||
/** @var BackgroundService|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $backgroundService;
|
||||
private IL10N|MockObject $l10n;
|
||||
private IUserSession&MockObject $userSession;
|
||||
private IURLGenerator&MockObject $urlGenerator;
|
||||
private ICacheFactory&MockObject $cacheFactory;
|
||||
private Util&MockObject $util;
|
||||
private ICache&MockObject $cache;
|
||||
private IAppManager&MockObject $appManager;
|
||||
private ImageManager&MockObject $imageManager;
|
||||
private INavigationManager&MockObject $navigationManager;
|
||||
private BackgroundService&MockObject $backgroundService;
|
||||
private ThemingDefaults $template;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
|
@ -186,18 +176,17 @@ class ThemingDefaultsTest extends TestCase {
|
|||
$this->assertEquals('https://example.com/', $this->template->getBaseUrl());
|
||||
}
|
||||
|
||||
public function legalUrlProvider() {
|
||||
public static function legalUrlProvider(): array {
|
||||
return [
|
||||
[ '' ],
|
||||
[ 'https://example.com/legal.html']
|
||||
[''],
|
||||
['https://example.com/legal.html'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $imprintUrl
|
||||
* @dataProvider legalUrlProvider
|
||||
*/
|
||||
public function testGetImprintURL($imprintUrl): void {
|
||||
public function testGetImprintURL(string $imprintUrl): void {
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getAppValue')
|
||||
|
|
@ -208,10 +197,9 @@ class ThemingDefaultsTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $privacyUrl
|
||||
* @dataProvider legalUrlProvider
|
||||
*/
|
||||
public function testGetPrivacyURL($privacyUrl): void {
|
||||
public function testGetPrivacyURL(string $privacyUrl): void {
|
||||
$this->config
|
||||
->expects($this->once())
|
||||
->method('getAppValue')
|
||||
|
|
@ -351,7 +339,7 @@ class ThemingDefaultsTest extends TestCase {
|
|||
$this->assertEquals('<a href="url" target="_blank" rel="noreferrer noopener" class="entity-name">Name</a> – Slogan<br/><span class="footer__legal-links"><a href="https://example.com/imprint" class="legal" target="_blank" rel="noreferrer noopener">Legal notice</a> · <a href="https://example.com/privacy" class="legal" target="_blank" rel="noreferrer noopener">Privacy policy</a></span>', $this->template->getShortFooter());
|
||||
}
|
||||
|
||||
public function invalidLegalUrlProvider() {
|
||||
public static function invalidLegalUrlProvider(): array {
|
||||
return [
|
||||
['example.com/legal'], # missing scheme
|
||||
['https:///legal'], # missing host
|
||||
|
|
@ -359,10 +347,9 @@ class ThemingDefaultsTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $invalidImprintUrl
|
||||
* @dataProvider invalidLegalUrlProvider
|
||||
*/
|
||||
public function testGetShortFooterInvalidImprint($invalidImprintUrl): void {
|
||||
public function testGetShortFooterInvalidImprint(string $invalidImprintUrl): void {
|
||||
$this->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
|
||||
$this->config
|
||||
->expects($this->exactly(5))
|
||||
|
|
@ -379,10 +366,9 @@ class ThemingDefaultsTest extends TestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $invalidPrivacyUrl
|
||||
* @dataProvider invalidLegalUrlProvider
|
||||
*/
|
||||
public function testGetShortFooterInvalidPrivacy($invalidPrivacyUrl): void {
|
||||
public function testGetShortFooterInvalidPrivacy(string $invalidPrivacyUrl): void {
|
||||
$this->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
|
||||
$this->config
|
||||
->expects($this->exactly(5))
|
||||
|
|
@ -428,7 +414,7 @@ class ThemingDefaultsTest extends TestCase {
|
|||
$this->assertEquals('#fff', $this->template->getColorPrimary());
|
||||
}
|
||||
|
||||
public function dataGetColorPrimary() {
|
||||
public static function dataGetColorPrimary(): array {
|
||||
return [
|
||||
'with fallback default' => [
|
||||
'disableTheming' => false,
|
||||
|
|
@ -803,7 +789,7 @@ class ThemingDefaultsTest extends TestCase {
|
|||
$this->assertEquals('1234567890', $this->template->getiTunesAppId());
|
||||
}
|
||||
|
||||
public function dataReplaceImagePath() {
|
||||
public static function dataReplaceImagePath(): array {
|
||||
return [
|
||||
['core', 'test.png', false],
|
||||
['core', 'manifest.json'],
|
||||
|
|
@ -812,8 +798,10 @@ class ThemingDefaultsTest extends TestCase {
|
|||
];
|
||||
}
|
||||
|
||||
/** @dataProvider dataReplaceImagePath */
|
||||
public function testReplaceImagePath($app, $image, $result = 'themingRoute?v=1234abcd'): void {
|
||||
/**
|
||||
* @dataProvider dataReplaceImagePath
|
||||
*/
|
||||
public function testReplaceImagePath(string $app, string $image, string|bool $result = 'themingRoute?v=1234abcd'): void {
|
||||
$this->cache->expects($this->any())
|
||||
->method('get')
|
||||
->with('shouldReplaceIcons')
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
|
@ -35,7 +37,7 @@ class UtilTest extends TestCase {
|
|||
$this->util = new Util($this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->appData, $this->imageManager);
|
||||
}
|
||||
|
||||
public function dataColorContrast() {
|
||||
public static function dataColorContrast(): array {
|
||||
return [
|
||||
['#ffffff', '#FFFFFF', 1],
|
||||
['#000000', '#000000', 1],
|
||||
|
|
@ -49,11 +51,11 @@ class UtilTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataColorContrast
|
||||
*/
|
||||
public function testColorContrast(string $color1, string $color2, $contrast): void {
|
||||
public function testColorContrast(string $color1, string $color2, int|float $contrast): void {
|
||||
$this->assertEqualsWithDelta($contrast, $this->util->colorContrast($color1, $color2), .001);
|
||||
}
|
||||
|
||||
public function dataInvertTextColor() {
|
||||
public static function dataInvertTextColor(): array {
|
||||
return [
|
||||
['#ffffff', true],
|
||||
['#000000', false],
|
||||
|
|
@ -64,7 +66,7 @@ class UtilTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataInvertTextColor
|
||||
*/
|
||||
public function testInvertTextColor($color, $expected): void {
|
||||
public function testInvertTextColor(string $color, bool $expected): void {
|
||||
$invert = $this->util->invertTextColor($color);
|
||||
$this->assertEquals($expected, $invert);
|
||||
}
|
||||
|
|
@ -144,7 +146,7 @@ class UtilTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataGetAppIcon
|
||||
*/
|
||||
public function testGetAppIcon($app, $expected): void {
|
||||
public function testGetAppIcon(string $app, string $expected): void {
|
||||
$this->appData->expects($this->any())
|
||||
->method('getFolder')
|
||||
->with('global/images')
|
||||
|
|
@ -153,7 +155,7 @@ class UtilTest extends TestCase {
|
|||
$this->assertEquals($expected, $icon);
|
||||
}
|
||||
|
||||
public function dataGetAppIcon() {
|
||||
public static function dataGetAppIcon(): array {
|
||||
return [
|
||||
['user_ldap', Server::get(IAppManager::class)->getAppPath('user_ldap') . '/img/app.svg'],
|
||||
['noapplikethis', \OC::$SERVERROOT . '/core/img/logo/logo.svg'],
|
||||
|
|
@ -179,11 +181,11 @@ class UtilTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataGetAppImage
|
||||
*/
|
||||
public function testGetAppImage($app, $image, $expected): void {
|
||||
public function testGetAppImage(string $app, string $image, string|bool $expected): void {
|
||||
$this->assertEquals($expected, $this->util->getAppImage($app, $image));
|
||||
}
|
||||
|
||||
public function dataGetAppImage() {
|
||||
public static function dataGetAppImage(): array {
|
||||
return [
|
||||
['core', 'logo/logo.svg', \OC::$SERVERROOT . '/core/img/logo/logo.svg'],
|
||||
['files', 'folder', \OC::$SERVERROOT . '/apps/files/img/folder.svg'],
|
||||
|
|
@ -217,7 +219,7 @@ class UtilTest extends TestCase {
|
|||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
public function dataIsBackgroundThemed() {
|
||||
public static function dataIsBackgroundThemed(): array {
|
||||
return [
|
||||
['', false],
|
||||
['png', true],
|
||||
|
|
@ -227,7 +229,7 @@ class UtilTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider dataIsBackgroundThemed
|
||||
*/
|
||||
public function testIsBackgroundThemed($backgroundMime, $expected): void {
|
||||
public function testIsBackgroundThemed(string $backgroundMime, bool $expected): void {
|
||||
$this->config->expects($this->once())
|
||||
->method('getAppValue')
|
||||
->with('theming', 'backgroundMime', '')
|
||||
|
|
|
|||
Loading…
Reference in a new issue