aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/Accounts/AccountManagerTest.php113
-rw-r--r--tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php9
-rw-r--r--tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php4
-rw-r--r--tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php31
-rw-r--r--tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php6
-rw-r--r--tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php287
-rw-r--r--tests/lib/Contacts/ContactsMenu/EntryTest.php4
-rw-r--r--tests/lib/Contacts/ContactsMenu/ManagerTest.php53
-rw-r--r--tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php9
-rw-r--r--tests/lib/Files/Cache/SearchBuilderTest.php2
-rw-r--r--tests/lib/Files/Config/UserMountCacheTest.php3
-rw-r--r--tests/lib/Repair/ClearFrontendCachesTest.php9
-rw-r--r--tests/lib/Template/CSSResourceLocatorTest.php13
-rw-r--r--tests/lib/Template/SCSSCacherTest.php524
14 files changed, 271 insertions, 796 deletions
diff --git a/tests/lib/Accounts/AccountManagerTest.php b/tests/lib/Accounts/AccountManagerTest.php
index 9d54ef36c80..2eaec755b50 100644
--- a/tests/lib/Accounts/AccountManagerTest.php
+++ b/tests/lib/Accounts/AccountManagerTest.php
@@ -1,9 +1,11 @@
<?php
/**
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ *
* @author Björn Schießle <schiessle@owncloud.com>
+ * @author Thomas Citharel <nextcloud@tcit.fr>
*
- * @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
@@ -62,26 +64,25 @@ class AccountManagerTest extends TestCase {
/** @var IFactory|MockObject */
protected $l10nFactory;
- /** @var \OCP\IDBConnection */
+ /** @var IDBConnection */
private $connection;
- /** @var IConfig|MockObject */
+ /** @var IConfig|MockObject */
private $config;
/** @var EventDispatcherInterface|MockObject */
private $eventDispatcher;
- /** @var IJobList|MockObject */
+ /** @var IJobList|MockObject */
private $jobList;
- /** @var string accounts table name */
- private $table = 'accounts';
+ /** accounts table name */
+ private string $table = 'accounts';
/** @var LoggerInterface|MockObject */
private $logger;
- /** @var AccountManager */
- private $accountManager;
+ private AccountManager $accountManager;
protected function setUp(): void {
parent::setUp();
@@ -115,7 +116,7 @@ class AccountManagerTest extends TestCase {
protected function tearDown(): void {
parent::tearDown();
$query = $this->connection->getQueryBuilder();
- $query->delete($this->table)->execute();
+ $query->delete($this->table)->executeStatement();
}
protected function makeUser(string $uid, string $name, string $email = null): IUser {
@@ -423,18 +424,18 @@ class AccountManagerTest extends TestCase {
],
],
];
+ $this->config->expects($this->exactly(count($users)))->method('getSystemValue')->with('account_manager.default_property_scope', [])->willReturn([]);
foreach ($users as $userInfo) {
- $this->invokePrivate($this->accountManager, 'updateUser', [$userInfo['user'], $userInfo['data'], false]);
+ $this->invokePrivate($this->accountManager, 'updateUser', [$userInfo['user'], $userInfo['data'], null, false]);
}
}
/**
* get a instance of the accountManager
*
- * @param array $mockedMethods list of methods which should be mocked
* @return MockObject | AccountManager
*/
- public function getInstance($mockedMethods = null) {
+ public function getInstance(?array $mockedMethods = null) {
return $this->getMockBuilder(AccountManager::class)
->setConstructorArgs([
$this->connection,
@@ -449,26 +450,19 @@ class AccountManagerTest extends TestCase {
$this->urlGenerator,
$this->crypto
])
- ->setMethods($mockedMethods)
+ ->onlyMethods($mockedMethods)
->getMock();
}
/**
* @dataProvider dataTrueFalse
*
- * @param array $newData
- * @param array $oldData
- * @param bool $insertNew
- * @param bool $updateExisting
*/
- public function testUpdateUser($newData, $oldData, $insertNew, $updateExisting) {
+ public function testUpdateUser(array $newData, array $oldData, bool $insertNew, bool $updateExisting) {
$accountManager = $this->getInstance(['getUser', 'insertNewUser', 'updateExistingUser']);
/** @var IUser $user */
$user = $this->createMock(IUser::class);
- // FIXME: should be an integration test instead of this abomination
- $accountManager->expects($this->once())->method('getUser')->with($user)->willReturn($oldData);
-
if ($updateExisting) {
$accountManager->expects($this->once())->method('updateExistingUser')
->with($user, $newData);
@@ -490,17 +484,16 @@ class AccountManagerTest extends TestCase {
function ($eventName, $event) use ($user, $newData) {
$this->assertSame('OC\AccountManager::userUpdated', $eventName);
$this->assertInstanceOf(GenericEvent::class, $event);
- /** @var GenericEvent $event */
$this->assertSame($user, $event->getSubject());
$this->assertSame($newData, $event->getArguments());
}
);
}
- $this->invokePrivate($accountManager, 'updateUser', [$user, $newData]);
+ $this->invokePrivate($accountManager, 'updateUser', [$user, $newData, $oldData]);
}
- public function dataTrueFalse() {
+ public function dataTrueFalse(): array {
return [
#$newData | $oldData | $insertNew | $updateExisting
[['myProperty' => ['value' => 'newData']], ['myProperty' => ['value' => 'oldData']], false, true],
@@ -606,6 +599,7 @@ class AccountManagerTest extends TestCase {
'value' => '1',
],
];
+ $this->config->expects($this->once())->method('getSystemValue')->with('account_manager.default_property_scope', [])->willReturn([]);
$defaultUserRecord = $this->invokePrivate($this->accountManager, 'buildDefaultUserRecord', [$user]);
$result = $this->invokePrivate($this->accountManager, 'addMissingDefaultValues', [$input, $defaultUserRecord]);
@@ -613,18 +607,6 @@ class AccountManagerTest extends TestCase {
$this->assertSame($expected, $result);
}
- private function addDummyValuesToTable($uid, $data) {
- $query = $this->connection->getQueryBuilder();
- $query->insert($this->table)
- ->values(
- [
- 'uid' => $query->createNamedParameter($uid),
- 'data' => $query->createNamedParameter(json_encode($data)),
- ]
- )
- ->execute();
- }
-
public function testGetAccount() {
$accountManager = $this->getInstance(['getUser']);
/** @var IUser $user */
@@ -671,9 +653,6 @@ class AccountManagerTest extends TestCase {
/**
* @dataProvider dataParsePhoneNumber
- * @param string $phoneInput
- * @param string $defaultRegion
- * @param string|null $phoneNumber
*/
public function testParsePhoneNumber(string $phoneInput, string $defaultRegion, ?string $phoneNumber): void {
$this->config->method('getSystemValueString')
@@ -793,6 +772,8 @@ class AccountManagerTest extends TestCase {
* @dataProvider dataCheckEmailVerification
*/
public function testCheckEmailVerification(IUser $user, ?string $newEmail): void {
+ // Once because of getAccount, once because of getUser
+ $this->config->expects($this->exactly(2))->method('getSystemValue')->with('account_manager.default_property_scope', [])->willReturn([]);
$account = $this->accountManager->getAccount($user);
$emailUpdated = false;
@@ -815,4 +796,58 @@ class AccountManagerTest extends TestCase {
$oldData = $this->invokePrivate($this->accountManager, 'getUser', [$user, false]);
$this->invokePrivate($this->accountManager, 'checkEmailVerification', [$account, $oldData]);
}
+
+ public function dataSetDefaultPropertyScopes(): array {
+ return [
+ [
+ [],
+ [
+ IAccountManager::PROPERTY_DISPLAYNAME => IAccountManager::SCOPE_FEDERATED,
+ IAccountManager::PROPERTY_ADDRESS => IAccountManager::SCOPE_LOCAL,
+ IAccountManager::PROPERTY_EMAIL => IAccountManager::SCOPE_FEDERATED,
+ IAccountManager::PROPERTY_ROLE => IAccountManager::SCOPE_LOCAL,
+ ]
+ ],
+ [
+ [
+ IAccountManager::PROPERTY_DISPLAYNAME => IAccountManager::SCOPE_FEDERATED,
+ IAccountManager::PROPERTY_EMAIL => IAccountManager::SCOPE_LOCAL,
+ IAccountManager::PROPERTY_ROLE => IAccountManager::SCOPE_PRIVATE,
+ ], [
+ IAccountManager::PROPERTY_DISPLAYNAME => IAccountManager::SCOPE_FEDERATED,
+ IAccountManager::PROPERTY_EMAIL => IAccountManager::SCOPE_LOCAL,
+ IAccountManager::PROPERTY_ROLE => IAccountManager::SCOPE_PRIVATE,
+ ]
+ ],
+ [
+ [
+ IAccountManager::PROPERTY_ADDRESS => 'invalid scope',
+ 'invalid property' => IAccountManager::SCOPE_LOCAL,
+ IAccountManager::PROPERTY_ROLE => IAccountManager::SCOPE_PRIVATE,
+ ],
+ [
+ IAccountManager::PROPERTY_ADDRESS => IAccountManager::SCOPE_LOCAL,
+ IAccountManager::PROPERTY_EMAIL => IAccountManager::SCOPE_FEDERATED,
+ IAccountManager::PROPERTY_ROLE => IAccountManager::SCOPE_PRIVATE,
+ ]
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataSetDefaultPropertyScopes
+ */
+ public function testSetDefaultPropertyScopes(array $propertyScopes, array $expectedResultScopes): void {
+ $user = $this->makeUser('steve', 'Steve Smith', 'steve@steve.steve');
+ $this->config->expects($this->once())->method('getSystemValue')->with('account_manager.default_property_scope', [])->willReturn($propertyScopes);
+
+ $result = $this->invokePrivate($this->accountManager, 'buildDefaultUserRecord', [$user]);
+ $resultProperties = array_column($result, 'name');
+
+ $this->assertEmpty(array_diff($resultProperties, IAccountManager::ALLOWED_PROPERTIES), "Building default user record returned non-allowed properties");
+ foreach ($expectedResultScopes as $expectedResultScopeKey => $expectedResultScopeValue) {
+ $resultScope = $result[array_search($expectedResultScopeKey, $resultProperties)]['scope'];
+ $this->assertEquals($expectedResultScopeValue, $resultScope, "The result scope doesn't follow the value set into the config or defaults correctly.");
+ }
+ }
}
diff --git a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
index f6067b8d15a..6ad57515c16 100644
--- a/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
+++ b/tests/lib/Authentication/Token/PublicKeyTokenProviderTest.php
@@ -94,8 +94,6 @@ class PublicKeyTokenProviderTest extends TestCase {
}
public function testGenerateTokenInvalidName() {
- $this->expectException(\OC\Authentication\Exceptions\InvalidTokenException::class);
-
$token = 'token';
$uid = 'user';
$user = 'User';
@@ -107,6 +105,13 @@ class PublicKeyTokenProviderTest extends TestCase {
$type = IToken::PERMANENT_TOKEN;
$actual = $this->tokenProvider->generateToken($token, $uid, $user, $password, $name, $type, IToken::DO_NOT_REMEMBER);
+
+ $this->assertInstanceOf(PublicKeyToken::class, $actual);
+ $this->assertSame($uid, $actual->getUID());
+ $this->assertSame($user, $actual->getLoginName());
+ $this->assertSame('User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12User-Agent: Mozill…', $actual->getName());
+ $this->assertSame(IToken::DO_NOT_REMEMBER, $actual->getRemember());
+ $this->assertSame($password, $this->tokenProvider->getPassword($actual, $token));
}
public function testUpdateToken() {
diff --git a/tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php b/tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php
index d858eab4d11..7102ed80129 100644
--- a/tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ActionFactoryTest.php
@@ -29,9 +29,7 @@ use OCP\Contacts\ContactsMenu\IAction;
use Test\TestCase;
class ActionFactoryTest extends TestCase {
-
- /** @var ActionFactory */
- private $actionFactory;
+ private ActionFactory $actionFactory;
protected function setUp(): void {
parent::setUp();
diff --git a/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php b/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php
index a3557d7cda6..67f84042996 100644
--- a/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ActionProviderStoreTest.php
@@ -33,31 +33,28 @@ use OCP\AppFramework\QueryException;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IServerContainer;
use OCP\IUser;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;
class ActionProviderStoreTest extends TestCase {
- /** @var IServerContainer|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IServerContainer|MockObject */
private $serverContainer;
- /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IAppManager|MockObject */
private $appManager;
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- private $logger;
-
- /** @var ActionProviderStore */
- private $actionProviderStore;
+ private ActionProviderStore $actionProviderStore;
protected function setUp(): void {
parent::setUp();
$this->serverContainer = $this->createMock(IServerContainer::class);
$this->appManager = $this->createMock(AppManager::class);
- $this->logger = $this->createMock(LoggerInterface::class);
+ $logger = $this->createMock(LoggerInterface::class);
- $this->actionProviderStore = new ActionProviderStore($this->serverContainer, $this->appManager, $this->logger);
+ $this->actionProviderStore = new ActionProviderStore($this->serverContainer, $this->appManager, $logger);
}
public function testGetProviders() {
@@ -79,11 +76,11 @@ class ActionProviderStoreTest extends TestCase {
],
]);
$this->serverContainer->expects($this->exactly(3))
- ->method('query')
+ ->method('get')
->willReturnMap([
- [ProfileProvider::class, true, $provider1],
- [EMailProvider::class, true, $provider2],
- ['OCA\Contacts\Provider1', true, $provider3]
+ [ProfileProvider::class, $provider1],
+ [EMailProvider::class, $provider2],
+ ['OCA\Contacts\Provider1', $provider3]
]);
$providers = $this->actionProviderStore->getProviders($user);
@@ -107,10 +104,10 @@ class ActionProviderStoreTest extends TestCase {
->with('contacts')
->willReturn([/* Empty info.xml */]);
$this->serverContainer->expects($this->exactly(2))
- ->method('query')
+ ->method('get')
->willReturnMap([
- [ProfileProvider::class, true, $provider1],
- [EMailProvider::class, true, $provider2],
+ [ProfileProvider::class, $provider1],
+ [EMailProvider::class, $provider2],
]);
$providers = $this->actionProviderStore->getProviders($user);
@@ -130,7 +127,7 @@ class ActionProviderStoreTest extends TestCase {
->with($user)
->willReturn([]);
$this->serverContainer->expects($this->once())
- ->method('query')
+ ->method('get')
->willThrowException(new QueryException());
$this->actionProviderStore->getProviders($user);
diff --git a/tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php b/tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php
index 1f5d37e7483..497cf992e95 100644
--- a/tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php
+++ b/tests/lib/Contacts/ContactsMenu/Actions/LinkActionTest.php
@@ -28,7 +28,7 @@ use OC\Contacts\ContactsMenu\Actions\LinkAction;
use Test\TestCase;
class LinkActionTest extends TestCase {
- private $action;
+ private LinkAction $action;
protected function setUp(): void {
parent::setUp();
@@ -49,7 +49,7 @@ class LinkActionTest extends TestCase {
public function testGetSetName() {
$name = 'Jane Doe';
- $this->assertNull($this->action->getName());
+ $this->assertEmpty($this->action->getName());
$this->action->setName($name);
$this->assertEquals($name, $this->action->getName());
}
@@ -67,7 +67,7 @@ class LinkActionTest extends TestCase {
$json = $this->action->jsonSerialize();
$this->assertArrayHasKey('hyperlink', $json);
- $this->assertEquals($json['hyperlink'], '/some/url');
+ $this->assertEquals('/some/url', $json['hyperlink']);
}
public function testJsonSerialize() {
diff --git a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
index bd82c203ff5..aa609aedbb9 100644
--- a/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ContactsStoreTest.php
@@ -39,19 +39,18 @@ use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ContactsStoreTest extends TestCase {
- /** @var ContactsStore */
- private $contactsStore;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
+ private ContactsStore $contactsStore;
+ /** @var IManager|MockObject */
private $contactsManager;
/** @var ProfileManager */
private $profileManager;
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IUserManager|MockObject */
private $userManager;
/** @var IURLGenerator */
private $urlGenerator;
- /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IGroupManager|MockObject */
private $groupManager;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
private $config;
/** @var KnownUserService|MockObject */
private $knownUserService;
@@ -82,7 +81,7 @@ class ContactsStoreTest extends TestCase {
}
public function testGetContactsWithoutFilter() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
@@ -112,7 +111,7 @@ class ContactsStoreTest extends TestCase {
}
public function testGetContactsHidesOwnEntry() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
@@ -139,7 +138,7 @@ class ContactsStoreTest extends TestCase {
}
public function testGetContactsWithoutBinaryImage() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
@@ -168,7 +167,7 @@ class ContactsStoreTest extends TestCase {
}
public function testGetContactsWithoutAvatarURI() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
@@ -208,7 +207,7 @@ class ContactsStoreTest extends TestCase {
['core', 'shareapi_exclude_groups_list', '', '["group1", "group5", "group6"]'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
@@ -251,44 +250,39 @@ class ContactsStoreTest extends TestCase {
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
- ->method('getUserGroupIds')
- ->with($this->equalTo($currentUser))
- ->willReturn(['group1', 'group2', 'group3']);
-
$user1 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(0))
- ->method('get')
- ->with('user1')
- ->willReturn($user1);
- $this->groupManager->expects($this->at(1))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user1))
- ->willReturn(['group1']);
$user2 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(1))
- ->method('get')
- ->with('user2')
- ->willReturn($user2);
- $this->groupManager->expects($this->at(2))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user2))
- ->willReturn(['group2', 'group3']);
$user3 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(2))
- ->method('get')
- ->with('user3')
- ->willReturn($user3);
- $this->groupManager->expects($this->at(3))
+
+ $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->with($this->equalTo($user3))
- ->willReturn(['group8', 'group9']);
+ ->withConsecutive(
+ [$this->equalTo($currentUser)],
+ [$this->equalTo($user1)],
+ [$this->equalTo($user2)],
+ [$this->equalTo($user3)]
+ )
+ ->willReturnOnConsecutiveCalls(
+ ['group1', 'group2', 'group3'],
+ ['group1'],
+ ['group2', 'group3'],
+ ['group8', 'group9']
+ );
+
+ $this->userManager->expects($this->exactly(3))
+ ->method('get')
+ ->withConsecutive(
+ ['user1'],
+ ['user2'],
+ ['user3']
+ )
+ ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
$this->contactsManager->expects($this->once())
->method('search')
@@ -330,44 +324,39 @@ class ContactsStoreTest extends TestCase {
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
- ->method('getUserGroupIds')
- ->with($this->equalTo($currentUser))
- ->willReturn(['group1', 'group2', 'group3']);
-
$user1 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(0))
- ->method('get')
- ->with('user1')
- ->willReturn($user1);
- $this->groupManager->expects($this->at(1))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user1))
- ->willReturn(['group1']);
$user2 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(1))
- ->method('get')
- ->with('user2')
- ->willReturn($user2);
- $this->groupManager->expects($this->at(2))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user2))
- ->willReturn(['group2', 'group3']);
$user3 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(2))
- ->method('get')
- ->with('user3')
- ->willReturn($user3);
- $this->groupManager->expects($this->at(3))
+
+ $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->with($this->equalTo($user3))
- ->willReturn(['group8', 'group9']);
+ ->withConsecutive(
+ [$this->equalTo($currentUser)],
+ [$this->equalTo($user1)],
+ [$this->equalTo($user2)],
+ [$this->equalTo($user3)]
+ )
+ ->willReturnOnConsecutiveCalls(
+ ['group1', 'group2', 'group3'],
+ ['group1'],
+ ['group2', 'group3'],
+ ['group8', 'group9']
+ );
+
+ $this->userManager->expects($this->exactly(3))
+ ->method('get')
+ ->withConsecutive(
+ ['user1'],
+ ['user2'],
+ ['user3']
+ )
+ ->willReturn($user1, $user2, $user3);
$this->contactsManager->expects($this->once())
->method('search')
@@ -409,13 +398,13 @@ class ContactsStoreTest extends TestCase {
['core', 'shareapi_only_share_with_group_members', 'no', 'no'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
+ $this->groupManager->expects($this->once())
->method('getUserGroupIds')
->with($this->equalTo($currentUser))
->willReturn(['group1', 'group2', 'group3']);
@@ -467,44 +456,39 @@ class ContactsStoreTest extends TestCase {
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
- ->method('getUserGroupIds')
- ->with($this->equalTo($currentUser))
- ->willReturn(['group1', 'group2', 'group3']);
-
$user1 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(0))
- ->method('get')
- ->with('user1')
- ->willReturn($user1);
- $this->groupManager->expects($this->at(1))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user1))
- ->willReturn(['group1']);
$user2 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(1))
- ->method('get')
- ->with('user2')
- ->willReturn($user2);
- $this->groupManager->expects($this->at(2))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user2))
- ->willReturn(['group2', 'group3']);
$user3 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(2))
- ->method('get')
- ->with('user3')
- ->willReturn($user3);
- $this->groupManager->expects($this->at(3))
+
+ $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->with($this->equalTo($user3))
- ->willReturn(['group8', 'group9']);
+ ->withConsecutive(
+ [$this->equalTo($currentUser)],
+ [$this->equalTo($user1)],
+ [$this->equalTo($user2)],
+ [$this->equalTo($user3)]
+ )
+ ->willReturnOnConsecutiveCalls(
+ ['group1', 'group2', 'group3'],
+ ['group1'],
+ ['group2', 'group3'],
+ ['group8', 'group9']
+ );
+
+ $this->userManager->expects($this->exactly(3))
+ ->method('get')
+ ->withConsecutive(
+ ['user1'],
+ ['user2'],
+ ['user3']
+ )
+ ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([
@@ -553,26 +537,29 @@ class ContactsStoreTest extends TestCase {
['core', 'shareapi_only_share_with_group_members', 'no', 'no'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
- ->method('getUserGroupIds')
- ->with($this->equalTo($currentUser))
- ->willReturn(['group1', 'group2', 'group3']);
-
$user1 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(0))
+
+ $this->groupManager->expects($this->exactly(2))
+ ->method('getUserGroupIds')
+ ->withConsecutive(
+ [$this->equalTo($currentUser)],
+ [$this->equalTo($user1)]
+ )
+ ->willReturnOnConsecutiveCalls(
+ ['group1', 'group2', 'group3'],
+ ['group1']
+ );
+
+ $this->userManager->expects($this->once())
->method('get')
->with('user1')
->willReturn($user1);
- $this->groupManager->expects($this->at(1))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user1))
- ->willReturn(['group1']);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([
@@ -622,44 +609,39 @@ class ContactsStoreTest extends TestCase {
['core', 'shareapi_only_share_with_group_members', 'no', 'yes'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $currentUser */
+ /** @var IUser|MockObject $currentUser */
$currentUser = $this->createMock(IUser::class);
$currentUser->expects($this->exactly(2))
->method('getUID')
->willReturn('user001');
- $this->groupManager->expects($this->at(0))
- ->method('getUserGroupIds')
- ->with($this->equalTo($currentUser))
- ->willReturn(['group1', 'group2', 'group3']);
-
$user1 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(0))
- ->method('get')
- ->with('user1')
- ->willReturn($user1);
- $this->groupManager->expects($this->at(1))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user1))
- ->willReturn(['group1']);
$user2 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(1))
- ->method('get')
- ->with('user2')
- ->willReturn($user2);
- $this->groupManager->expects($this->at(2))
- ->method('getUserGroupIds')
- ->with($this->equalTo($user2))
- ->willReturn(['group2', 'group3']);
$user3 = $this->createMock(IUser::class);
- $this->userManager->expects($this->at(2))
- ->method('get')
- ->with('user3')
- ->willReturn($user3);
- $this->groupManager->expects($this->at(3))
+
+ $this->groupManager->expects($this->exactly(4))
->method('getUserGroupIds')
- ->with($this->equalTo($user3))
- ->willReturn(['group8', 'group9']);
+ ->withConsecutive(
+ [$this->equalTo($currentUser)],
+ [$this->equalTo($user1)],
+ [$this->equalTo($user2)],
+ [$this->equalTo($user3)]
+ )
+ ->willReturnOnConsecutiveCalls(
+ ['group1', 'group2', 'group3'],
+ ['group1'],
+ ['group2', 'group3'],
+ ['group8', 'group9']
+ );
+
+ $this->userManager->expects($this->exactly(3))
+ ->method('get')
+ ->withConsecutive(
+ ['user1'],
+ ['user2'],
+ ['user3']
+ )
+ ->willReturnOnConsecutiveCalls($user1, $user2, $user3);
$this->knownUserService->method('isKnownToUser')
->willReturnMap([
@@ -705,7 +687,7 @@ class ContactsStoreTest extends TestCase {
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->any())
->method('search')
@@ -792,7 +774,7 @@ class ContactsStoreTest extends TestCase {
['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'no'],
]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->any())
->method('search')
@@ -869,11 +851,18 @@ class ContactsStoreTest extends TestCase {
}
public function testFindOneUser() {
- $this->config->expects($this->at(0))->method('getAppValue')
- ->with($this->equalTo('core'), $this->equalTo('shareapi_allow_share_dialog_user_enumeration'), $this->equalTo('yes'))
- ->willReturn('yes');
+ $this->config
+ ->method('getAppValue')
+ ->willReturnMap([
+ ['core', 'shareapi_allow_share_dialog_user_enumeration', 'yes', 'yes'],
+ ['core', 'shareapi_restrict_user_enumeration_to_group', 'no', 'no'],
+ ['core', 'shareapi_restrict_user_enumeration_to_phone', 'no', 'no'],
+ ['core', 'shareapi_restrict_user_enumeration_full_match', 'yes', 'yes'],
+ ['core', 'shareapi_exclude_groups', 'no', 'yes'],
+ ['core', 'shareapi_only_share_with_group_members', 'no', 'no'],
+ ]);
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
@@ -904,7 +893,7 @@ class ContactsStoreTest extends TestCase {
}
public function testFindOneEMail() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
@@ -935,7 +924,7 @@ class ContactsStoreTest extends TestCase {
}
public function testFindOneNotSupportedType() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$entry = $this->contactsStore->findOne($user, 42, 'darren@roner.au');
@@ -944,7 +933,7 @@ class ContactsStoreTest extends TestCase {
}
public function testFindOneNoMatches() {
- /** @var IUser|\PHPUnit\Framework\MockObject\MockObject $user */
+ /** @var IUser|MockObject $user */
$user = $this->createMock(IUser::class);
$this->contactsManager->expects($this->once())
->method('search')
diff --git a/tests/lib/Contacts/ContactsMenu/EntryTest.php b/tests/lib/Contacts/ContactsMenu/EntryTest.php
index 561afcf5dde..684edd9f25e 100644
--- a/tests/lib/Contacts/ContactsMenu/EntryTest.php
+++ b/tests/lib/Contacts/ContactsMenu/EntryTest.php
@@ -29,9 +29,7 @@ use OC\Contacts\ContactsMenu\Entry;
use Test\TestCase;
class EntryTest extends TestCase {
-
- /** @var Entry */
- private $entry;
+ private Entry $entry;
protected function setUp(): void {
parent::setUp();
diff --git a/tests/lib/Contacts/ContactsMenu/ManagerTest.php b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
index 2f5acf61644..ecd925faffa 100644
--- a/tests/lib/Contacts/ContactsMenu/ManagerTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
@@ -33,24 +33,24 @@ use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IConfig;
use OCP\IUser;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class ManagerTest extends TestCase {
- /** @var ContactsStore|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ContactsStore|MockObject */
private $contactsStore;
- /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IAppManager|MockObject */
private $appManager;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IConfig|MockObject */
private $config;
- /** @var ActionProviderStore|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ActionProviderStore|MockObject */
private $actionProviderStore;
- /** @var Manager */
- private $manager;
+ private Manager $manager;
protected function setUp(): void {
parent::setUp();
@@ -63,7 +63,7 @@ class ManagerTest extends TestCase {
$this->manager = new Manager($this->contactsStore, $this->actionProviderStore, $this->appManager, $this->config);
}
- private function generateTestEntries() {
+ private function generateTestEntries(): array {
$entries = [];
foreach (range('Z', 'A') as $char) {
$entry = $this->createMock(IEntry::class);
@@ -81,14 +81,13 @@ class ManagerTest extends TestCase {
$entries = $this->generateTestEntries();
$provider = $this->createMock(IProvider::class);
- $this->config->expects($this->at(0))
+ $this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
- ->willReturn(25);
- $this->config->expects($this->at(1))
- ->method('getSystemValueInt')
- ->with('sharing.minSearchStringLength', 0)
- ->willReturn(0);
+ ->withConsecutive(
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
+ ['sharing.minSearchStringLength', 0]
+ )
+ ->willReturnOnConsecutiveCalls(25, 0);
$this->contactsStore->expects($this->once())
->method('getContacts')
->with($user, $filter)
@@ -119,14 +118,13 @@ class ManagerTest extends TestCase {
$entries = $this->generateTestEntries();
$provider = $this->createMock(IProvider::class);
- $this->config->expects($this->at(0))
- ->method('getSystemValueInt')
- ->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
- ->willReturn(3);
- $this->config->expects($this->at(1))
+ $this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->with('sharing.minSearchStringLength', 0)
- ->willReturn(0);
+ ->withConsecutive(
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
+ ['sharing.minSearchStringLength', 0]
+ )
+ ->willReturnOnConsecutiveCalls(3, 0);
$this->contactsStore->expects($this->once())
->method('getContacts')
->with($user, $filter)
@@ -156,14 +154,13 @@ class ManagerTest extends TestCase {
$user = $this->createMock(IUser::class);
$provider = $this->createMock(IProvider::class);
- $this->config->expects($this->at(0))
- ->method('getSystemValueInt')
- ->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
- ->willReturn(3);
- $this->config->expects($this->at(1))
+ $this->config->expects($this->exactly(2))
->method('getSystemValueInt')
- ->with('sharing.minSearchStringLength', 0)
- ->willReturn(4);
+ ->withConsecutive(
+ ['sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT],
+ ['sharing.minSearchStringLength', 0]
+ )
+ ->willReturnOnConsecutiveCalls(3, 4);
$this->appManager->expects($this->once())
->method('isEnabledForUser')
->with($this->equalTo('contacts'), $user)
diff --git a/tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php b/tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php
index c0052469aba..39deeeaecc9 100644
--- a/tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php
+++ b/tests/lib/Contacts/ContactsMenu/Providers/EMailproviderTest.php
@@ -29,18 +29,18 @@ use OCP\Contacts\ContactsMenu\IActionFactory;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\ContactsMenu\ILinkAction;
use OCP\IURLGenerator;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class EMailproviderTest extends TestCase {
- /** @var IActionFactory|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IActionFactory|MockObject */
private $actionFactory;
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var IURLGenerator|MockObject */
private $urlGenerator;
- /** @var EMailProvider */
- private $provider;
+ private EMailProvider $provider;
protected function setUp(): void {
parent::setUp();
@@ -80,7 +80,6 @@ class EMailproviderTest extends TestCase {
public function testProcessEmptyAddress() {
$entry = $this->createMock(IEntry::class);
- $action = $this->createMock(ILinkAction::class);
$iconUrl = 'https://example.com/img/actions/icon.svg';
$this->urlGenerator->expects($this->once())
->method('imagePath')
diff --git a/tests/lib/Files/Cache/SearchBuilderTest.php b/tests/lib/Files/Cache/SearchBuilderTest.php
index 82c4dbaa27f..5eb1a0252f0 100644
--- a/tests/lib/Files/Cache/SearchBuilderTest.php
+++ b/tests/lib/Files/Cache/SearchBuilderTest.php
@@ -79,7 +79,7 @@ class SearchBuilderTest extends TestCase {
$this->numericStorageId = 10000;
$this->builder->select(['fileid'])
- ->from('filecache')
+ ->from('filecache', 'file') // alias needed for QuerySearchHelper#getOperatorFieldAndValue
->where($this->builder->expr()->eq('storage', new Literal($this->numericStorageId)));
}
diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php
index f4c6a427abd..221159bc983 100644
--- a/tests/lib/Files/Config/UserMountCacheTest.php
+++ b/tests/lib/Files/Config/UserMountCacheTest.php
@@ -11,6 +11,7 @@ namespace Test\Files\Config;
use OC\DB\QueryBuilder\Literal;
use OC\Files\Mount\MountPoint;
use OC\Files\Storage\Storage;
+use OC\Cache\CappedMemoryCache;
use OC\User\Manager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\ICachedMountInfo;
@@ -114,7 +115,7 @@ class UserMountCacheTest extends TestCase {
}
private function clearCache() {
- $this->invokePrivate($this->cache, 'mountsForUsers', [[]]);
+ $this->invokePrivate($this->cache, 'mountsForUsers', [new CappedMemoryCache()]);
}
public function testNewMounts() {
diff --git a/tests/lib/Repair/ClearFrontendCachesTest.php b/tests/lib/Repair/ClearFrontendCachesTest.php
index 9acd1f4df17..d89a19e70cc 100644
--- a/tests/lib/Repair/ClearFrontendCachesTest.php
+++ b/tests/lib/Repair/ClearFrontendCachesTest.php
@@ -24,7 +24,6 @@
namespace Test\Repair;
use OC\Template\JSCombiner;
-use OC\Template\SCSSCacher;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\Migration\IOutput;
@@ -34,9 +33,6 @@ class ClearFrontendCachesTest extends \Test\TestCase {
/** @var ICacheFactory */
private $cacheFactory;
- /** @var SCSSCacher */
- private $scssCacher;
-
/** @var JSCombiner */
private $jsCombiner;
@@ -52,10 +48,9 @@ class ClearFrontendCachesTest extends \Test\TestCase {
$this->outputMock = $this->createMock(IOutput::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
- $this->scssCacher = $this->createMock(SCSSCacher::class);
$this->jsCombiner = $this->createMock(JSCombiner::class);
- $this->repair = new \OC\Repair\ClearFrontendCaches($this->cacheFactory, $this->scssCacher, $this->jsCombiner);
+ $this->repair = new \OC\Repair\ClearFrontendCaches($this->cacheFactory, $this->jsCombiner);
}
@@ -66,8 +61,6 @@ class ClearFrontendCachesTest extends \Test\TestCase {
->with('');
$this->jsCombiner->expects($this->once())
->method('resetCache');
- $this->scssCacher->expects($this->once())
- ->method('resetCache');
$this->cacheFactory->expects($this->at(0))
->method('createDistributed')
->with('imagePath')
diff --git a/tests/lib/Template/CSSResourceLocatorTest.php b/tests/lib/Template/CSSResourceLocatorTest.php
index 8f93ef6d9df..3d337dceb9e 100644
--- a/tests/lib/Template/CSSResourceLocatorTest.php
+++ b/tests/lib/Template/CSSResourceLocatorTest.php
@@ -27,7 +27,6 @@ use OC\AppConfig;
use OC\Files\AppData\AppData;
use OC\Files\AppData\Factory;
use OC\Template\CSSResourceLocator;
-use OC\Template\SCSSCacher;
use OCA\Theming\ThemingDefaults;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Files\IAppData;
@@ -71,23 +70,11 @@ class CSSResourceLocatorTest extends \Test\TestCase {
/** @var Factory|\PHPUnit\Framework\MockObject\MockObject $factory */
$factory = $this->createMock(Factory::class);
$factory->method('get')->with('css')->willReturn($this->appData);
- $scssCacher = new SCSSCacher(
- $this->logger,
- $factory,
- $this->urlGenerator,
- $this->config,
- $this->themingDefaults,
- \OC::$SERVERROOT,
- $this->cacheFactory,
- $this->timeFactory,
- $this->appConfig
- );
return new CSSResourceLocator(
$this->logger,
'theme',
['core' => 'map'],
['3rd' => 'party'],
- $scssCacher
);
}
diff --git a/tests/lib/Template/SCSSCacherTest.php b/tests/lib/Template/SCSSCacherTest.php
deleted file mode 100644
index 576ba35d009..00000000000
--- a/tests/lib/Template/SCSSCacherTest.php
+++ /dev/null
@@ -1,524 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2017 Julius Härtl <jus@bitgrid.net>
- *
- * @author Julius Härtl <jus@bitgrid.net>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace Test\Template;
-
-use OC\AppConfig;
-use OC\Files\AppData\AppData;
-use OC\Files\AppData\Factory;
-use OC\Template\SCSSCacher;
-use OCA\Theming\ThemingDefaults;
-use OCP\AppFramework\Utility\ITimeFactory;
-use OCP\Files\IAppData;
-use OCP\Files\NotFoundException;
-use OCP\Files\SimpleFS\ISimpleFile;
-use OCP\Files\SimpleFS\ISimpleFolder;
-use OCP\ICache;
-use OCP\ICacheFactory;
-use OCP\IConfig;
-use OCP\IURLGenerator;
-use Psr\Log\LoggerInterface;
-
-class SCSSCacherTest extends \Test\TestCase {
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- protected $logger;
- /** @var IAppData|\PHPUnit\Framework\MockObject\MockObject */
- protected $appData;
- /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */
- protected $urlGenerator;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
- /** @var ThemingDefaults|\PHPUnit\Framework\MockObject\MockObject */
- protected $themingDefaults;
- /** @var SCSSCacher */
- protected $scssCacher;
- /** @var ICache|\PHPUnit\Framework\MockObject\MockObject */
- protected $depsCache;
- /** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
- protected $isCachedCache;
- /** @var ICacheFactory|\PHPUnit\Framework\MockObject\MockObject */
- protected $cacheFactory;
- /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject */
- protected $timeFactory;
- /** @var AppConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $appConfig;
-
- protected function setUp(): void {
- parent::setUp();
- $this->logger = $this->createMock(LoggerInterface::class);
- $this->appData = $this->createMock(AppData::class);
- $this->timeFactory = $this->createMock(ITimeFactory::class);
-
- /** @var Factory|\PHPUnit\Framework\MockObject\MockObject $factory */
- $factory = $this->createMock(Factory::class);
- $factory->method('get')->with('css')->willReturn($this->appData);
-
- $this->urlGenerator = $this->createMock(IURLGenerator::class);
- $this->urlGenerator->expects($this->any())
- ->method('getBaseUrl')
- ->willReturn('http://localhost/nextcloud');
-
- $this->config = $this->createMock(IConfig::class);
- $this->config->expects($this->any())
- ->method('getAppValue')
- ->will($this->returnCallback(function ($appId, $configKey, $defaultValue) {
- return $defaultValue;
- }));
- $this->cacheFactory = $this->createMock(ICacheFactory::class);
- $this->depsCache = $this->createMock(ICache::class);
- $this->isCachedCache = $this->createMock(ICache::class);
- $this->cacheFactory
- ->method('createDistributed')
- ->withConsecutive()
- ->willReturnOnConsecutiveCalls(
- $this->depsCache,
- $this->isCachedCache,
- $this->createMock(ICache::class)
- );
-
- $this->themingDefaults = $this->createMock(ThemingDefaults::class);
- $this->themingDefaults->expects($this->any())->method('getScssVariables')->willReturn([]);
-
- $iconsFile = $this->createMock(ISimpleFile::class);
-
- $this->appConfig = $this->createMock(AppConfig::class);
-
- $this->scssCacher = new SCSSCacher(
- $this->logger,
- $factory,
- $this->urlGenerator,
- $this->config,
- $this->themingDefaults,
- \OC::$SERVERROOT,
- $this->cacheFactory,
- $this->timeFactory,
- $this->appConfig
- );
- }
-
- public function testProcessUncachedFileNoAppDataFolder() {
- $folder = $this->createMock(ISimpleFolder::class);
- $file = $this->createMock(ISimpleFile::class);
- $file->expects($this->any())->method('getSize')->willReturn(1);
-
- $this->appData->expects($this->once())->method('getFolder')->with('core')->willThrowException(new NotFoundException());
- $this->appData->expects($this->once())->method('newFolder')->with('core')->willReturn($folder);
- $this->appData->method('getDirectoryListing')->willReturn([]);
-
- $fileDeps = $this->createMock(ISimpleFile::class);
- $gzfile = $this->createMock(ISimpleFile::class);
- $filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
- substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
-
- $folder->method('getFile')
- ->willReturnCallback(function ($path) use ($file, $gzfile, $filePrefix) {
- if ($path === $filePrefix.'styles.css') {
- return $file;
- } elseif ($path === $filePrefix.'styles.css.deps') {
- throw new NotFoundException();
- } elseif ($path === $filePrefix.'styles.css.gzip') {
- return $gzfile;
- } else {
- $this->fail();
- }
- });
- $folder->expects($this->once())
- ->method('newFile')
- ->with($filePrefix.'styles.css.deps')
- ->willReturn($fileDeps);
-
- $this->urlGenerator->expects($this->once())
- ->method('getBaseUrl')
- ->willReturn('http://localhost/nextcloud');
-
- $actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
- $this->assertTrue($actual);
- }
-
- public function testProcessUncachedFile() {
- $folder = $this->createMock(ISimpleFolder::class);
- $this->appData->expects($this->once())->method('getFolder')->with('core')->willReturn($folder);
- $this->appData->method('getDirectoryListing')->willReturn([]);
- $file = $this->createMock(ISimpleFile::class);
- $file->expects($this->any())->method('getSize')->willReturn(1);
- $fileDeps = $this->createMock(ISimpleFile::class);
- $gzfile = $this->createMock(ISimpleFile::class);
- $filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
- substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
-
- $folder->method('getFile')
- ->willReturnCallback(function ($path) use ($file, $gzfile, $filePrefix) {
- if ($path === $filePrefix.'styles.css') {
- return $file;
- } elseif ($path === $filePrefix.'styles.css.deps') {
- throw new NotFoundException();
- } elseif ($path === $filePrefix.'styles.css.gzip') {
- return $gzfile;
- } else {
- $this->fail();
- }
- });
- $folder->expects($this->once())
- ->method('newFile')
- ->with($filePrefix.'styles.css.deps')
- ->willReturn($fileDeps);
-
- $actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
- $this->assertTrue($actual);
- }
-
- public function testProcessCachedFile() {
- $folder = $this->createMock(ISimpleFolder::class);
- $this->appData->expects($this->once())->method('getFolder')->with('core')->willReturn($folder);
- $this->appData->method('getDirectoryListing')->willReturn([]);
- $file = $this->createMock(ISimpleFile::class);
- $fileDeps = $this->createMock(ISimpleFile::class);
- $fileDeps->expects($this->any())->method('getSize')->willReturn(1);
- $gzFile = $this->createMock(ISimpleFile::class);
- $filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
- substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
-
- $folder->method('getFile')
- ->willReturnCallback(function ($name) use ($file, $fileDeps, $gzFile, $filePrefix) {
- if ($name === $filePrefix.'styles.css') {
- return $file;
- } elseif ($name === $filePrefix.'styles.css.deps') {
- return $fileDeps;
- } elseif ($name === $filePrefix.'styles.css.gzip') {
- return $gzFile;
- }
- $this->fail();
- });
-
- $actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
- $this->assertTrue($actual);
- }
-
- public function testProcessCachedFileMemcache() {
- $folder = $this->createMock(ISimpleFolder::class);
- $this->appData->expects($this->once())
- ->method('getFolder')
- ->with('core')
- ->willReturn($folder);
- $folder->method('getName')
- ->willReturn('core');
- $this->appData->method('getDirectoryListing')->willReturn([]);
-
- $file = $this->createMock(ISimpleFile::class);
-
- $fileDeps = $this->createMock(ISimpleFile::class);
- $fileDeps->expects($this->any())->method('getSize')->willReturn(1);
-
- $gzFile = $this->createMock(ISimpleFile::class);
- $filePrefix = substr(md5(\OC_Util::getVersionString('core')), 0, 4) . '-' .
- substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-';
- $folder->method('getFile')
- ->willReturnCallback(function ($name) use ($file, $fileDeps, $gzFile, $filePrefix) {
- if ($name === $filePrefix.'styles.css') {
- return $file;
- } elseif ($name === $filePrefix.'styles.css.deps') {
- return $fileDeps;
- } elseif ($name === $filePrefix.'styles.css.gzip') {
- return $gzFile;
- }
- $this->fail();
- });
-
- $actual = $this->scssCacher->process(\OC::$SERVERROOT, '/core/css/styles.scss', 'core');
- $this->assertTrue($actual);
- }
-
- public function testIsCachedNoFile() {
- $fileNameCSS = "styles.css";
- $folder = $this->createMock(ISimpleFolder::class);
-
- $folder->expects($this->at(0))->method('getFile')->with($fileNameCSS)->willThrowException(new NotFoundException());
- $this->appData->expects($this->any())
- ->method('getFolder')
- ->willReturn($folder);
- $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, 'core']);
- $this->assertFalse($actual);
- }
-
- public function testIsCachedNoDepsFile() {
- $fileNameCSS = "styles.css";
- $folder = $this->createMock(ISimpleFolder::class);
- $file = $this->createMock(ISimpleFile::class);
-
- $file->expects($this->once())->method('getSize')->willReturn(1);
- $folder->method('getFile')
- ->willReturnCallback(function ($path) use ($file) {
- if ($path === 'styles.css') {
- return $file;
- } elseif ($path === 'styles.css.deps') {
- throw new NotFoundException();
- } else {
- $this->fail();
- }
- });
-
- $this->appData->expects($this->any())
- ->method('getFolder')
- ->willReturn($folder);
- $actual = self::invokePrivate($this->scssCacher, 'isCached', [$fileNameCSS, 'core']);
- $this->assertFalse($actual);
- }
- public function testCacheNoFile() {
- $fileNameCSS = "styles.css";
- $fileNameSCSS = "styles.scss";
- $folder = $this->createMock(ISimpleFolder::class);
- $file = $this->createMock(ISimpleFile::class);
- $depsFile = $this->createMock(ISimpleFile::class);
- $gzipFile = $this->createMock(ISimpleFile::class);
-
- $webDir = "core/css";
- $path = \OC::$SERVERROOT . '/core/css/';
-
- $folder->method('getFile')->willThrowException(new NotFoundException());
- $folder->method('newFile')->willReturnCallback(function ($fileName) use ($file, $depsFile, $gzipFile) {
- if ($fileName === 'styles.css') {
- return $file;
- } elseif ($fileName === 'styles.css.deps') {
- return $depsFile;
- } elseif ($fileName === 'styles.css.gzip') {
- return $gzipFile;
- }
- throw new \Exception();
- });
-
- $file->expects($this->once())->method('putContent');
- $depsFile->expects($this->once())->method('putContent');
- $gzipFile->expects($this->once())->method('putContent');
-
- $actual = self::invokePrivate($this->scssCacher, 'cache', [$path, $fileNameCSS, $fileNameSCSS, $folder, $webDir]);
- $this->assertTrue($actual);
- }
-
- public function testCache() {
- $fileNameCSS = "styles.css";
- $fileNameSCSS = "styles.scss";
- $folder = $this->createMock(ISimpleFolder::class);
- $file = $this->createMock(ISimpleFile::class);
- $depsFile = $this->createMock(ISimpleFile::class);
- $gzipFile = $this->createMock(ISimpleFile::class);
-
- $webDir = "core/css";
- $path = \OC::$SERVERROOT;
-
- $folder->method('getFile')->willReturnCallback(function ($fileName) use ($file, $depsFile, $gzipFile) {
- if ($fileName === 'styles.css') {
- return $file;
- } elseif ($fileName === 'styles.css.deps') {
- return $depsFile;
- } elseif ($fileName === 'styles.css.gzip') {
- return $gzipFile;
- }
- throw new \Exception();
- });
-
- $file->expects($this->once())->method('putContent');
- $depsFile->expects($this->once())->method('putContent');
- $gzipFile->expects($this->once())->method('putContent');
-
- $actual = self::invokePrivate($this->scssCacher, 'cache', [$path, $fileNameCSS, $fileNameSCSS, $folder, $webDir]);
- $this->assertTrue($actual);
- }
-
- public function testCacheSuccess() {
- $fileNameCSS = "styles-success.css";
- $fileNameSCSS = "../../tests/data/scss/styles-success.scss";
- $folder = $this->createMock(ISimpleFolder::class);
- $file = $this->createMock(ISimpleFile::class);
- $depsFile = $this->createMock(ISimpleFile::class);
- $gzipFile = $this->createMock(ISimpleFile::class);
-
- $webDir = "tests/data/scss";
- $path = \OC::$SERVERROOT . $webDir;
-
- $folder->method('getFile')->willReturnCallback(function ($fileName) use ($file, $depsFile, $gzipFile) {
- if ($fileName === 'styles-success.css') {
- return $file;
- } elseif ($fileName === 'styles-success.css.deps') {
- return $depsFile;
- } elseif ($fileName === 'styles-success.css.gzip') {
- return $gzipFile;
- }
- throw new \Exception();
- });
-
- $file->expects($this->at(0))->method('putContent')->with($this->callback(
- function ($content) {
- return 'body{background-color:#0082c9}' === $content;
- }));
- $depsFile->expects($this->at(0))->method('putContent')->with($this->callback(
- function ($content) {
- $deps = json_decode($content, true);
- return array_key_exists(\OC::$SERVERROOT . '/core/css/variables.scss', $deps)
- && array_key_exists(\OC::$SERVERROOT . '/tests/data/scss/styles-success.scss', $deps);
- }));
- $gzipFile->expects($this->at(0))->method('putContent')->with($this->callback(
- function ($content) {
- return gzdecode($content) === 'body{background-color:#0082c9}';
- }
- ));
-
- $actual = self::invokePrivate($this->scssCacher, 'cache', [$path, $fileNameCSS, $fileNameSCSS, $folder, $webDir]);
- $this->assertTrue($actual);
- }
-
- public function testCacheFailure() {
- $fileNameCSS = "styles-error.css";
- $fileNameSCSS = "../../tests/data/scss/styles-error.scss";
- $folder = $this->createMock(ISimpleFolder::class);
- $file = $this->createMock(ISimpleFile::class);
- $depsFile = $this->createMock(ISimpleFile::class);
-
- $webDir = "/tests/data/scss";
- $path = \OC::$SERVERROOT . $webDir;
-
- $folder->expects($this->at(0))->method('getFile')->with($fileNameCSS)->willReturn($file);
- $folder->expects($this->at(1))->method('getFile')->with($fileNameCSS . '.deps')->willReturn($depsFile);
-
- $actual = self::invokePrivate($this->scssCacher, 'cache', [$path, $fileNameCSS, $fileNameSCSS, $folder, $webDir]);
- $this->assertFalse($actual);
- }
-
- public function dataRebaseUrls() {
- return [
- ['#id { background-image: url(\'../img/image.jpg\'); }','#id { background-image: url(\'/apps/files/css/../img/image.jpg\'); }'],
- ['#id { background-image: url("../img/image.jpg"); }','#id { background-image: url(\'/apps/files/css/../img/image.jpg\'); }'],
- ['#id { background-image: url(\'/img/image.jpg\'); }','#id { background-image: url(\'/img/image.jpg\'); }'],
- ['#id { background-image: url("http://example.com/test.jpg"); }','#id { background-image: url("http://example.com/test.jpg"); }'],
- ];
- }
-
- /**
- * @dataProvider dataRebaseUrls
- */
- public function testRebaseUrls($scss, $expected) {
- $webDir = '/apps/files/css';
- $actual = self::invokePrivate($this->scssCacher, 'rebaseUrls', [$scss, $webDir]);
- $this->assertEquals($expected, $actual);
- }
-
- public function dataGetCachedSCSS() {
- return [
- ['core', 'core/css/styles.scss', '/css/core/styles.css', \OC_Util::getVersionString()],
- ['files', 'apps/files/css/styles.scss', '/css/files/styles.css', \OC_App::getAppVersion('files')]
- ];
- }
-
- /**
- * @param $appName
- * @param $fileName
- * @param $result
- * @dataProvider dataGetCachedSCSS
- */
- public function testGetCachedSCSS($appName, $fileName, $result, $version) {
- $this->urlGenerator->expects($this->once())
- ->method('linkToRoute')
- ->with('core.Css.getCss', [
- 'fileName' => substr(md5($version), 0, 4) . '-' .
- substr(md5('http://localhost/nextcloud/index.php'), 0, 4) . '-styles.css',
- 'appName' => $appName,
- 'v' => 0,
- ])
- ->willReturn(\OC::$WEBROOT . $result);
- $actual = $this->scssCacher->getCachedSCSS($appName, $fileName);
- $this->assertEquals(substr($result, 1), $actual);
- }
-
- private function randomString() {
- return sha1(uniqid(mt_rand(), true));
- }
-
- private function rrmdir($directory) {
- $files = array_diff(scandir($directory), ['.','..']);
- foreach ($files as $file) {
- if (is_dir($directory . '/' . $file)) {
- $this->rrmdir($directory . '/' . $file);
- } else {
- unlink($directory . '/' . $file);
- }
- }
- return rmdir($directory);
- }
-
- public function dataGetWebDir() {
- return [
- // Root installation
- ['/http/core/css', 'core', '', '/http', '/core/css'],
- ['/http/apps/scss/css', 'scss', '', '/http', '/apps/scss/css'],
- ['/srv/apps2/scss/css', 'scss', '', '/http', '/apps2/scss/css'],
- // Sub directory install
- ['/http/nextcloud/core/css', 'core', '/nextcloud', '/http/nextcloud', '/nextcloud/core/css'],
- ['/http/nextcloud/apps/scss/css', 'scss', '/nextcloud', '/http/nextcloud', '/nextcloud/apps/scss/css'],
- ['/srv/apps2/scss/css', 'scss', '/nextcloud', '/http/nextcloud', '/apps2/scss/css']
- ];
- }
-
- /**
- * @param $path
- * @param $appName
- * @param $webRoot
- * @param $serverRoot
- * @dataProvider dataGetWebDir
- */
- public function testgetWebDir($path, $appName, $webRoot, $serverRoot, $correctWebDir) {
- $tmpDir = sys_get_temp_dir().'/'.$this->randomString();
- // Adding fake apps folder and create fake app install
- \OC::$APPSROOTS[] = [
- 'path' => $tmpDir.'/srv/apps2',
- 'url' => '/apps2',
- 'writable' => false
- ];
- mkdir($tmpDir.$path, 0777, true);
- $actual = self::invokePrivate($this->scssCacher, 'getWebDir', [$tmpDir.$path, $appName, $tmpDir.$serverRoot, $webRoot]);
- $this->assertEquals($correctWebDir, $actual);
- array_pop(\OC::$APPSROOTS);
- $this->rrmdir($tmpDir.$path);
- }
-
- public function testResetCache() {
- $file = $this->createMock(ISimpleFile::class);
- $file->expects($this->once())
- ->method('delete');
-
- $folder = $this->createMock(ISimpleFolder::class);
- $folder->expects($this->once())
- ->method('getDirectoryListing')
- ->willReturn([$file]);
-
- $this->depsCache->expects($this->once())
- ->method('clear')
- ->with('');
- $this->isCachedCache->expects($this->once())
- ->method('clear')
- ->with('');
- $this->appData->expects($this->once())
- ->method('getDirectoryListing')
- ->willReturn([$folder]);
-
- $this->scssCacher->resetCache();
- }
-}