Skip to content

Commit

Permalink
test: Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Oct 9, 2024
1 parent 1dcdc87 commit 96035d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
10 changes: 5 additions & 5 deletions apps/provisioning_api/tests/Controller/GroupsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace OCA\Provisioning_API\Tests\Controller;

use OC\Group\Manager;
use OC\SubAdmin;
use OC\User\NoUserException;
use OCA\Provisioning_API\Controller\GroupsController;
use OCP\Accounts\IAccountManager;
use OCP\Group\ISubAdmin;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUser;
Expand All @@ -34,12 +34,12 @@ class GroupsControllerTest extends \Test\TestCase {
protected $userSession;
/** @var IAccountManager|\PHPUnit\Framework\MockObject\MockObject */
protected $accountManager;
/** @var ISubAdmin|\PHPUnit\Framework\MockObject\MockObject */
protected $subAdminManager;
/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
protected $l10nFactory;
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
protected $logger;
/** @var SubAdmin|\PHPUnit\Framework\MockObject\MockObject */
protected $subAdminManager;

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

$this->subAdminManager = $this->createMock(SubAdmin::class);

$this->groupManager
->method('getSubAdmin')
->willReturn($this->subAdminManager);
Expand All @@ -72,6 +71,7 @@ protected function setUp(): void {
$this->groupManager,
$this->userSession,
$this->accountManager,
$this->subAdminManager,
$this->l10nFactory,
$this->logger
])
Expand Down
20 changes: 8 additions & 12 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\ISubAdmin;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IL10N;
Expand Down Expand Up @@ -57,6 +58,8 @@ class UsersControllerTest extends TestCase {
protected $api;
/** @var IAccountManager|MockObject */
protected $accountManager;
/** @var ISubAdmin|MockObject */
protected $subAdminManager;
/** @var IURLGenerator|MockObject */
protected $urlGenerator;
/** @var IRequest|MockObject */
Expand Down Expand Up @@ -86,6 +89,7 @@ protected function setUp(): void {
$this->logger = $this->createMock(LoggerInterface::class);
$this->request = $this->createMock(IRequest::class);
$this->accountManager = $this->createMock(IAccountManager::class);
$this->subAdminManager = $this->createMock(ISubAdmin::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->newUserMailHelper = $this->createMock(NewUserMailHelper::class);
Expand All @@ -108,6 +112,7 @@ protected function setUp(): void {
$this->groupManager,
$this->userSession,
$this->accountManager,
$this->subAdminManager,
$this->l10nFactory,
$this->urlGenerator,
$this->logger,
Expand Down Expand Up @@ -376,6 +381,7 @@ public function testAddUserSuccessfulWithDisplayName(): void {
$this->groupManager,
$this->userSession,
$this->accountManager,
$this->subAdminManager,
$this->l10nFactory,
$this->urlGenerator,
$this->logger,
Expand Down Expand Up @@ -931,7 +937,6 @@ public function testGetUserDataAsAdmin(): void {
->disableOriginalConstructor()
->getMock();
$loggedInUser
->expects($this->exactly(2))
->method('getUID')
->willReturn('admin');
$targetUser = $this->getMockBuilder(IUser::class)
Expand All @@ -941,16 +946,13 @@ public function testGetUserDataAsAdmin(): void {
->method('getSystemEMailAddress')
->willReturn('[email protected]');
$this->userSession
->expects($this->once())
->method('getUser')
->willReturn($loggedInUser);
$this->userManager
->expects($this->exactly(2))
->method('get')
->with('UID')
->willReturn($targetUser);
$this->groupManager
->expects($this->once())
->method('isAdmin')
->with('admin')
->willReturn(true);
Expand Down Expand Up @@ -1079,7 +1081,6 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible(): void {
->disableOriginalConstructor()
->getMock();
$loggedInUser
->expects($this->exactly(2))
->method('getUID')
->willReturn('subadmin');
$targetUser = $this->getMockBuilder(IUser::class)
Expand All @@ -1090,16 +1091,13 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible(): void {
->method('getSystemEMailAddress')
->willReturn('[email protected]');
$this->userSession
->expects($this->once())
->method('getUser')
->willReturn($loggedInUser);
$this->userManager
->expects($this->exactly(2))
->method('get')
->with('UID')
->willReturn($targetUser);
$this->groupManager
->expects($this->once())
->method('isAdmin')
->with('subadmin')
->willReturn(false);
Expand Down Expand Up @@ -1267,23 +1265,19 @@ public function testGetUserDataAsSubAdminSelfLookup(): void {
->disableOriginalConstructor()
->getMock();
$loggedInUser
->expects($this->exactly(3))
->method('getUID')
->willReturn('UID');
$targetUser = $this->getMockBuilder(IUser::class)
->disableOriginalConstructor()
->getMock();
$this->userSession
->expects($this->once())
->method('getUser')
->willReturn($loggedInUser);
$this->userManager
->expects($this->exactly(2))
->method('get')
->with('UID')
->willReturn($targetUser);
$this->groupManager
->expects($this->once())
->method('isAdmin')
->with('UID')
->willReturn(false);
Expand Down Expand Up @@ -3667,6 +3661,7 @@ public function testGetCurrentUserLoggedIn(): void {
$this->groupManager,
$this->userSession,
$this->accountManager,
$this->subAdminManager,
$this->l10nFactory,
$this->urlGenerator,
$this->logger,
Expand Down Expand Up @@ -3756,6 +3751,7 @@ public function testGetUser(): void {
$this->groupManager,
$this->userSession,
$this->accountManager,
$this->subAdminManager,
$this->l10nFactory,
$this->urlGenerator,
$this->logger,
Expand Down

0 comments on commit 96035d2

Please sign in to comment.