aboutsummaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/provisioning_api/tests')
-rw-r--r--apps/provisioning_api/tests/CapabilitiesTest.php8
-rw-r--r--apps/provisioning_api/tests/Controller/AppConfigControllerTest.php28
-rw-r--r--apps/provisioning_api/tests/Controller/AppsControllerTest.php11
-rw-r--r--apps/provisioning_api/tests/Controller/GroupsControllerTest.php8
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php91
-rw-r--r--apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php9
6 files changed, 91 insertions, 64 deletions
diff --git a/apps/provisioning_api/tests/CapabilitiesTest.php b/apps/provisioning_api/tests/CapabilitiesTest.php
index 67a0335829c..86d2bb8c4fa 100644
--- a/apps/provisioning_api/tests/CapabilitiesTest.php
+++ b/apps/provisioning_api/tests/CapabilitiesTest.php
@@ -48,16 +48,14 @@ class CapabilitiesTest extends TestCase {
];
}
- /**
- * @dataProvider getCapabilitiesProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('getCapabilitiesProvider')]
public function testGetCapabilities(bool $federationAppEnabled, bool $federatedFileSharingAppEnabled, bool $lookupServerEnabled, bool $expectedFederatedScopeEnabled, bool $expectedPublishedScopeEnabled): void {
$this->appManager->expects($this->any())
->method('isEnabledForUser')
- ->will($this->returnValueMap([
+ ->willReturnMap([
['federation', null, $federationAppEnabled],
['federatedfilesharing', null, $federatedFileSharingAppEnabled],
- ]));
+ ]);
$federatedShareProvider = $this->createMock(FederatedShareProvider::class);
$this->overwriteService(FederatedShareProvider::class, $federatedShareProvider);
diff --git a/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php b/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php
index 3d2c1645d25..1b09838cbc3 100644
--- a/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/AppConfigControllerTest.php
@@ -103,9 +103,7 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataGetKeys
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetKeys')]
public function testGetKeys(string $app, ?array $keys, ?\Throwable $throws, int $status): void {
$api = $this->getInstance(['verifyAppId']);
if ($throws instanceof \Exception) {
@@ -144,9 +142,7 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataGetValue
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetValue')]
public function testGetValue(string $app, string $key, string $default, ?string $return, ?\Throwable $throws, int $status): void {
$api = $this->getInstance(['verifyAppId']);
if ($throws instanceof \Exception) {
@@ -190,9 +186,7 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataSetValue
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSetValue')]
public function testSetValue(string $app, string $key, string $value, ?\Throwable $appThrows, ?\Throwable $keyThrows, int $status, int|\Throwable $type = IAppConfig::VALUE_MIXED): void {
$adminUser = $this->createMock(IUser::class);
$adminUser->expects($this->once())
@@ -290,9 +284,7 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataDeleteValue
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataDeleteValue')]
public function testDeleteValue(string $app, string $key, ?\Throwable $appThrows, ?\Throwable $keyThrows, int $status): void {
$api = $this->getInstance(['verifyAppId', 'verifyConfigKey']);
if ($appThrows instanceof \Exception) {
@@ -356,9 +348,7 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataVerifyAppIdThrows
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataVerifyAppIdThrows')]
public function testVerifyAppIdThrows(string $app): void {
$this->expectException(\InvalidArgumentException::class);
@@ -375,9 +365,7 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataVerifyConfigKey
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataVerifyConfigKey')]
public function testVerifyConfigKey(string $app, string $key, string $value): void {
$api = $this->getInstance();
$this->invokePrivate($api, 'verifyConfigKey', [$app, $key, $value]);
@@ -398,9 +386,7 @@ class AppConfigControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataVerifyConfigKeyThrows
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataVerifyConfigKeyThrows')]
public function testVerifyConfigKeyThrows(string $app, string $key, string $value): void {
$this->expectException(\InvalidArgumentException::class);
diff --git a/apps/provisioning_api/tests/Controller/AppsControllerTest.php b/apps/provisioning_api/tests/Controller/AppsControllerTest.php
index f56be7c4c36..f95daeae7d3 100644
--- a/apps/provisioning_api/tests/Controller/AppsControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/AppsControllerTest.php
@@ -7,14 +7,17 @@
*/
namespace OCA\Provisioning_API\Tests\Controller;
+use OC\Installer;
use OCA\Provisioning_API\Controller\AppsController;
use OCA\Provisioning_API\Tests\TestCase;
use OCP\App\IAppManager;
use OCP\AppFramework\OCS\OCSException;
+use OCP\IAppConfig;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class AppsTest
@@ -25,6 +28,8 @@ use OCP\Server;
*/
class AppsControllerTest extends TestCase {
private IAppManager $appManager;
+ private IAppConfig&MockObject $appConfig;
+ private Installer&MockObject $installer;
private AppsController $api;
private IUserSession $userSession;
@@ -34,13 +39,17 @@ class AppsControllerTest extends TestCase {
$this->appManager = Server::get(IAppManager::class);
$this->groupManager = Server::get(IGroupManager::class);
$this->userSession = Server::get(IUserSession::class);
+ $this->appConfig = $this->createMock(IAppConfig::class);
+ $this->installer = $this->createMock(Installer::class);
$request = $this->createMock(IRequest::class);
$this->api = new AppsController(
'provisioning_api',
$request,
- $this->appManager
+ $this->appManager,
+ $this->installer,
+ $this->appConfig,
);
}
diff --git a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
index e4f8b3af183..85e5d733b1f 100644
--- a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
@@ -77,7 +77,7 @@ class GroupsControllerTest extends \Test\TestCase {
}
private function createGroup(string $gid): IGroup&MockObject {
- $group = $this->createMock(\OCP\IGroup::class);
+ $group = $this->createMock(IGroup::class);
$group
->method('getGID')
->willReturn($gid);
@@ -161,9 +161,7 @@ class GroupsControllerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dataGetGroups
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')]
public function testGetGroups(?string $search, int $limit, int $offset): void {
$groups = [$this->createGroup('group1'), $this->createGroup('group2')];
@@ -180,12 +178,12 @@ class GroupsControllerTest extends \Test\TestCase {
}
/**
- * @dataProvider dataGetGroups
*
* @param string|null $search
* @param int|null $limit
* @param int|null $offset
*/
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')]
public function testGetGroupsDetails($search, $limit, $offset): void {
$groups = [$this->createGroup('group1'), $this->createGroup('group2')];
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index 80d6d0f6152..85ec9e374d6 100644
--- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
@@ -20,6 +20,7 @@ use OCP\Accounts\IAccount;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\IAccountProperty;
use OCP\Accounts\IAccountPropertyCollection;
+use OCP\App\IAppManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\EventDispatcher\IEventDispatcher;
@@ -64,6 +65,7 @@ class UsersControllerTest extends TestCase {
private IEventDispatcher&MockObject $eventDispatcher;
private IRootFolder $rootFolder;
private IPhoneNumberUtil $phoneNumberUtil;
+ private IAppManager $appManager;
protected function setUp(): void {
parent::setUp();
@@ -84,6 +86,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService = $this->createMock(KnownUserService::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->phoneNumberUtil = new PhoneNumberUtil();
+ $this->appManager = $this->createMock(IAppManager::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$l10n = $this->createMock(IL10N::class);
@@ -110,6 +113,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['fillStorageInfo'])
->getMock();
@@ -195,8 +199,7 @@ class UsersControllerTest extends TestCase {
->willReturn($subAdminManager);
$this->groupManager
->expects($this->any())
- ->method('displayNamesInGroup')
- ->will($this->onConsecutiveCalls(['AnotherUserInTheFirstGroup' => []], ['UserInTheSecondGroup' => []]));
+ ->method('displayNamesInGroup')->willReturnOnConsecutiveCalls(['AnotherUserInTheFirstGroup' => []], ['UserInTheSecondGroup' => []]);
$expected = [
'users' => [
@@ -501,6 +504,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['editUser'])
->getMock();
@@ -605,7 +609,7 @@ class UsersControllerTest extends TestCase {
->willReturn(false);
$newUser = $this->createMock(IUser::class);
$newUser->expects($this->once())
- ->method('setEMailAddress');
+ ->method('setSystemEMailAddress');
$this->userManager
->expects($this->once())
->method('createUser')
@@ -641,6 +645,51 @@ class UsersControllerTest extends TestCase {
));
}
+ public function testAddUserSuccessfulLowercaseEmail(): void {
+ $this->userManager
+ ->expects($this->once())
+ ->method('userExists')
+ ->with('NewUser')
+ ->willReturn(false);
+ $newUser = $this->createMock(IUser::class);
+ $newUser->expects($this->once())
+ ->method('setSystemEMailAddress')
+ ->with('foo@bar.com');
+ $this->userManager
+ ->expects($this->once())
+ ->method('createUser')
+ ->willReturn($newUser);
+ $this->logger
+ ->expects($this->once())
+ ->method('info')
+ ->with('Successful addUser call with userid: NewUser', ['app' => 'ocs_api']);
+ $loggedInUser = $this->getMockBuilder(IUser::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $loggedInUser
+ ->expects($this->exactly(2))
+ ->method('getUID')
+ ->willReturn('adminUser');
+ $this->userSession
+ ->expects($this->once())
+ ->method('getUser')
+ ->willReturn($loggedInUser);
+ $this->groupManager
+ ->expects($this->once())
+ ->method('isAdmin')
+ ->with('adminUser')
+ ->willReturn(true);
+ $this->eventDispatcher
+ ->expects($this->once())
+ ->method('dispatchTyped')
+ ->with(new GenerateSecurePasswordEvent());
+
+ $this->assertTrue(key_exists(
+ 'id',
+ $this->api->addUser('NewUser', '', '', 'fOo@BaR.CoM')->getData()
+ ));
+ }
+
public function testAddUserFailedToGenerateUserID(): void {
$this->expectException(OCSException::class);
@@ -785,7 +834,7 @@ class UsersControllerTest extends TestCase {
$this->logger
->expects($this->exactly(2))
->method('info')
- ->willReturnCallback(function () use (&$calls) {
+ ->willReturnCallback(function () use (&$calls): void {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
@@ -809,7 +858,7 @@ class UsersControllerTest extends TestCase {
->expects($this->once())
->method('createUser')
->with('NewUser', 'PasswordOfTheNewUser')
- ->will($this->throwException($exception));
+ ->willThrowException($exception);
$this->logger
->expects($this->once())
->method('error')
@@ -989,7 +1038,7 @@ class UsersControllerTest extends TestCase {
$this->logger
->expects($this->exactly(3))
->method('info')
- ->willReturnCallback(function () use (&$calls) {
+ ->willReturnCallback(function () use (&$calls): void {
$expected = array_shift($calls);
$this->assertEquals($expected, func_get_args());
});
@@ -1529,9 +1578,7 @@ class UsersControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataSearchByPhoneNumbers
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchByPhoneNumbers')]
public function testSearchByPhoneNumbers(string $location, array $search, int $status, ?array $searchUsers, ?array $userMatches, array $expected): void {
$knownTo = 'knownTo';
$user = $this->createMock(IUser::class);
@@ -1627,7 +1674,7 @@ class UsersControllerTest extends TestCase {
->willReturn($targetUser);
$targetUser
->expects($this->once())
- ->method('setEMailAddress')
+ ->method('setSystemEMailAddress')
->with('demo@nextcloud.com');
$targetUser
->expects($this->any())
@@ -1857,9 +1904,7 @@ class UsersControllerTest extends TestCase {
];
}
- /**
- * @dataProvider selfEditChangePropertyProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('selfEditChangePropertyProvider')]
public function testEditUserRegularUserSelfEditChangeProperty($propertyName, $oldValue, $newValue): void {
$loggedInUser = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
@@ -1935,9 +1980,7 @@ class UsersControllerTest extends TestCase {
];
}
- /**
- * @dataProvider selfEditChangePropertyProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('selfEditChangePropertyProvider')]
public function testEditUserRegularUserSelfEditChangePropertyScope($propertyName, $oldScope, $newScope): void {
$loggedInUser = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
@@ -2272,9 +2315,7 @@ class UsersControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataEditUserSelfEditChangeLanguageButForced
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataEditUserSelfEditChangeLanguageButForced')]
public function testEditUserSelfEditChangeLanguageButForced($forced): void {
$this->expectException(OCSException::class);
@@ -2368,9 +2409,7 @@ class UsersControllerTest extends TestCase {
$this->assertEquals([], $this->api->editUser('UserToEdit', 'language', 'de')->getData());
}
- /**
- * @dataProvider dataEditUserSelfEditChangeLanguageButForced
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataEditUserSelfEditChangeLanguageButForced')]
public function testEditUserAdminEditChangeLanguageInvalidLanguage(): void {
$this->expectException(OCSException::class);
@@ -3796,6 +3835,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['getUserData'])
->getMock();
@@ -3887,6 +3927,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['getUserData'])
->getMock();
@@ -4356,9 +4397,7 @@ class UsersControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataGetEditableFields
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetEditableFields')]
public function testGetEditableFields(bool $allowedToChangeDisplayName, bool $allowedToChangeEmail, string $userBackend, array $expected): void {
$this->config->method('getSystemValue')->willReturnCallback(fn (string $key, mixed $default) => match ($key) {
'allow_user_to_change_display_name' => $allowedToChangeDisplayName,
@@ -4393,7 +4432,7 @@ class UsersControllerTest extends TestCase {
$account = $this->createMock(IAccount::class);
$account->method('getProperty')
- ->will($this->returnValueMap($mockedProperties));
+ ->willReturnMap($mockedProperties);
$this->accountManager->expects($this->any())->method('getAccount')
->with($targetUser)
diff --git a/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php b/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php
index d40aab90d66..c027e518a3d 100644
--- a/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php
+++ b/apps/provisioning_api/tests/Middleware/ProvisioningApiMiddlewareTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -43,9 +44,7 @@ class ProvisioningApiMiddlewareTest extends TestCase {
];
}
- /**
- * @dataProvider dataAnnotation
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAnnotation')]
public function testBeforeController(bool $subadminRequired, bool $isAdmin, bool $isSubAdmin, bool $hasSettingAuthorizationAnnotation, bool $shouldThrowException): void {
$middleware = new ProvisioningApiMiddleware(
$this->reflector,
@@ -82,9 +81,7 @@ class ProvisioningApiMiddlewareTest extends TestCase {
];
}
- /**
- * @dataProvider dataAfterException
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataAfterException')]
public function testAfterException(\Exception $exception, bool $forwared): void {
$middleware = new ProvisioningApiMiddleware(
$this->reflector,