aboutsummaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/tests/Controller/UsersControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/provisioning_api/tests/Controller/UsersControllerTest.php')
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php180
1 files changed, 70 insertions, 110 deletions
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php
index 7d4f99356b3..cf35a4fb324 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;
@@ -46,41 +47,25 @@ use RuntimeException;
use Test\TestCase;
class UsersControllerTest extends TestCase {
- /** @var IUserManager|MockObject */
- protected $userManager;
- /** @var IConfig|MockObject */
- protected $config;
- /** @var Manager|MockObject */
- protected $groupManager;
- /** @var IUserSession|MockObject */
- protected $userSession;
- /** @var LoggerInterface|MockObject */
- protected $logger;
- /** @var UsersController|MockObject */
- protected $api;
- /** @var IAccountManager|MockObject */
- protected $accountManager;
- /** @var ISubAdmin|MockObject */
- protected $subAdminManager;
- /** @var IURLGenerator|MockObject */
- protected $urlGenerator;
- /** @var IRequest|MockObject */
- protected $request;
- /** @var IFactory|MockObject */
- private $l10nFactory;
- /** @var NewUserMailHelper|MockObject */
- private $newUserMailHelper;
- /** @var ISecureRandom|MockObject */
- private $secureRandom;
- /** @var RemoteWipe|MockObject */
- private $remoteWipe;
- /** @var KnownUserService|MockObject */
- private $knownUserService;
- /** @var IEventDispatcher|MockObject */
- private $eventDispatcher;
+ protected IUserManager&MockObject $userManager;
+ protected IConfig&MockObject $config;
+ protected Manager&MockObject $groupManager;
+ protected IUserSession&MockObject $userSession;
+ protected LoggerInterface&MockObject $logger;
+ protected UsersController&MockObject $api;
+ protected IAccountManager&MockObject $accountManager;
+ protected ISubAdmin&MockObject $subAdminManager;
+ protected IURLGenerator&MockObject $urlGenerator;
+ protected IRequest&MockObject $request;
+ private IFactory&MockObject $l10nFactory;
+ private NewUserMailHelper&MockObject $newUserMailHelper;
+ private ISecureRandom&MockObject $secureRandom;
+ private RemoteWipe&MockObject $remoteWipe;
+ private KnownUserService&MockObject $knownUserService;
+ private IEventDispatcher&MockObject $eventDispatcher;
private IRootFolder $rootFolder;
- /** @var IPhoneNumberUtil */
- private $phoneNumberUtil;
+ private IPhoneNumberUtil $phoneNumberUtil;
+ private IAppManager $appManager;
protected function setUp(): void {
parent::setUp();
@@ -101,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);
@@ -127,6 +113,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['fillStorageInfo'])
->getMock();
@@ -212,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' => [
@@ -449,10 +435,6 @@ class UsersControllerTest extends TestCase {
$this->groupManager
->expects($this->exactly(2))
->method('groupExists')
- ->withConsecutive(
- ['ExistingGroup'],
- ['NonExistingGroup']
- )
->willReturnMap([
['ExistingGroup', true],
['NonExistingGroup', false]
@@ -522,6 +504,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['editUser'])
->getMock();
@@ -798,18 +781,20 @@ class UsersControllerTest extends TestCase {
->method('get')
->with('ExistingGroup')
->willReturn($group);
+
+ $calls = [
+ ['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']],
+ ['Added userid NewUser to group ExistingGroup', ['app' => 'ocs_api']],
+ ];
$this->logger
->expects($this->exactly(2))
->method('info')
- ->withConsecutive(
- ['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']],
- ['Added userid NewUser to group ExistingGroup', ['app' => 'ocs_api']]
- );
+ ->willReturnCallback(function () use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
- $this->assertTrue(key_exists(
- 'id',
- $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData()
- ));
+ $this->assertArrayHasKey('id', $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData());
}
@@ -828,7 +813,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')
@@ -966,11 +951,10 @@ class UsersControllerTest extends TestCase {
$this->groupManager
->expects($this->exactly(2))
->method('groupExists')
- ->withConsecutive(
- ['ExistingGroup1'],
- ['ExistingGroup2']
- )
- ->willReturn(true);
+ ->willReturnMap([
+ ['ExistingGroup1', true],
+ ['ExistingGroup2', true]
+ ]);
$user = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
->getMock();
@@ -996,24 +980,23 @@ class UsersControllerTest extends TestCase {
$this->groupManager
->expects($this->exactly(4))
->method('get')
- ->withConsecutive(
- ['ExistingGroup1'],
- ['ExistingGroup2'],
- ['ExistingGroup1'],
- ['ExistingGroup2']
- )
->willReturnMap([
['ExistingGroup1', $existingGroup1],
['ExistingGroup2', $existingGroup2]
]);
+
+ $calls = [
+ ['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']],
+ ['Added userid NewUser to group ExistingGroup1', ['app' => 'ocs_api']],
+ ['Added userid NewUser to group ExistingGroup2', ['app' => 'ocs_api']],
+ ];
$this->logger
->expects($this->exactly(3))
->method('info')
- ->withConsecutive(
- ['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']],
- ['Added userid NewUser to group ExistingGroup1', ['app' => 'ocs_api']],
- ['Added userid NewUser to group ExistingGroup2', ['app' => 'ocs_api']]
- );
+ ->willReturnCallback(function () use (&$calls): void {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
->disableOriginalConstructor()->getMock();
$this->groupManager
@@ -1023,16 +1006,12 @@ class UsersControllerTest extends TestCase {
$subAdminManager
->expects($this->exactly(2))
->method('isSubAdminOfGroup')
- ->withConsecutive(
- [$loggedInUser, $existingGroup1],
- [$loggedInUser, $existingGroup2]
- )
- ->willReturn(true);
+ ->willReturnMap([
+ [$loggedInUser, $existingGroup1, true],
+ [$loggedInUser, $existingGroup2, true],
+ ]);
- $this->assertTrue(key_exists(
- 'id',
- $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup1', 'ExistingGroup2'])->getData()
- ));
+ $this->assertArrayHasKey('id', $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup1', 'ExistingGroup2'])->getData());
}
@@ -1541,7 +1520,7 @@ class UsersControllerTest extends TestCase {
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
- public function dataSearchByPhoneNumbers(): array {
+ public static function dataSearchByPhoneNumbers(): array {
return [
'Invalid country' => ['Not a country code', ['12345' => ['NaN']], 400, null, null, []],
'No number to search' => ['DE', ['12345' => ['NaN']], 200, null, null, []],
@@ -1554,13 +1533,7 @@ class UsersControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataSearchByPhoneNumbers
- * @param string $location
- * @param array $search
- * @param int $status
- * @param array $expected
- */
+ #[\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);
@@ -1870,7 +1843,7 @@ class UsersControllerTest extends TestCase {
$this->api->editUser('UserToEdit', 'email', 'demo.org');
}
- public function selfEditChangePropertyProvider() {
+ public static function selfEditChangePropertyProvider(): array {
return [
[IAccountManager::PROPERTY_TWITTER, '@oldtwitter', '@newtwitter'],
[IAccountManager::PROPERTY_FEDIVERSE, '@oldFediverse@floss.social', '@newFediverse@floss.social'],
@@ -1886,9 +1859,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()
@@ -1964,9 +1935,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()
@@ -2294,16 +2263,14 @@ class UsersControllerTest extends TestCase {
$this->assertEquals([], $this->api->editUser('UserToEdit', 'language', 'de')->getData());
}
- public function dataEditUserSelfEditChangeLanguageButForced() {
+ public static function dataEditUserSelfEditChangeLanguageButForced(): array {
return [
['de'],
[true],
];
}
- /**
- * @dataProvider dataEditUserSelfEditChangeLanguageButForced
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataEditUserSelfEditChangeLanguageButForced')]
public function testEditUserSelfEditChangeLanguageButForced($forced): void {
$this->expectException(OCSException::class);
@@ -2397,9 +2364,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);
@@ -3825,6 +3790,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['getUserData'])
->getMock();
@@ -3916,6 +3882,7 @@ class UsersControllerTest extends TestCase {
$this->knownUserService,
$this->eventDispatcher,
$this->phoneNumberUtil,
+ $this->appManager,
])
->onlyMethods(['getUserData'])
->getMock();
@@ -3942,11 +3909,10 @@ class UsersControllerTest extends TestCase {
$api->expects($this->exactly(2))
->method('getUserData')
- ->withConsecutive(
- ['uid', false],
- ['currentuser', true],
- )
- ->willReturn($expected);
+ ->willReturnMap([
+ ['uid', false, $expected],
+ ['currentuser', true, $expected],
+ ]);
$this->assertSame($expected, $api->getUser('uid')->getData());
@@ -4263,7 +4229,7 @@ class UsersControllerTest extends TestCase {
}
- public function dataGetEditableFields() {
+ public static function dataGetEditableFields(): array {
return [
[false, true, ISetDisplayNameBackend::class, [
IAccountManager::PROPERTY_EMAIL,
@@ -4386,13 +4352,7 @@ class UsersControllerTest extends TestCase {
];
}
- /**
- * @dataProvider dataGetEditableFields
- *
- * @param bool $allowedToChangeDisplayName
- * @param string $userBackend
- * @param array $expected
- */
+ #[\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,
@@ -4427,7 +4387,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)