Skip to content

Commit 96035d2

Browse files
committed
test: Fix tests
Signed-off-by: Christopher Ng <chrng8@gmail.com>
1 parent 1dcdc87 commit 96035d2

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

apps/provisioning_api/tests/Controller/GroupsControllerTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
namespace OCA\Provisioning_API\Tests\Controller;
99

1010
use OC\Group\Manager;
11-
use OC\SubAdmin;
1211
use OC\User\NoUserException;
1312
use OCA\Provisioning_API\Controller\GroupsController;
1413
use OCP\Accounts\IAccountManager;
14+
use OCP\Group\ISubAdmin;
1515
use OCP\IConfig;
1616
use OCP\IRequest;
1717
use OCP\IUser;
@@ -34,12 +34,12 @@ class GroupsControllerTest extends \Test\TestCase {
3434
protected $userSession;
3535
/** @var IAccountManager|\PHPUnit\Framework\MockObject\MockObject */
3636
protected $accountManager;
37+
/** @var ISubAdmin|\PHPUnit\Framework\MockObject\MockObject */
38+
protected $subAdminManager;
3739
/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
3840
protected $l10nFactory;
3941
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
4042
protected $logger;
41-
/** @var SubAdmin|\PHPUnit\Framework\MockObject\MockObject */
42-
protected $subAdminManager;
4343

4444
/** @var GroupsController|\PHPUnit\Framework\MockObject\MockObject */
4545
protected $api;
@@ -54,11 +54,10 @@ protected function setUp(): void {
5454
$this->groupManager = $this->createMock(Manager::class);
5555
$this->userSession = $this->createMock(IUserSession::class);
5656
$this->accountManager = $this->createMock(IAccountManager::class);
57+
$this->subAdminManager = $this->createMock(ISubAdmin::class);
5758
$this->l10nFactory = $this->createMock(IFactory::class);
5859
$this->logger = $this->createMock(LoggerInterface::class);
5960

60-
$this->subAdminManager = $this->createMock(SubAdmin::class);
61-
6261
$this->groupManager
6362
->method('getSubAdmin')
6463
->willReturn($this->subAdminManager);
@@ -72,6 +71,7 @@ protected function setUp(): void {
7271
$this->groupManager,
7372
$this->userSession,
7473
$this->accountManager,
74+
$this->subAdminManager,
7575
$this->l10nFactory,
7676
$this->logger
7777
])

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use OCP\AppFramework\Http\DataResponse;
2424
use OCP\AppFramework\OCS\OCSException;
2525
use OCP\EventDispatcher\IEventDispatcher;
26+
use OCP\Group\ISubAdmin;
2627
use OCP\IConfig;
2728
use OCP\IGroup;
2829
use OCP\IL10N;
@@ -57,6 +58,8 @@ class UsersControllerTest extends TestCase {
5758
protected $api;
5859
/** @var IAccountManager|MockObject */
5960
protected $accountManager;
61+
/** @var ISubAdmin|MockObject */
62+
protected $subAdminManager;
6063
/** @var IURLGenerator|MockObject */
6164
protected $urlGenerator;
6265
/** @var IRequest|MockObject */
@@ -86,6 +89,7 @@ protected function setUp(): void {
8689
$this->logger = $this->createMock(LoggerInterface::class);
8790
$this->request = $this->createMock(IRequest::class);
8891
$this->accountManager = $this->createMock(IAccountManager::class);
92+
$this->subAdminManager = $this->createMock(ISubAdmin::class);
8993
$this->urlGenerator = $this->createMock(IURLGenerator::class);
9094
$this->l10nFactory = $this->createMock(IFactory::class);
9195
$this->newUserMailHelper = $this->createMock(NewUserMailHelper::class);
@@ -108,6 +112,7 @@ protected function setUp(): void {
108112
$this->groupManager,
109113
$this->userSession,
110114
$this->accountManager,
115+
$this->subAdminManager,
111116
$this->l10nFactory,
112117
$this->urlGenerator,
113118
$this->logger,
@@ -376,6 +381,7 @@ public function testAddUserSuccessfulWithDisplayName(): void {
376381
$this->groupManager,
377382
$this->userSession,
378383
$this->accountManager,
384+
$this->subAdminManager,
379385
$this->l10nFactory,
380386
$this->urlGenerator,
381387
$this->logger,
@@ -931,7 +937,6 @@ public function testGetUserDataAsAdmin(): void {
931937
->disableOriginalConstructor()
932938
->getMock();
933939
$loggedInUser
934-
->expects($this->exactly(2))
935940
->method('getUID')
936941
->willReturn('admin');
937942
$targetUser = $this->getMockBuilder(IUser::class)
@@ -941,16 +946,13 @@ public function testGetUserDataAsAdmin(): void {
941946
->method('getSystemEMailAddress')
942947
->willReturn('demo@nextcloud.com');
943948
$this->userSession
944-
->expects($this->once())
945949
->method('getUser')
946950
->willReturn($loggedInUser);
947951
$this->userManager
948-
->expects($this->exactly(2))
949952
->method('get')
950953
->with('UID')
951954
->willReturn($targetUser);
952955
$this->groupManager
953-
->expects($this->once())
954956
->method('isAdmin')
955957
->with('admin')
956958
->willReturn(true);
@@ -1079,7 +1081,6 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible(): void {
10791081
->disableOriginalConstructor()
10801082
->getMock();
10811083
$loggedInUser
1082-
->expects($this->exactly(2))
10831084
->method('getUID')
10841085
->willReturn('subadmin');
10851086
$targetUser = $this->getMockBuilder(IUser::class)
@@ -1090,16 +1091,13 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible(): void {
10901091
->method('getSystemEMailAddress')
10911092
->willReturn('demo@nextcloud.com');
10921093
$this->userSession
1093-
->expects($this->once())
10941094
->method('getUser')
10951095
->willReturn($loggedInUser);
10961096
$this->userManager
1097-
->expects($this->exactly(2))
10981097
->method('get')
10991098
->with('UID')
11001099
->willReturn($targetUser);
11011100
$this->groupManager
1102-
->expects($this->once())
11031101
->method('isAdmin')
11041102
->with('subadmin')
11051103
->willReturn(false);
@@ -1267,23 +1265,19 @@ public function testGetUserDataAsSubAdminSelfLookup(): void {
12671265
->disableOriginalConstructor()
12681266
->getMock();
12691267
$loggedInUser
1270-
->expects($this->exactly(3))
12711268
->method('getUID')
12721269
->willReturn('UID');
12731270
$targetUser = $this->getMockBuilder(IUser::class)
12741271
->disableOriginalConstructor()
12751272
->getMock();
12761273
$this->userSession
1277-
->expects($this->once())
12781274
->method('getUser')
12791275
->willReturn($loggedInUser);
12801276
$this->userManager
1281-
->expects($this->exactly(2))
12821277
->method('get')
12831278
->with('UID')
12841279
->willReturn($targetUser);
12851280
$this->groupManager
1286-
->expects($this->once())
12871281
->method('isAdmin')
12881282
->with('UID')
12891283
->willReturn(false);
@@ -3667,6 +3661,7 @@ public function testGetCurrentUserLoggedIn(): void {
36673661
$this->groupManager,
36683662
$this->userSession,
36693663
$this->accountManager,
3664+
$this->subAdminManager,
36703665
$this->l10nFactory,
36713666
$this->urlGenerator,
36723667
$this->logger,
@@ -3756,6 +3751,7 @@ public function testGetUser(): void {
37563751
$this->groupManager,
37573752
$this->userSession,
37583753
$this->accountManager,
3754+
$this->subAdminManager,
37593755
$this->l10nFactory,
37603756
$this->urlGenerator,
37613757
$this->logger,

0 commit comments

Comments
 (0)