Merge pull request #53007 from nextcloud/tests/noid/more-phpunit10-apps

test: Migrate theming and sharebymail to PHPUnit10
pull/53029/head
Joas Schilling 2025-05-21 08:34:15 +07:00 committed by GitHub
commit c02e5608ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 372 additions and 447 deletions

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -9,25 +11,18 @@ use OCA\ShareByMail\Capabilities;
use OCA\ShareByMail\Settings\SettingsManager; use OCA\ShareByMail\Settings\SettingsManager;
use OCP\App\IAppManager; use OCP\App\IAppManager;
use OCP\Share\IManager; use OCP\Share\IManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
class CapabilitiesTest extends TestCase { class CapabilitiesTest extends TestCase {
/** @var Capabilities */ private IManager&MockObject $manager;
private $capabilities; private SettingsManager&MockObject $settingsManager;
private IAppManager&MockObject $appManager;
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject */ private Capabilities $capabilities;
private $manager;
/** @var IManager | \PHPUnit\Framework\MockObject\MockObject */
private $settingsManager;
/** @var IAppManager | \PHPUnit\Framework\MockObject\MockObject */
private $appManager;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
$this->manager = $this::createMock(IManager::class); $this->manager = $this::createMock(IManager::class);
$this->settingsManager = $this::createMock(SettingsManager::class); $this->settingsManager = $this::createMock(SettingsManager::class);
$this->appManager = $this::createMock(IAppManager::class); $this->appManager = $this::createMock(IAppManager::class);

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -47,7 +49,7 @@ use Test\TestCase;
* @group DB * @group DB
*/ */
class ShareByMailProviderTest extends TestCase { class ShareByMailProviderTest extends TestCase {
private IDBConnection $connection; private IDBConnection $connection;
private IL10N&MockObject $l; private IL10N&MockObject $l;
@ -71,25 +73,25 @@ class ShareByMailProviderTest extends TestCase {
$this->connection = Server::get(IDBConnection::class); $this->connection = Server::get(IDBConnection::class);
$this->l = $this->getMockBuilder(IL10N::class)->getMock(); $this->l = $this->createMock(IL10N::class);
$this->l->method('t') $this->l->method('t')
->willReturnCallback(function ($text, $parameters = []) { ->willReturnCallback(function ($text, $parameters = []) {
return vsprintf($text, $parameters); return vsprintf($text, $parameters);
}); });
$this->config = $this->getMockBuilder(IConfig::class)->getMock(); $this->config = $this->createMock(IConfig::class);
$this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $this->logger = $this->createMock(LoggerInterface::class);
$this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock(); $this->rootFolder = $this->createMock('OCP\Files\IRootFolder');
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock(); $this->userManager = $this->createMock(IUserManager::class);
$this->secureRandom = $this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(); $this->secureRandom = $this->createMock('\OCP\Security\ISecureRandom');
$this->mailer = $this->getMockBuilder('\OCP\Mail\IMailer')->getMock(); $this->mailer = $this->createMock('\OCP\Mail\IMailer');
$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock(); $this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->share = $this->getMockBuilder(IShare::class)->getMock(); $this->share = $this->createMock(IShare::class);
$this->activityManager = $this->getMockBuilder('OCP\Activity\IManager')->getMock(); $this->activityManager = $this->createMock('OCP\Activity\IManager');
$this->settingsManager = $this->getMockBuilder(SettingsManager::class)->disableOriginalConstructor()->getMock(); $this->settingsManager = $this->createMock(SettingsManager::class);
$this->defaults = $this->createMock(Defaults::class); $this->defaults = $this->createMock(Defaults::class);
$this->hasher = $this->getMockBuilder(IHasher::class)->getMock(); $this->hasher = $this->createMock(IHasher::class);
$this->eventDispatcher = $this->getMockBuilder(IEventDispatcher::class)->getMock(); $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->shareManager = $this->getMockBuilder(IManager::class)->getMock(); $this->shareManager = $this->createMock(IManager::class);
$this->userManager->expects($this->any())->method('userExists')->willReturn(true); $this->userManager->expects($this->any())->method('userExists')->willReturn(true);
$this->config->expects($this->any())->method('getAppValue')->with('core', 'enforce_strict_email_check')->willReturn('yes'); $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 = []) { private function getInstance(array $mockedMethods = []) {
if (!empty($mockedMethods)) { if (!empty($mockedMethods)) {
return $this->getMockBuilder('OCA\ShareByMail\ShareByMailProvider') return $this->getMockBuilder(ShareByMailProvider::class)
->setConstructorArgs([ ->setConstructorArgs([
$this->config, $this->config,
$this->connection, $this->connection,
@ -119,9 +121,9 @@ class ShareByMailProviderTest extends TestCase {
$this->defaults, $this->defaults,
$this->hasher, $this->hasher,
$this->eventDispatcher, $this->eventDispatcher,
$this->shareManager $this->shareManager,
]) ])
->setMethods($mockedMethods) ->onlyMethods($mockedMethods)
->getMock(); ->getMock();
} }
@ -140,7 +142,7 @@ class ShareByMailProviderTest extends TestCase {
$this->defaults, $this->defaults,
$this->hasher, $this->hasher,
$this->eventDispatcher, $this->eventDispatcher,
$this->shareManager $this->shareManager,
); );
} }
@ -156,10 +158,10 @@ class ShareByMailProviderTest extends TestCase {
public function testCreate(): void { public function testCreate(): void {
$expectedShare = $this->createMock(IShare::class); $expectedShare = $this->createMock(IShare::class);
$share = $this->getMockBuilder(IShare::class)->getMock(); $share = $this->createMock(IShare::class);
$share->expects($this->any())->method('getSharedWith')->willReturn('user1'); $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'); $node->expects($this->any())->method('getName')->willReturn('filename');
$instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'sendEmail', 'sendPassword']); $instance = $this->getInstance(['getSharedWith', 'createMailShare', 'getRawShare', 'createShareObject', 'createShareActivity', 'sendEmail', 'sendPassword']);
@ -185,10 +187,10 @@ class ShareByMailProviderTest extends TestCase {
public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection(): void { public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection(): void {
$expectedShare = $this->createMock(IShare::class); $expectedShare = $this->createMock(IShare::class);
$node = $this->getMockBuilder(File::class)->getMock(); $node = $this->createMock(File::class);
$node->expects($this->any())->method('getName')->willReturn('filename'); $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('getSharedWith')->willReturn('receiver@examplelölöl.com');
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
$share->expects($this->any())->method('getSharedBy')->willReturn('owner'); $share->expects($this->any())->method('getSharedBy')->willReturn('owner');
@ -227,10 +229,10 @@ class ShareByMailProviderTest extends TestCase {
public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithPermanentPassword(): void { public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithPermanentPassword(): void {
$expectedShare = $this->createMock(IShare::class); $expectedShare = $this->createMock(IShare::class);
$node = $this->getMockBuilder(File::class)->getMock(); $node = $this->createMock(File::class);
$node->expects($this->any())->method('getName')->willReturn('filename'); $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('getSharedWith')->willReturn('receiver@example.com');
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
$share->expects($this->any())->method('getSharedBy')->willReturn('owner'); $share->expects($this->any())->method('getSharedBy')->willReturn('owner');
@ -273,10 +275,10 @@ class ShareByMailProviderTest extends TestCase {
public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithoutPermanentPassword(): void { public function testCreateSendPasswordByMailWithPasswordAndWithoutEnforcedPasswordProtectionWithoutPermanentPassword(): void {
$expectedShare = $this->createMock(IShare::class); $expectedShare = $this->createMock(IShare::class);
$node = $this->getMockBuilder(File::class)->getMock(); $node = $this->createMock(File::class);
$node->expects($this->any())->method('getName')->willReturn('filename'); $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('getSharedWith')->willReturn('receiver@example.com');
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
$share->expects($this->any())->method('getSharedBy')->willReturn('owner'); $share->expects($this->any())->method('getSharedBy')->willReturn('owner');
@ -326,10 +328,10 @@ class ShareByMailProviderTest extends TestCase {
public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPermanentPassword(): void { public function testCreateSendPasswordByMailWithEnforcedPasswordProtectionWithPermanentPassword(): void {
$expectedShare = $this->createMock(IShare::class); $expectedShare = $this->createMock(IShare::class);
$node = $this->getMockBuilder(File::class)->getMock(); $node = $this->createMock(File::class);
$node->expects($this->any())->method('getName')->willReturn('filename'); $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('getSharedWith')->willReturn('receiver@example.com');
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
$share->expects($this->any())->method('getSharedBy')->willReturn('owner'); $share->expects($this->any())->method('getSharedBy')->willReturn('owner');
@ -374,26 +376,36 @@ class ShareByMailProviderTest extends TestCase {
$message = $this->createMock(IMessage::class); $message = $this->createMock(IMessage::class);
$message->expects($this->exactly(2))->method('setTo')->with(['receiver@example.com']); $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('createMessage')->willReturn($message);
$this->mailer->expects($this->exactly(2))->method('createEMailTemplate') $calls = [
->withConsecutive([ [
'sharebymail.RecipientNotification', [ 'sharebymail.RecipientNotification',
[
'filename' => 'filename', 'filename' => 'filename',
'link' => 'https://example.com/file.txt', 'link' => 'https://example.com/file.txt',
'initiator' => 'owner', 'initiator' => 'owner',
'expiration' => null, 'expiration' => null,
'shareWith' => 'receiver@example.com', 'shareWith' => 'receiver@example.com',
'note' => '' 'note' => '',
] ],
], ],
[
'sharebymail.RecipientPasswordNotification',
[ [
'sharebymail.RecipientPasswordNotification', [ 'filename' => 'filename',
'filename' => 'filename', 'password' => 'autogeneratedPassword',
'password' => 'autogeneratedPassword', 'initiator' => 'owner',
'initiator' => 'owner', 'initiatorEmail' => null,
'initiatorEmail' => null, 'shareWith' => 'receiver@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 // Main email notification is sent as well as the password
// to the recipient because shareApiLinkEnforcePassword is enabled. // to the recipient because shareApiLinkEnforcePassword is enabled.
@ -407,10 +419,10 @@ class ShareByMailProviderTest extends TestCase {
public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordProtectionWithPermanentPassword(): void { public function testCreateSendPasswordByMailWithPasswordAndWithEnforcedPasswordProtectionWithPermanentPassword(): void {
$expectedShare = $this->createMock(IShare::class); $expectedShare = $this->createMock(IShare::class);
$node = $this->getMockBuilder(File::class)->getMock(); $node = $this->createMock(File::class);
$node->expects($this->any())->method('getName')->willReturn('filename'); $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('getSharedWith')->willReturn('receiver@example.com');
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
$share->expects($this->any())->method('getSharedBy')->willReturn('owner'); $share->expects($this->any())->method('getSharedBy')->willReturn('owner');
@ -448,26 +460,37 @@ class ShareByMailProviderTest extends TestCase {
$message = $this->createMock(IMessage::class); $message = $this->createMock(IMessage::class);
$message->expects($this->exactly(2))->method('setTo')->with(['receiver@example.com']); $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('createMessage')->willReturn($message);
$this->mailer->expects($this->exactly(2))->method('createEMailTemplate')
->withConsecutive([ $calls = [
'sharebymail.RecipientNotification', [ [
'sharebymail.RecipientNotification',
[
'filename' => 'filename', 'filename' => 'filename',
'link' => 'https://example.com/file.txt', 'link' => 'https://example.com/file.txt',
'initiator' => 'owner', 'initiator' => 'owner',
'expiration' => null, 'expiration' => null,
'shareWith' => 'receiver@example.com', 'shareWith' => 'receiver@example.com',
'note' => '' 'note' => '',
] ],
], ],
[
'sharebymail.RecipientPasswordNotification',
[ [
'sharebymail.RecipientPasswordNotification', [ 'filename' => 'filename',
'filename' => 'filename', 'password' => 'password',
'password' => 'password', 'initiator' => 'owner',
'initiator' => 'owner', 'initiatorEmail' => null,
'initiatorEmail' => null, 'shareWith' => 'receiver@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 // Main email notification is sent as well as the password
// to the recipient because the password is set. // to the recipient because the password is set.
@ -482,15 +505,15 @@ class ShareByMailProviderTest extends TestCase {
$expectedShare = $this->createMock(IShare::class); $expectedShare = $this->createMock(IShare::class);
// The owner of the share. // 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); $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('getEMailAddress')->willReturn('owner@example.com');
$owner->expects($this->any())->method('getDisplayName')->willReturn('owner'); $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'); $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('getSharedWith')->willReturn('receiver@example.com');
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(true); $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(true);
$share->expects($this->any())->method('getSharedBy')->willReturn('owner'); $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'); $instance->expects($this->once())->method('autoGeneratePassword')->with($share)->willReturn('autogeneratedPassword');
$message = $this->createMock(IMessage::class); $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('createMessage')->willReturn($message);
$this->mailer->expects($this->exactly(2))->method('createEMailTemplate')
->withConsecutive([ $calls = [
'sharebymail.RecipientNotification', [ [
'sharebymail.RecipientNotification',
[
'filename' => 'filename', 'filename' => 'filename',
'link' => 'https://example.com/file.txt', 'link' => 'https://example.com/file.txt',
'initiator' => 'owner', 'initiator' => 'owner',
'expiration' => null, 'expiration' => null,
'shareWith' => 'receiver@example.com', 'shareWith' => 'receiver@example.com',
'note' => '' 'note' => '',
] ],
], ],
[
'sharebymail.OwnerPasswordNotification',
[ [
'sharebymail.OwnerPasswordNotification', [ 'filename' => 'filename',
'filename' => 'filename', 'password' => 'autogeneratedPassword',
'password' => 'autogeneratedPassword', 'initiator' => 'owner',
'initiator' => 'owner', 'initiatorEmail' => 'owner@example.com',
'initiatorEmail' => 'owner@example.com', 'shareWith' => 'receiver@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 // Main email notification is sent as well as the password to owner
// because the password is set and SendPasswordByTalk is enabled. // because the password is set and SendPasswordByTalk is enabled.
@ -560,10 +604,10 @@ class ShareByMailProviderTest extends TestCase {
public function sendNotificationToMultipleEmails() { public function sendNotificationToMultipleEmails() {
$expectedShare = $this->createMock(IShare::class); $expectedShare = $this->createMock(IShare::class);
$node = $this->getMockBuilder(File::class)->getMock(); $node = $this->createMock(File::class);
$node->expects($this->any())->method('getName')->willReturn('filename'); $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('getSharedWith')->willReturn('');
$share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false);
$share->expects($this->any())->method('getSharedBy')->willReturn('owner'); $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('getNote')->willReturn('');
$share->expects($this->any())->method('getToken')->willReturn('token'); $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); $share->expects($this->any())->method('getAttributes')->willReturn($attributes);
$attributes->expects($this->any())->method('getAttribute')->with('shareWith', 'emails')->willReturn([ $attributes->expects($this->any())->method('getAttribute')->with('shareWith', 'emails')->willReturn([
'receiver1@example.com', 'receiver1@example.com',
@ -607,8 +651,8 @@ class ShareByMailProviderTest extends TestCase {
->with($share, ['receiver1@example.com', 'receiver2@example.com', 'receiver3@example.com']); ->with($share, ['receiver1@example.com', 'receiver2@example.com', 'receiver3@example.com']);
$instance->expects($this->once())->method('sendPassword')->with($share, 'password'); $instance->expects($this->once())->method('sendPassword')->with($share, 'password');
$instance->expects($this->never())->method('sendPasswordToOwner'); $instance->expects($this->never())->method('sendPasswordToOwner');
$message = $this->createMock(IMessage::class); $message = $this->createMock(IMessage::class);
$message->expects($this->never())->method('setTo'); $message->expects($this->never())->method('setTo');
$message->expects($this->exactly(2))->method('setBcc')->with(['receiver1@example.com', 'receiver2@example.com', 'receiver3@example.com']); $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->expectException(\Exception::class);
$this->share->expects($this->once())->method('getSharedWith')->willReturn('user1'); $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'); $node->expects($this->any())->method('getName')->willReturn('fileName');
$this->share->expects($this->any())->method('getNode')->willReturn($node); $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('getNote')->willReturn('Check this!');
$this->share->expects($this->any())->method('getMailSend')->willReturn(true); $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'); $node->expects($this->any())->method('getName')->willReturn('fileName');
$this->share->expects($this->any())->method('getNode')->willReturn($node); $this->share->expects($this->any())->method('getNode')->willReturn($node);
@ -788,7 +832,7 @@ class ShareByMailProviderTest extends TestCase {
$this->assertSame($note, $result[0]['note']); $this->assertSame($note, $result[0]['note']);
} }
public function dataUpdateSendPassword() { public static function dataUpdateSendPassword(): array {
return [ return [
['password', 'hashed', 'hashed new', false, false, true], ['password', 'hashed', 'hashed new', false, false, true],
['', 'hashed', 'hashed new', false, false, false], ['', 'hashed', 'hashed new', false, false, false],
@ -802,28 +846,21 @@ class ShareByMailProviderTest extends TestCase {
/** /**
* @dataProvider dataUpdateSendPassword * @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 = $this->createMock(File::class);
$node->expects($this->any())->method('getName')->willReturn('filename'); $node->expects($this->any())->method('getName')->willReturn('filename');
$this->settingsManager->method('sendPasswordByMail')->willReturn(true); $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('getSharedWith')->willReturn('receiver@example.com');
$originalShare->expects($this->any())->method('getNode')->willReturn($node); $originalShare->expects($this->any())->method('getNode')->willReturn($node);
$originalShare->expects($this->any())->method('getId')->willReturn(42); $originalShare->expects($this->any())->method('getId')->willReturn(42);
$originalShare->expects($this->any())->method('getPassword')->willReturn($originalPassword); $originalShare->expects($this->any())->method('getPassword')->willReturn($originalPassword);
$originalShare->expects($this->any())->method('getSendPasswordByTalk')->willReturn($originalSendPasswordByTalk); $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('getSharedWith')->willReturn('receiver@example.com');
$share->expects($this->any())->method('getNode')->willReturn($node); $share->expects($this->any())->method('getNode')->willReturn($node);
$share->expects($this->any())->method('getId')->willReturn(42); $share->expects($this->any())->method('getId')->willReturn(42);
@ -1155,8 +1192,8 @@ class ShareByMailProviderTest extends TestCase {
$provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']);
$this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true);
$u1 = $userManager->createUser('testFed', md5(time())); $u1 = $userManager->createUser('testFed', md5((string)time()));
$u2 = $userManager->createUser('testFed2', md5(time())); $u2 = $userManager->createUser('testFed2', md5((string)time()));
$folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo'); $folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');
$file1 = $folder1->newFile('bar1'); $file1 = $folder1->newFile('bar1');
@ -1202,8 +1239,8 @@ class ShareByMailProviderTest extends TestCase {
$provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']);
$this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true);
$u1 = $userManager->createUser('testFed', md5(time())); $u1 = $userManager->createUser('testFed', md5((string)time()));
$u2 = $userManager->createUser('testFed2', md5(time())); $u2 = $userManager->createUser('testFed2', md5((string)time()));
$folder = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo'); $folder = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');
@ -1347,17 +1384,17 @@ class ShareByMailProviderTest extends TestCase {
->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) ->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
->willReturn('https://example.com/file.txt'); ->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'); $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('getSharedBy')->willReturn('OwnerUser');
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com'); $share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
$share->expects($this->any())->method('getNode')->willReturn($node); $share->expects($this->any())->method('getNode')->willReturn($node);
$share->expects($this->any())->method('getId')->willReturn(42); $share->expects($this->any())->method('getId')->willReturn(42);
$share->expects($this->any())->method('getNote')->willReturn(''); $share->expects($this->any())->method('getNote')->willReturn('');
$share->expects($this->any())->method('getToken')->willReturn('token'); $share->expects($this->any())->method('getToken')->willReturn('token');
self::invokePrivate( self::invokePrivate(
$provider, $provider,
'sendMailNotification', 'sendMailNotification',
@ -1469,17 +1506,17 @@ class ShareByMailProviderTest extends TestCase {
->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) ->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
->willReturn('https://example.com/file.txt'); ->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'); $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('getSharedBy')->willReturn('OwnerUser');
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com'); $share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
$share->expects($this->any())->method('getNode')->willReturn($node); $share->expects($this->any())->method('getNode')->willReturn($node);
$share->expects($this->any())->method('getId')->willReturn(42); $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('getNote')->willReturn('This is a note to the recipient');
$share->expects($this->any())->method('getToken')->willReturn('token'); $share->expects($this->any())->method('getToken')->willReturn('token');
self::invokePrivate( self::invokePrivate(
$provider, $provider,
'sendMailNotification', 'sendMailNotification',
@ -1596,10 +1633,10 @@ class ShareByMailProviderTest extends TestCase {
->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) ->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
->willReturn('https://example.com/file.txt'); ->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'); $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('getSharedBy')->willReturn('OwnerUser');
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com'); $share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
$share->expects($this->any())->method('getNode')->willReturn($node); $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('getNote')->willReturn('');
$share->expects($this->any())->method('getExpirationDate')->willReturn($expiration); $share->expects($this->any())->method('getExpirationDate')->willReturn($expiration);
$share->expects($this->any())->method('getToken')->willReturn('token'); $share->expects($this->any())->method('getToken')->willReturn('token');
self::invokePrivate( self::invokePrivate(
$provider, $provider,
'sendMailNotification', 'sendMailNotification',
@ -1694,10 +1731,10 @@ class ShareByMailProviderTest extends TestCase {
->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) ->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
->willReturn('https://example.com/file.txt'); ->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'); $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('getSharedBy')->willReturn('InitiatorUser');
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com'); $share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
$share->expects($this->any())->method('getNode')->willReturn($node); $share->expects($this->any())->method('getNode')->willReturn($node);
@ -1795,10 +1832,10 @@ class ShareByMailProviderTest extends TestCase {
->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) ->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
->willReturn('https://example.com/file.txt'); ->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'); $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('getSharedBy')->willReturn('OwnerUser');
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com'); $share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
$share->expects($this->any())->method('getNode')->willReturn($node); $share->expects($this->any())->method('getNode')->willReturn($node);
@ -1892,10 +1929,10 @@ class ShareByMailProviderTest extends TestCase {
->with('files_sharing.sharecontroller.showShare', ['token' => 'token']) ->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
->willReturn('https://example.com/file.txt'); ->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'); $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('getSharedBy')->willReturn('InitiatorUser');
$share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com'); $share->expects($this->any())->method('getSharedWith')->willReturn('john@doe.com');
$share->expects($this->any())->method('getNode')->willReturn($node); $share->expects($this->any())->method('getNode')->willReturn($node);

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -24,22 +26,12 @@ use Test\TestCase;
* @package OCA\Theming\Tests * @package OCA\Theming\Tests
*/ */
class CapabilitiesTest extends TestCase { class CapabilitiesTest extends TestCase {
/** @var ThemingDefaults|MockObject */ protected ThemingDefaults&MockObject $theming;
protected $theming; protected IURLGenerator&MockObject $url;
protected IConfig&MockObject $config;
/** @var IURLGenerator|MockObject */ protected Util&MockObject $util;
protected $url;
/** @var IConfig|MockObject */
protected $config;
/** @var Util|MockObject */
protected $util;
protected IUserSession $userSession; protected IUserSession $userSession;
protected Capabilities $capabilities;
/** @var Capabilities */
protected $capabilities;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
@ -58,7 +50,7 @@ class CapabilitiesTest extends TestCase {
); );
} }
public function dataGetCapabilities() { public static function dataGetCapabilities(): array {
return [ return [
['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', '#fff', '#000', 'http://absolute/', true, [ ['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', '#fff', '#000', 'http://absolute/', true, [
'name' => 'name', 'name' => 'name',
@ -133,18 +125,9 @@ class CapabilitiesTest extends TestCase {
/** /**
* @dataProvider dataGetCapabilities * @dataProvider dataGetCapabilities
* @param string $name * @param non-empty-array<string, string> $expected
* @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
*/ */
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()) $this->config->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->willReturn($background); ->willReturn($background);

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * 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\Http\FileDisplayResponse;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IRequest; use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
class IconControllerTest extends TestCase { class IconControllerTest extends TestCase {
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ private IRequest&MockObject $request;
private $request; private ThemingDefaults&MockObject $themingDefaults;
/** @var ThemingDefaults|\PHPUnit\Framework\MockObject\MockObject */ private ITimeFactory&MockObject $timeFactory;
private $themingDefaults; private IconBuilder&MockObject $iconBuilder;
/** @var ITimeFactory */ private FileAccessHelper&MockObject $fileAccessHelper;
private $timeFactory; private IAppManager&MockObject $appManager;
/** @var IconController|\PHPUnit\Framework\MockObject\MockObject */ private ImageManager&MockObject $imageManager;
private $iconController; private IconController $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;
protected function setUp(): void { protected function setUp(): void {
$this->request = $this->createMock(IRequest::class); $this->request = $this->createMock(IRequest::class);

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -82,7 +84,7 @@ class ThemingControllerTest extends TestCase {
parent::setUp(); parent::setUp();
} }
public function dataUpdateStylesheetSuccess() { public static function dataUpdateStylesheetSuccess(): array {
return [ return [
['name', str_repeat('a', 250), 'Saved'], ['name', str_repeat('a', 250), 'Saved'],
['url', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'], ['url', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'],
@ -97,12 +99,8 @@ class ThemingControllerTest extends TestCase {
/** /**
* @dataProvider dataUpdateStylesheetSuccess * @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 $this->themingDefaults
->expects($this->once()) ->expects($this->once())
->method('set') ->method('set')
@ -126,7 +124,7 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value)); $this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value));
} }
public function dataUpdateStylesheetError() { public static function dataUpdateStylesheetError(): array {
$urls = [ $urls = [
'url' => 'web address', 'url' => 'web address',
'imprintUrl' => 'legal notice address', 'imprintUrl' => 'legal notice address',
@ -159,12 +157,8 @@ class ThemingControllerTest extends TestCase {
/** /**
* @dataProvider dataUpdateStylesheetError * @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 $this->themingDefaults
->expects($this->never()) ->expects($this->never())
->method('set') ->method('set')
@ -254,9 +248,6 @@ class ThemingControllerTest extends TestCase {
/** /**
* Checks that trying to upload an SVG favicon without imagemagick * Checks that trying to upload an SVG favicon without imagemagick
* results in an unsupported media type response. * results in an unsupported media type response.
*
* @test
* @return void
*/ */
public function testUploadSVGFaviconWithoutImagemagick(): void { public function testUploadSVGFaviconWithoutImagemagick(): void {
$this->imageManager $this->imageManager
@ -344,7 +335,7 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->uploadImage()); $this->assertEquals($expected, $this->themingController->uploadImage());
} }
public function dataUpdateImages() { public static function dataUpdateImages(): array {
return [ return [
['image/jpeg', false], ['image/jpeg', false],
['image/jpeg', true], ['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'; $tmpLogo = Server::get(ITempManager::class)->getTemporaryFolder() . '/logo.svg';
$destination = Server::get(ITempManager::class)->getTemporaryFolder(); $destination = Server::get(ITempManager::class)->getTemporaryFolder();
@ -407,8 +400,7 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->uploadImage()); $this->assertEquals($expected, $this->themingController->uploadImage());
} }
/** @dataProvider dataUpdateImages */ public function testUpdateLogoLoginScreenUpload(): void {
public function testUpdateLogoLoginScreenUpload($folderExists): void {
$tmpLogo = Server::get(ITempManager::class)->getTemporaryFolder() . 'logo.png'; $tmpLogo = Server::get(ITempManager::class)->getTemporaryFolder() . 'logo.png';
touch($tmpLogo); touch($tmpLogo);
@ -500,7 +492,7 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->uploadImage()); $this->assertEquals($expected, $this->themingController->uploadImage());
} }
public function dataPhpUploadErrors() { public static function dataPhpUploadErrors(): array {
return [ return [
[UPLOAD_ERR_INI_SIZE, 'The uploaded file exceeds the upload_max_filesize directive in php.ini'], [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'], [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 * @dataProvider dataPhpUploadErrors
*/ */
public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload($error, $expectedErrorMessage): void { public function testUpdateLogoLoginScreenUploadWithInvalidImageUpload(int $error, string $expectedErrorMessage): void {
$this->request $this->request
->expects($this->once()) ->expects($this->once())
->method('getParam') ->method('getParam')
@ -615,15 +607,17 @@ class ThemingControllerTest extends TestCase {
$this->assertEquals($expected, $this->themingController->undo('MySetting')); $this->assertEquals($expected, $this->themingController->undo('MySetting'));
} }
public function dataUndoDelete() { public static function dataUndoDelete(): array {
return [ return [
[ 'backgroundMime', 'background' ], [ 'backgroundMime', 'background' ],
[ 'logoMime', 'logo' ] [ 'logoMime', 'logo' ]
]; ];
} }
/** @dataProvider dataUndoDelete */ /**
public function testUndoDelete($value, $filename): void { * @dataProvider dataUndoDelete
*/
public function testUndoDelete(string $value, string $filename): void {
$this->l10n $this->l10n
->expects($this->once()) ->expects($this->once())
->method('t') ->method('t')
@ -722,7 +716,9 @@ class ThemingControllerTest extends TestCase {
]; ];
} }
/** @dataProvider dataGetManifest */ /**
* @dataProvider dataGetManifest
*/
public function testGetManifest(bool $standalone): void { public function testGetManifest(bool $standalone): void {
$this->config $this->config
->expects($this->once()) ->expects($this->once())

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -27,25 +29,17 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
class UserThemeControllerTest extends TestCase { class UserThemeControllerTest extends TestCase {
/** @var UserThemeController */ private IRequest&MockObject $request;
private $userThemeController; private IConfig&MockObject $config;
private IUserSession&MockObject $userSession;
/** @var IRequest|MockObject */ private ThemesService&MockObject $themesService;
private $request; private ThemingDefaults&MockObject $themingDefaults;
/** @var IConfig|MockObject */ private BackgroundService&MockObject $backgroundService;
private $config; private UserThemeController $userThemeController;
/** @var IUserSession|MockObject */
private $userSession;
/** @var ThemeService|MockObject */
private $themesService;
/** @var ThemingDefaults */
private $themingDefaults;
/** @var BackgroundService|MockObject */
private $backgroundService;
/** @var ITheme[] */ /** @var ITheme[] */
private $themes; private array $themes;
protected function setUp(): void { protected function setUp(): void {
$this->request = $this->createMock(IRequest::class); $this->request = $this->createMock(IRequest::class);
@ -85,7 +79,7 @@ class UserThemeControllerTest extends TestCase {
parent::setUp(); parent::setUp();
} }
public function dataTestThemes() { public static function dataTestThemes(): array {
return [ return [
['default'], ['default'],
['light'], ['light'],
@ -100,11 +94,8 @@ class UserThemeControllerTest extends TestCase {
/** /**
* @dataProvider dataTestThemes * @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 $this->themesService
->expects($this->any()) ->expects($this->any())
->method('getThemes') ->method('getThemes')
@ -120,11 +111,8 @@ class UserThemeControllerTest extends TestCase {
/** /**
* @dataProvider dataTestThemes * @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 $this->themesService
->expects($this->any()) ->expects($this->any())
->method('getThemes') ->method('getThemes')

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -14,24 +16,17 @@ use OCP\App\IAppManager;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\IConfig; use OCP\IConfig;
use OCP\ServerVersion; use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
class IconBuilderTest extends TestCase { class IconBuilderTest extends TestCase {
protected IConfig&MockObject $config;
/** @var IConfig */ protected AppData&MockObject $appData;
protected $config; protected ThemingDefaults&MockObject $themingDefaults;
/** @var AppData */ protected ImageManager&MockObject $imageManager;
protected $appData; protected IAppManager&MockObject $appManager;
/** @var ThemingDefaults */ protected Util $util;
protected $themingDefaults; protected IconBuilder $iconBuilder;
/** @var Util */
protected $util;
/** @var ImageManager */
protected $imageManager;
/** @var IconBuilder */
protected $iconBuilder;
/** @var IAppManager */
protected $appManager;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
@ -58,7 +53,7 @@ class IconBuilderTest extends TestCase {
} }
} }
public function dataRenderAppIcon() { public static function dataRenderAppIcon(): array {
return [ return [
['core', '#0082c9', 'touch-original.png'], ['core', '#0082c9', 'touch-original.png'],
['core', '#FF0000', 'touch-core-red.png'], ['core', '#FF0000', 'touch-core-red.png'],
@ -70,11 +65,8 @@ class IconBuilderTest extends TestCase {
/** /**
* @dataProvider dataRenderAppIcon * @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->checkImagick();
$this->themingDefaults->expects($this->once()) $this->themingDefaults->expects($this->once())
->method('getColorPrimary') ->method('getColorPrimary')
@ -99,11 +91,8 @@ class IconBuilderTest extends TestCase {
/** /**
* @dataProvider dataRenderAppIcon * @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->checkImagick();
$this->themingDefaults->expects($this->once()) $this->themingDefaults->expects($this->once())
->method('getColorPrimary') ->method('getColorPrimary')
@ -129,11 +118,8 @@ class IconBuilderTest extends TestCase {
/** /**
* @dataProvider dataRenderAppIcon * @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->checkImagick();
$this->imageManager->expects($this->once()) $this->imageManager->expects($this->once())
->method('shouldReplaceIcons') ->method('shouldReplaceIcons')

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -20,24 +22,14 @@ use Psr\Log\LoggerInterface;
use Test\TestCase; use Test\TestCase;
class ImageManagerTest extends TestCase { class ImageManagerTest extends TestCase {
/** @var IConfig|MockObject */ protected IConfig&MockObject $config;
protected $config; protected IAppData&MockObject $appData;
/** @var IAppData|MockObject */ private IURLGenerator&MockObject $urlGenerator;
protected $appData; private ICacheFactory&MockObject $cacheFactory;
/** @var ImageManager */ private LoggerInterface&MockObject $logger;
protected $imageManager; private ITempManager&MockObject $tempManager;
/** @var IURLGenerator|MockObject */ private ISimpleFolder&MockObject $rootFolder;
private $urlGenerator; protected ImageManager $imageManager;
/** @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 function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
@ -48,7 +40,7 @@ class ImageManagerTest extends TestCase {
$this->logger = $this->createMock(LoggerInterface::class); $this->logger = $this->createMock(LoggerInterface::class);
$this->tempManager = $this->createMock(ITempManager::class); $this->tempManager = $this->createMock(ITempManager::class);
$this->rootFolder = $this->createMock(ISimpleFolder::class); $this->rootFolder = $this->createMock(ISimpleFolder::class);
$this->backgroundService = $this->createMock(BackgroundService::class); $backgroundService = $this->createMock(BackgroundService::class);
$this->imageManager = new ImageManager( $this->imageManager = new ImageManager(
$this->config, $this->config,
$this->appData, $this->appData,
@ -56,7 +48,7 @@ class ImageManagerTest extends TestCase {
$this->cacheFactory, $this->cacheFactory,
$this->logger, $this->logger,
$this->tempManager, $this->tempManager,
$this->backgroundService, $backgroundService,
); );
$this->appData $this->appData
->expects($this->any()) ->expects($this->any())
@ -309,7 +301,7 @@ class ImageManagerTest extends TestCase {
} }
public function dataUpdateImage() { public static function dataUpdateImage(): array {
return [ return [
['background', __DIR__ . '/../../../tests/data/testimage.png', true, false], ['background', __DIR__ . '/../../../tests/data/testimage.png', true, false],
['background', __DIR__ . '/../../../tests/data/testimage.png', false, false], ['background', __DIR__ . '/../../../tests/data/testimage.png', false, false],
@ -324,7 +316,7 @@ class ImageManagerTest extends TestCase {
/** /**
* @dataProvider dataUpdateImage * @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); $file = $this->createMock(ISimpleFile::class);
$folder = $this->createMock(ISimpleFolder::class); $folder = $this->createMock(ISimpleFolder::class);
$oldFile = $this->createMock(ISimpleFile::class); $oldFile = $this->createMock(ISimpleFile::class);

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -28,21 +30,15 @@ use Psr\Log\LoggerInterface;
use Test\TestCase; use Test\TestCase;
class ThemesServiceTest extends TestCase { class ThemesServiceTest extends TestCase {
/** @var ThemesService */ private IUserSession&MockObject $userSession;
private $themesService; 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&MockObject $themingDefaults;
private $themingDefaults; private ThemesService $themesService;
/** @var ITheme[] */ /** @var ITheme[] */
private $themes; private array $themes;
protected function setUp(): void { protected function setUp(): void {
$this->userSession = $this->createMock(IUserSession::class); $this->userSession = $this->createMock(IUserSession::class);
@ -119,7 +115,7 @@ class ThemesServiceTest extends TestCase {
$this->assertEquals($expected, array_keys($this->themesService->getThemes())); $this->assertEquals($expected, array_keys($this->themesService->getThemes()));
} }
public function dataTestEnableTheme() { public static function dataTestEnableTheme(): array {
return [ return [
['default', ['default'], ['default']], ['default', ['default'], ['default']],
['dark', ['default'], ['dark']], ['dark', ['default'], ['dark']],
@ -132,7 +128,6 @@ class ThemesServiceTest extends TestCase {
/** /**
* @dataProvider dataTestEnableTheme * @dataProvider dataTestEnableTheme
* *
* @param string $toEnable
* @param string[] $enabledThemes * @param string[] $enabledThemes
* @param string[] $expectedEnabled * @param string[] $expectedEnabled
*/ */
@ -154,7 +149,7 @@ class ThemesServiceTest extends TestCase {
} }
public function dataTestDisableTheme() { public static function dataTestDisableTheme(): array {
return [ return [
['dark', ['default'], ['default']], ['dark', ['default'], ['default']],
['dark', ['dark'], []], ['dark', ['dark'], []],
@ -166,7 +161,6 @@ class ThemesServiceTest extends TestCase {
/** /**
* @dataProvider dataTestDisableTheme * @dataProvider dataTestDisableTheme
* *
* @param string $toEnable
* @param string[] $enabledThemes * @param string[] $enabledThemes
* @param string[] $expectedEnabled * @param string[] $expectedEnabled
*/ */
@ -189,7 +183,7 @@ class ThemesServiceTest extends TestCase {
} }
public function dataTestIsEnabled() { public static function dataTestIsEnabled(): array {
return [ return [
['dark', [], false], ['dark', [], false],
['dark', ['dark'], true], ['dark', ['dark'], true],
@ -201,10 +195,9 @@ class ThemesServiceTest extends TestCase {
/** /**
* @dataProvider dataTestIsEnabled * @dataProvider dataTestIsEnabled
* *
* @param string $toEnable
* @param string[] $enabledThemes * @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); $user = $this->createMock(IUser::class);
$this->userSession->expects($this->any()) $this->userSession->expects($this->any())
->method('getUser') ->method('getUser')
@ -267,7 +260,7 @@ class ThemesServiceTest extends TestCase {
} }
public function dataTestSetEnabledThemes() { public static function dataTestSetEnabledThemes(): array {
return [ return [
[[], []], [[], []],
[['light'], ['light']], [['light'], ['light']],

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -26,11 +28,9 @@ use Test\TestCase;
* @package OCA\Theming\Tests * @package OCA\Theming\Tests
*/ */
class ServicesTest extends TestCase { class ServicesTest extends TestCase {
/** @var \OCA\Activity\AppInfo\Application */ protected App $app;
protected $app;
/** @var IAppContainer */ protected IAppContainer $container;
protected $container;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
@ -38,7 +38,7 @@ class ServicesTest extends TestCase {
$this->container = $this->app->getContainer(); $this->container = $this->app->getContainer();
} }
public function queryData() { public static function queryData(): array {
return [ return [
[IL10N::class], [IL10N::class],
@ -62,13 +62,11 @@ class ServicesTest extends TestCase {
/** /**
* @dataProvider queryData * @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) { if ($expected === null) {
$expected = $service; $expected = $service;
} }
$this->assertTrue($this->container->query($service) instanceof $expected); $this->assertInstanceOf($expected, $this->container->query($service));
} }
} }

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -9,15 +11,13 @@ use OCA\Theming\AppInfo\Application;
use OCA\Theming\Settings\AdminSection; use OCA\Theming\Settings\AdminSection;
use OCP\IL10N; use OCP\IL10N;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
class AdminSectionTest extends TestCase { class AdminSectionTest extends TestCase {
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ private IURLGenerator&MockObject $url;
private $url; private IL10N&MockObject $l;
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ private AdminSection $section;
private $l;
/** @var AdminSection */
private $section;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -15,17 +17,18 @@ use OCP\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\INavigationManager; use OCP\INavigationManager;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
class AdminTest extends TestCase { class AdminTest extends TestCase {
private Admin $admin; private Admin $admin;
private IConfig $config; private IConfig&MockObject $config;
private ThemingDefaults $themingDefaults; private ThemingDefaults&MockObject $themingDefaults;
private IInitialState $initialState; private IInitialState&MockObject $initialState;
private IURLGenerator $urlGenerator; private IURLGenerator&MockObject $urlGenerator;
private ImageManager $imageManager; private ImageManager&MockObject $imageManager;
private IL10N $l10n; private IL10N&MockObject $l10n;
private INavigationManager $navigationManager; private INavigationManager&MockObject $navigationManager;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -39,7 +41,7 @@ class PersonalTest extends TestCase {
private Personal $admin; private Personal $admin;
/** @var ITheme[] */ /** @var ITheme[] */
private $themes; private array $themes;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
@ -67,8 +69,7 @@ class PersonalTest extends TestCase {
); );
} }
public function dataTestGetForm(): array {
public function dataTestGetForm() {
return [ return [
['', [ ['', [
$this->formatThemeForm('default'), $this->formatThemeForm('default'),
@ -88,10 +89,9 @@ class PersonalTest extends TestCase {
/** /**
* @dataProvider dataTestGetForm * @dataProvider dataTestGetForm
* *
* @param string $toEnable
* @param string[] $enabledThemes * @param string[] $enabledThemes
*/ */
public function testGetForm(string $enforcedTheme, $themesState): void { public function testGetForm(string $enforcedTheme, array $themesState): void {
$this->config->expects($this->once()) $this->config->expects($this->once())
->method('getSystemValueString') ->method('getSystemValueString')
->with('enforce_theme', '') ->with('enforce_theme', '')

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * 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 * Set to true to check for WCAG AAA level accessibility
*/ */
protected bool $WCAGaaa = false; protected static bool $WCAGaaa = false;
public function dataAccessibilityPairs() { public static function dataAccessibilityPairs(): array {
$textContrast = $this->WCAGaaa ? 7.0 : 4.5; $textContrast = self::$WCAGaaa ? 7.0 : 4.5;
$elementContrast = 3.0; $elementContrast = 3.0;
return [ return [
@ -148,7 +150,7 @@ class AccessibleThemeTestCase extends TestCase {
/** /**
* @dataProvider dataAccessibilityPairs * @dataProvider dataAccessibilityPairs
*/ */
public function testAccessibilityOfVariables($mainColors, $backgroundColors, $minContrast): void { public function testAccessibilityOfVariables(array $mainColors, array $backgroundColors, float $minContrast): void {
if (!isset($this->theme)) { if (!isset($this->theme)) {
$this->markTestSkipped('You need to setup $this->theme in your setUp function'); $this->markTestSkipped('You need to setup $this->theme in your setUp function');
} elseif (!isset($this->util)) { } elseif (!isset($this->util)) {

@ -22,23 +22,16 @@ use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
class DarkHighContrastThemeTest extends AccessibleThemeTestCase { class DarkHighContrastThemeTest extends AccessibleThemeTestCase {
/** @var ThemingDefaults|MockObject */ private ThemingDefaults&MockObject $themingDefaults;
private $themingDefaults; private IUserSession&MockObject $userSession;
/** @var IUserSession|MockObject */ private IURLGenerator&MockObject $urlGenerator;
private $userSession; private ImageManager&MockObject $imageManager;
/** @var IURLGenerator|MockObject */ private IConfig&MockObject $config;
private $urlGenerator; private IL10N&MockObject $l10n;
/** @var ImageManager|MockObject */ private IAppManager&MockObject $appManager;
private $imageManager;
/** @var IConfig|MockObject */
private $config;
/** @var IL10N|MockObject */
private $l10n;
/** @var IAppManager|MockObject */
private $appManager;
// !! important: Enable WCAG AAA tests // !! important: Enable WCAG AAA tests
protected bool $WCAGaaa = true; protected static bool $WCAGaaa = true;
protected function setUp(): void { protected function setUp(): void {
$this->themingDefaults = $this->createMock(ThemingDefaults::class); $this->themingDefaults = $this->createMock(ThemingDefaults::class);

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -22,20 +24,13 @@ use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
class DarkThemeTest extends AccessibleThemeTestCase { class DarkThemeTest extends AccessibleThemeTestCase {
/** @var ThemingDefaults|MockObject */ private ThemingDefaults&MockObject $themingDefaults;
private $themingDefaults; private IUserSession&MockObject $userSession;
/** @var IUserSession|MockObject */ private IURLGenerator&MockObject $urlGenerator;
private $userSession; private ImageManager&MockObject $imageManager;
/** @var IURLGenerator|MockObject */ private IConfig&MockObject $config;
private $urlGenerator; private IL10N&MockObject $l10n;
/** @var ImageManager|MockObject */ private IAppManager&MockObject $appManager;
private $imageManager;
/** @var IConfig|MockObject */
private $config;
/** @var IL10N|MockObject */
private $l10n;
/** @var IAppManager|MockObject */
private $appManager;
protected function setUp(): void { protected function setUp(): void {
$this->themingDefaults = $this->createMock(ThemingDefaults::class); $this->themingDefaults = $this->createMock(ThemingDefaults::class);

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -22,20 +24,13 @@ use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
class DefaultThemeTest extends AccessibleThemeTestCase { class DefaultThemeTest extends AccessibleThemeTestCase {
/** @var ThemingDefaults|MockObject */ private ThemingDefaults&MockObject $themingDefaults;
private $themingDefaults; private IUserSession&MockObject $userSession;
/** @var IUserSession|MockObject */ private IURLGenerator&MockObject $urlGenerator;
private $userSession; private ImageManager&MockObject $imageManager;
/** @var IURLGenerator|MockObject */ private IConfig&MockObject $config;
private $urlGenerator; private IL10N&MockObject $l10n;
/** @var ImageManager|MockObject */ private IAppManager&MockObject $appManager;
private $imageManager;
/** @var IConfig|MockObject */
private $config;
/** @var IL10N|MockObject */
private $l10n;
/** @var IAppManager|MockObject */
private $appManager;
protected function setUp(): void { protected function setUp(): void {
$this->themingDefaults = $this->createMock(ThemingDefaults::class); $this->themingDefaults = $this->createMock(ThemingDefaults::class);

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -25,20 +27,13 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase; use Test\TestCase;
class DyslexiaFontTest extends TestCase { class DyslexiaFontTest extends TestCase {
/** @var ThemingDefaults|MockObject */ private ThemingDefaults&MockObject $themingDefaults;
private $themingDefaults; private IUserSession&MockObject $userSession;
/** @var IUserSession|MockObject */ private IURLGenerator $urlGenerator;
private $userSession; private ImageManager&MockObject $imageManager;
/** @var IURLGenerator|MockObject */ private IConfig&MockObject $config;
private $urlGenerator; private IL10N&MockObject $l10n;
/** @var ImageManager|MockObject */ private IAppManager&MockObject $appManager;
private $imageManager;
/** @var IConfig|MockObject */
private $config;
/** @var IL10N|MockObject */
private $l10n;
/** @var IAppManager|MockObject */
private $appManager;
private DyslexiaFont $dyslexiaFont; private DyslexiaFont $dyslexiaFont;
@ -141,7 +136,7 @@ class DyslexiaFontTest extends TestCase {
$this->assertStringStartsWith('OpenDyslexic', $this->dyslexiaFont->getCSSVariables()['--font-face']); $this->assertStringStartsWith('OpenDyslexic', $this->dyslexiaFont->getCSSVariables()['--font-face']);
} }
public function dataTestGetCustomCss() { public static function dataTestGetCustomCss(): array {
return [ return [
['', true], ['', true],
['', false], ['', false],
@ -155,11 +150,8 @@ class DyslexiaFontTest extends TestCase {
* *
* Ensure the fonts are always loaded from the web root * Ensure the fonts are always loaded from the web root
* despite having url rewriting enabled or not * 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; \OC::$WEBROOT = $webRoot;
$this->config->expects($this->any()) $this->config->expects($this->any())
->method('getSystemValue') ->method('getSystemValue')

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -22,23 +24,16 @@ use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
class HighContrastThemeTest extends AccessibleThemeTestCase { class HighContrastThemeTest extends AccessibleThemeTestCase {
/** @var ThemingDefaults|MockObject */ private ThemingDefaults&MockObject $themingDefaults;
private $themingDefaults; private IUserSession&MockObject $userSession;
/** @var IUserSession|MockObject */ private IURLGenerator&MockObject $urlGenerator;
private $userSession; private ImageManager&MockObject $imageManager;
/** @var IURLGenerator|MockObject */ private IConfig&MockObject $config;
private $urlGenerator; private IL10N&MockObject $l10n;
/** @var ImageManager|MockObject */ private IAppManager&MockObject $appManager;
private $imageManager;
/** @var IConfig|MockObject */
private $config;
/** @var IL10N|MockObject */
private $l10n;
/** @var IAppManager|MockObject */
private $appManager;
// !! important: Enable WCAG AAA tests // !! important: Enable WCAG AAA tests
protected bool $WCAGaaa = true; protected static bool $WCAGaaa = true;
protected function setUp(): void { protected function setUp(): void {
$this->themingDefaults = $this->createMock(ThemingDefaults::class); $this->themingDefaults = $this->createMock(ThemingDefaults::class);

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
@ -27,29 +29,17 @@ class ThemingDefaultsTest extends TestCase {
private IAppConfig&MockObject $appConfig; private IAppConfig&MockObject $appConfig;
private IConfig&MockObject $config; private IConfig&MockObject $config;
private \OC_Defaults $defaults; private \OC_Defaults $defaults;
private IL10N|MockObject $l10n;
/** @var IL10N|\PHPUnit\Framework\MockObject\MockObject */ private IUserSession&MockObject $userSession;
private $l10n; private IURLGenerator&MockObject $urlGenerator;
/** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ private ICacheFactory&MockObject $cacheFactory;
private $userSession; private Util&MockObject $util;
/** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ private ICache&MockObject $cache;
private $urlGenerator; private IAppManager&MockObject $appManager;
/** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */ private ImageManager&MockObject $imageManager;
private $cacheFactory; private INavigationManager&MockObject $navigationManager;
/** @var ThemingDefaults */ private BackgroundService&MockObject $backgroundService;
private $template; private ThemingDefaults $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;
protected function setUp(): void { protected function setUp(): void {
parent::setUp(); parent::setUp();
@ -186,18 +176,17 @@ class ThemingDefaultsTest extends TestCase {
$this->assertEquals('https://example.com/', $this->template->getBaseUrl()); $this->assertEquals('https://example.com/', $this->template->getBaseUrl());
} }
public function legalUrlProvider() { public static function legalUrlProvider(): array {
return [ return [
[ '' ], [''],
[ 'https://example.com/legal.html'] ['https://example.com/legal.html'],
]; ];
} }
/** /**
* @param $imprintUrl
* @dataProvider legalUrlProvider * @dataProvider legalUrlProvider
*/ */
public function testGetImprintURL($imprintUrl): void { public function testGetImprintURL(string $imprintUrl): void {
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getAppValue') ->method('getAppValue')
@ -208,10 +197,9 @@ class ThemingDefaultsTest extends TestCase {
} }
/** /**
* @param $privacyUrl
* @dataProvider legalUrlProvider * @dataProvider legalUrlProvider
*/ */
public function testGetPrivacyURL($privacyUrl): void { public function testGetPrivacyURL(string $privacyUrl): void {
$this->config $this->config
->expects($this->once()) ->expects($this->once())
->method('getAppValue') ->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()); $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 [ return [
['example.com/legal'], # missing scheme ['example.com/legal'], # missing scheme
['https:///legal'], # missing host ['https:///legal'], # missing host
@ -359,10 +347,9 @@ class ThemingDefaultsTest extends TestCase {
} }
/** /**
* @param $invalidImprintUrl
* @dataProvider invalidLegalUrlProvider * @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->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
$this->config $this->config
->expects($this->exactly(5)) ->expects($this->exactly(5))
@ -379,10 +366,9 @@ class ThemingDefaultsTest extends TestCase {
} }
/** /**
* @param $invalidPrivacyUrl
* @dataProvider invalidLegalUrlProvider * @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->navigationManager->expects($this->once())->method('getAll')->with(INavigationManager::TYPE_GUEST)->willReturn([]);
$this->config $this->config
->expects($this->exactly(5)) ->expects($this->exactly(5))
@ -428,7 +414,7 @@ class ThemingDefaultsTest extends TestCase {
$this->assertEquals('#fff', $this->template->getColorPrimary()); $this->assertEquals('#fff', $this->template->getColorPrimary());
} }
public function dataGetColorPrimary() { public static function dataGetColorPrimary(): array {
return [ return [
'with fallback default' => [ 'with fallback default' => [
'disableTheming' => false, 'disableTheming' => false,
@ -803,7 +789,7 @@ class ThemingDefaultsTest extends TestCase {
$this->assertEquals('1234567890', $this->template->getiTunesAppId()); $this->assertEquals('1234567890', $this->template->getiTunesAppId());
} }
public function dataReplaceImagePath() { public static function dataReplaceImagePath(): array {
return [ return [
['core', 'test.png', false], ['core', 'test.png', false],
['core', 'manifest.json'], ['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()) $this->cache->expects($this->any())
->method('get') ->method('get')
->with('shouldReplaceIcons') ->with('shouldReplaceIcons')

@ -1,4 +1,6 @@
<?php <?php
declare(strict_types=1);
/** /**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later * 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); $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 [ return [
['#ffffff', '#FFFFFF', 1], ['#ffffff', '#FFFFFF', 1],
['#000000', '#000000', 1], ['#000000', '#000000', 1],
@ -49,11 +51,11 @@ class UtilTest extends TestCase {
/** /**
* @dataProvider dataColorContrast * @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); $this->assertEqualsWithDelta($contrast, $this->util->colorContrast($color1, $color2), .001);
} }
public function dataInvertTextColor() { public static function dataInvertTextColor(): array {
return [ return [
['#ffffff', true], ['#ffffff', true],
['#000000', false], ['#000000', false],
@ -64,7 +66,7 @@ class UtilTest extends TestCase {
/** /**
* @dataProvider dataInvertTextColor * @dataProvider dataInvertTextColor
*/ */
public function testInvertTextColor($color, $expected): void { public function testInvertTextColor(string $color, bool $expected): void {
$invert = $this->util->invertTextColor($color); $invert = $this->util->invertTextColor($color);
$this->assertEquals($expected, $invert); $this->assertEquals($expected, $invert);
} }
@ -144,7 +146,7 @@ class UtilTest extends TestCase {
/** /**
* @dataProvider dataGetAppIcon * @dataProvider dataGetAppIcon
*/ */
public function testGetAppIcon($app, $expected): void { public function testGetAppIcon(string $app, string $expected): void {
$this->appData->expects($this->any()) $this->appData->expects($this->any())
->method('getFolder') ->method('getFolder')
->with('global/images') ->with('global/images')
@ -153,7 +155,7 @@ class UtilTest extends TestCase {
$this->assertEquals($expected, $icon); $this->assertEquals($expected, $icon);
} }
public function dataGetAppIcon() { public static function dataGetAppIcon(): array {
return [ return [
['user_ldap', Server::get(IAppManager::class)->getAppPath('user_ldap') . '/img/app.svg'], ['user_ldap', Server::get(IAppManager::class)->getAppPath('user_ldap') . '/img/app.svg'],
['noapplikethis', \OC::$SERVERROOT . '/core/img/logo/logo.svg'], ['noapplikethis', \OC::$SERVERROOT . '/core/img/logo/logo.svg'],
@ -179,11 +181,11 @@ class UtilTest extends TestCase {
/** /**
* @dataProvider dataGetAppImage * @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)); $this->assertEquals($expected, $this->util->getAppImage($app, $image));
} }
public function dataGetAppImage() { public static function dataGetAppImage(): array {
return [ return [
['core', 'logo/logo.svg', \OC::$SERVERROOT . '/core/img/logo/logo.svg'], ['core', 'logo/logo.svg', \OC::$SERVERROOT . '/core/img/logo/logo.svg'],
['files', 'folder', \OC::$SERVERROOT . '/apps/files/img/folder.svg'], ['files', 'folder', \OC::$SERVERROOT . '/apps/files/img/folder.svg'],
@ -217,7 +219,7 @@ class UtilTest extends TestCase {
$this->assertTrue($actual); $this->assertTrue($actual);
} }
public function dataIsBackgroundThemed() { public static function dataIsBackgroundThemed(): array {
return [ return [
['', false], ['', false],
['png', true], ['png', true],
@ -227,7 +229,7 @@ class UtilTest extends TestCase {
/** /**
* @dataProvider dataIsBackgroundThemed * @dataProvider dataIsBackgroundThemed
*/ */
public function testIsBackgroundThemed($backgroundMime, $expected): void { public function testIsBackgroundThemed(string $backgroundMime, bool $expected): void {
$this->config->expects($this->once()) $this->config->expects($this->once())
->method('getAppValue') ->method('getAppValue')
->with('theming', 'backgroundMime', '') ->with('theming', 'backgroundMime', '')