mirror of
https://github.com/Combodo/iTop.git
synced 2026-07-10 16:56:40 +02:00
WIP
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Users;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use Combodo\iTop\Users\ITopUserCountingRepository;
|
||||
use User;
|
||||
|
||||
class ITopUserCountingRepositoryTest extends ItopDataTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->CreateReadOnlyUsers();
|
||||
|
||||
}
|
||||
|
||||
private function CreateReadOnlyUsers()
|
||||
{
|
||||
$this->GivenUserInDB('qpf_z17H3232*"ré$"é', ['Configuration ReadOnly']);
|
||||
$this->GivenUserInDB('qpf_z17H3232*"ré$"é', ['Ticket ReadOnly']);
|
||||
$this->GivenUserInDB('qpf_z17H3232*"ré$"é', ['Service Catalog ReadOnly']);
|
||||
$this->GivenUserInDB('qpf_z17H3232*"ré$"é', ['Configuration ReadOnly', 'Ticket ReadOnly']);
|
||||
$this->GivenUserInDB('qpf_z17H3232*"ré$"é', ['Ticket ReadOnly', 'Service Catalog ReadOnly']);
|
||||
$this->GivenUserInDB('qpf_z17H3232*"ré$"é', ['Configuration ReadOnly', 'Ticket ReadOnly', 'Service Catalog ReadOnly']);
|
||||
}
|
||||
|
||||
private function CreateDisabledUser()
|
||||
{
|
||||
$sUser = $this->GivenUserInDB('qpf_z17H3232*"ré$"é', ['Configuration Manager']);
|
||||
// get user by login
|
||||
$oUser = \MetaModel::GetObjectByName('User', $sUser);
|
||||
$oUser->Set('status', 'disabled');
|
||||
$oUser->DBUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \CoreUnexpectedValue
|
||||
* @throws \DictExceptionMissingString
|
||||
* @throws \CoreException
|
||||
* @throws \MySQLException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testNotDuplicateInDifferentCountsCategories(): void
|
||||
{
|
||||
$oITopUserRepository = new ITopUserCountingRepository();
|
||||
|
||||
$aCountedUsers = [
|
||||
'console' => $oITopUserRepository->GetConsoleUsers(),
|
||||
'portal' => $oITopUserRepository->GetPortalUsers(),
|
||||
'disabled' => $oITopUserRepository->GetDisabledUsers(),
|
||||
'readonly' => $oITopUserRepository->GetReadOnlyUsers(),
|
||||
'application' => $oITopUserRepository->GetApplicationUsers(),
|
||||
];
|
||||
|
||||
$aCountedUserFormated = [];
|
||||
foreach ($aCountedUsers as $sCountedCategory => $aUsers) {
|
||||
foreach ($aUsers as $oUser) {
|
||||
$sUserId = (string) $oUser->GetKey();
|
||||
$aCountedUserFormated[$sUserId][$sCountedCategory] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$aDuplicates = [];
|
||||
foreach ($aCountedUserFormated as $sUserId => $aCountedCategory) {
|
||||
$aCountedCategoryName = array_keys($aCountedCategory);
|
||||
if (count($aCountedCategoryName) > 1) {
|
||||
sort($aCountedCategoryName);
|
||||
$aDuplicates[] = sprintf('User #%s appears in: %s', $sUserId, implode(', ', $aCountedCategoryName));
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEmpty(
|
||||
$aDuplicates,
|
||||
"Some users are counted in multiple categories:\n- ".implode("\n- ", $aDuplicates)
|
||||
);
|
||||
}
|
||||
|
||||
public function testAllUsersAreCounted()
|
||||
{
|
||||
$oITopUserRepository = new ITopUserCountingRepository();
|
||||
|
||||
$aConsoleUsers = $oITopUserRepository->GetConsoleUsers();
|
||||
$aPortalUsers = $oITopUserRepository->GetPortalUsers();
|
||||
$aDisabledUsers = $oITopUserRepository->GetDisabledUsers();
|
||||
$aReadOnlyUsers = $oITopUserRepository->GetReadOnlyUsers();
|
||||
$aApplicationUsers = $oITopUserRepository->GetApplicationUsers();
|
||||
|
||||
$aAllUsersFromMergedCounts = array_merge($aConsoleUsers, $aPortalUsers, $aDisabledUsers, $aReadOnlyUsers, $aApplicationUsers);
|
||||
|
||||
$aAllUsersFromOQL = $oITopUserRepository->GetAllUsers();
|
||||
|
||||
$this->assertEmpty(array_merge(array_diff($aAllUsersFromMergedCounts, $aAllUsersFromOQL), array_diff($aAllUsersFromOQL, $aAllUsersFromMergedCounts)));
|
||||
}
|
||||
|
||||
public function testAllCountedUsersAreUsersObjects()
|
||||
{
|
||||
$oITopUserRepository = new ITopUserCountingRepository();
|
||||
|
||||
$aConsoleUsers = $oITopUserRepository->GetConsoleUsers();
|
||||
$aPortalUsers = $oITopUserRepository->GetPortalUsers();
|
||||
$aDisabledUsers = $oITopUserRepository->GetDisabledUsers();
|
||||
$aReadOnlyUsers = $oITopUserRepository->GetReadOnlyUsers();
|
||||
$aApplicationUsers = $oITopUserRepository->GetApplicationUsers();
|
||||
|
||||
$aCountedUsers = array_merge($aConsoleUsers, $aPortalUsers, $aDisabledUsers, $aReadOnlyUsers, $aApplicationUsers);
|
||||
|
||||
foreach ($aCountedUsers as $oUser) {
|
||||
$this->assertInstanceOf(User::class, $oUser);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user