Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit ldap user count #50171

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore(tests): Adapt tests to the countUsers refactor
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Jan 14, 2025
commit db94aeb96ebaa91f66af4b1a08f5c7bb0933552c
115 changes: 6 additions & 109 deletions apps/updatenotification/tests/Settings/AdminTest.php
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@
*/
namespace OCA\UpdateNotification\Tests\Settings;

use OC\User\Backend;
use OCA\UpdateNotification\Settings\Admin;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse;
@@ -22,8 +21,6 @@
use OCP\L10N\IFactory;
use OCP\L10N\ILanguageIterator;
use OCP\Support\Subscription\IRegistry;
use OCP\User\Backend\ICountUsersBackend;
use OCP\UserInterface;
use OCP\Util;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@@ -81,42 +78,10 @@ protected function setUp(): void {
}

public function testGetFormWithUpdate(): void {
$backend1 = $this->createMock(CountUsersBackend::class);
$backend2 = $this->createMock(CountUsersBackend::class);
$backend3 = $this->createMock(CountUsersBackend::class);
$backend1
->expects($this->once())
->method('implementsActions')
->with(Backend::COUNT_USERS)
->willReturn(false);
$backend2
->expects($this->once())
->method('implementsActions')
->with(Backend::COUNT_USERS)
->willReturn(true);
$backend3
->expects($this->once())
->method('implementsActions')
->with(Backend::COUNT_USERS)
->willReturn(true);
$backend1
->expects($this->never())
->method('countUsers');
$backend2
->expects($this->once())
->method('countUsers')
->with()
->willReturn(false);
$backend3
->expects($this->once())
->method('countUsers')
->with()
->willReturn(5);
$this->userManager
->expects($this->once())
->method('getBackends')
->with()
->willReturn([$backend1, $backend2, $backend3]);
->method('countUsersTotal')
->willReturn(5);
$channels = [
'daily',
'beta',
@@ -207,42 +172,10 @@ public function testGetFormWithUpdate(): void {
}

public function testGetFormWithUpdateAndChangedUpdateServer(): void {
$backend1 = $this->createMock(CountUsersBackend::class);
$backend2 = $this->createMock(CountUsersBackend::class);
$backend3 = $this->createMock(CountUsersBackend::class);
$backend1
->expects($this->once())
->method('implementsActions')
->with(Backend::COUNT_USERS)
->willReturn(false);
$backend2
->expects($this->once())
->method('implementsActions')
->with(Backend::COUNT_USERS)
->willReturn(true);
$backend3
->expects($this->once())
->method('implementsActions')
->with(Backend::COUNT_USERS)
->willReturn(true);
$backend1
->expects($this->never())
->method('countUsers');
$backend2
->expects($this->once())
->method('countUsers')
->with()
->willReturn(false);
$backend3
->expects($this->once())
->method('countUsers')
->with()
->willReturn(5);
$this->userManager
->expects($this->once())
->method('getBackends')
->with()
->willReturn([$backend1, $backend2, $backend3]);
->method('countUsersTotal')
->willReturn(5);
$channels = [
'daily',
'beta',
@@ -334,42 +267,10 @@ public function testGetFormWithUpdateAndChangedUpdateServer(): void {
}

public function testGetFormWithUpdateAndCustomersUpdateServer(): void {
$backend1 = $this->createMock(CountUsersBackend::class);
$backend2 = $this->createMock(CountUsersBackend::class);
$backend3 = $this->createMock(CountUsersBackend::class);
$backend1
->expects($this->once())
->method('implementsActions')
->with(Backend::COUNT_USERS)
->willReturn(false);
$backend2
->expects($this->once())
->method('implementsActions')
->with(Backend::COUNT_USERS)
->willReturn(true);
$backend3
->expects($this->once())
->method('implementsActions')
->with(Backend::COUNT_USERS)
->willReturn(true);
$backend1
->expects($this->never())
->method('countUsers');
$backend2
->expects($this->once())
->method('countUsers')
->with()
->willReturn(false);
$backend3
->expects($this->once())
->method('countUsers')
->with()
->willReturn(5);
$this->userManager
->expects($this->once())
->method('getBackends')
->with()
->willReturn([$backend1, $backend2, $backend3]);
->method('countUsersTotal')
->willReturn(5);
$channels = [
'daily',
'beta',
@@ -543,7 +444,3 @@ public function testFilterChanges($changes, $userLang, $expectation): void {
$this->assertSame($expectation, $result);
}
}

abstract class CountUsersBackend implements UserInterface, ICountUsersBackend {

}
41 changes: 9 additions & 32 deletions tests/lib/Support/Subscription/RegistryTest.php
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@
namespace Test\Support\Subscription;

use OC\Support\Subscription\Registry;
use OC\User\Database;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
@@ -17,33 +16,19 @@
use OCP\Notification\IManager;
use OCP\Support\Subscription\ISubscription;
use OCP\Support\Subscription\ISupportedApps;
use OCP\User\Backend\ICountUsersBackend;
use OCP\UserInterface;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Test\TestCase;

class RegistryTest extends TestCase {
/** @var Registry */
private $registry;
private Registry $registry;

/** @var MockObject|IConfig */
private $config;

/** @var MockObject|IServerContainer */
private $serverContainer;

/** @var MockObject|IUserManager */
private $userManager;

/** @var MockObject|IGroupManager */
private $groupManager;

/** @var MockObject|LoggerInterface */
private $logger;

/** @var MockObject|IManager */
private $notificationManager;
private MockObject&IConfig $config;
private MockObject&IServerContainer $serverContainer;
private MockObject&IUserManager $userManager;
private MockObject&IGroupManager $groupManager;
private MockObject&LoggerInterface $logger;
private MockObject&IManager $notificationManager;

protected function setUp(): void {
parent::setUp();
@@ -198,17 +183,9 @@ public function testDelegateIsHardUserLimitReachedWithoutSupportAppAndUserCount(
->method('getUsersForUserValue')
->with('core', 'enabled', 'false')
->willReturn(array_fill(0, $disabledUsers, ''));
/* @var UserInterface|ICountUsersBackend|\PHPUnit\Framework\MockObject\MockObject $dummyBackend */
$dummyBackend = $this->createMock(Database::class);
$dummyBackend->expects($this->once())
->method('implementsActions')
->willReturn(true);
$dummyBackend->expects($this->once())
->method('countUsers')
->willReturn($userCount);
$this->userManager->expects($this->once())
->method('getBackends')
->willReturn([$dummyBackend]);
->method('countUsersTotal')
->willReturn($userCount);

if ($expectedResult) {
$dummyGroup = $this->createMock(IGroup::class);
Loading