From ba54cae217e45c39f3b4e052269a1dad93de6d39 Mon Sep 17 00:00:00 2001 From: jf-cbd Date: Wed, 10 Jun 2026 15:34:49 +0200 Subject: [PATCH] Check if class UserToken exists --- sources/Users/ITopUserCountingRepository.php | 5 ++++- .../Users/ITopUserCountingRepositoryTest.php | 17 ++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/sources/Users/ITopUserCountingRepository.php b/sources/Users/ITopUserCountingRepository.php index e2356b9047..ccf6fece17 100644 --- a/sources/Users/ITopUserCountingRepository.php +++ b/sources/Users/ITopUserCountingRepository.php @@ -159,8 +159,11 @@ class ITopUserCountingRepository /** * @throws Exception */ - public function GetApplicationUsers(bool $bAllData = true): array + public function GetApplicationUsers(bool $bAllData = true): ?array { + if (!MetaModel::IsValidClass('UserToken')) { + return null; + } $sOQLApplicationUser = 'SELECT UserToken'; try { $oFilter = $bAllData ? DBObjectSearch::FromOQL_AllData($sOQLApplicationUser) : DBObjectSearch::FromOQL($sOQLApplicationUser); diff --git a/tests/php-unit-tests/unitary-tests/sources/Users/ITopUserCountingRepositoryTest.php b/tests/php-unit-tests/unitary-tests/sources/Users/ITopUserCountingRepositoryTest.php index 88417e52b7..117296c5b1 100644 --- a/tests/php-unit-tests/unitary-tests/sources/Users/ITopUserCountingRepositoryTest.php +++ b/tests/php-unit-tests/unitary-tests/sources/Users/ITopUserCountingRepositoryTest.php @@ -4,6 +4,7 @@ namespace Users; use Combodo\iTop\Test\UnitTest\ItopDataTestCase; use Combodo\iTop\Users\ITopUserCountingRepository; +use MetaModel; use User; class ITopUserCountingRepositoryTest extends ItopDataTestCase @@ -14,7 +15,9 @@ class ITopUserCountingRepositoryTest extends ItopDataTestCase $this->CreateReadOnlyUsers(); $this->CreateDisabledUsers(); $this->CreatePortalUsers(); - $this->CreateTokenUsers(); + if (MetaModel::IsValidClass('UserToken')) { + $this->CreateTokenUsers(); + } $this->CreateConsoleUsers(); $this->CreateBusinessPartnerUser(); @@ -220,23 +223,23 @@ class ITopUserCountingRepositoryTest extends ItopDataTestCase public function RealUseCasesDataProvider() { return [ - [ + 'User with profiles Support Agent and Configuration ReadOnly' => [ 'profiles' => ['Support Agent', 'Configuration ReadOnly'], 'expected category' => 'console', ], - [ + 'User with profiles Configuration ReadOnly and Service Catalog ReadOnly' => [ 'profiles' => ['Configuration ReadOnly', 'Service Catalog ReadOnly'], 'expected category' => 'readonly', ], - [[ - 'profiles' => 'Portal user', 'Service Catalog ReadOnly'], + 'User with profiles Portal user and Service Catalog ReadOnly' => [ + 'profiles' => ['Portal user', 'Service Catalog ReadOnly'], 'expected category' => 'portal', ], - [ + 'User with profiles Support Agent and Portal user' => [ 'profiles' => ['Support Agent', 'Portal user'], 'expected category' => 'portal', ], - [ + 'User with profiles Configuration Manager and Ticket ReadOnly' => [ 'profiles' => ['Configuration Manager', 'Ticket ReadOnly'], 'expected category' => 'console', ],