Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rskrzypczak committed Nov 2, 2023
1 parent 384c4b6 commit 407561e
Showing 1 changed file with 49 additions and 45 deletions.
94 changes: 49 additions & 45 deletions tests/Settings/AutoAssign.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,47 @@ class AutoAssign extends \Tests\Base
*/
private static $autoAssign;

/**
* @codeCoverageIgnore
* Setting of tests.
*/
public static function setUpBeforeClass(): void
{
\App\User::setCurrentUserId(\App\User::getActiveAdminId());
self::$users['assignUserNo'] = self::createUserRecord('assignUserNo');
self::$users['assignUserYes'] = self::createUserRecord('assignUserYes', ['available' => '1', 'auto_assign' => '1']);
self::$users['assignUserYes2'] = self::createUserRecord('assignUserYes2', ['available' => '1', 'auto_assign' => '1']);
self::$defaultUser = self::createUserRecord('assignUserDefault');

self::$autoAssignUsers = array_filter(array_map(fn ($userModel) => $userModel->get('auto_assign') ? $userModel->getId() : null, self::$users));

$members = array_map(fn ($userModel) => \App\PrivilegeUtil::MEMBER_TYPE_USERS . ':' . $userModel->getId(), self::$users);

$recordModel = \Settings_Groups_Record_Model::getCleanInstance();
$recordModel->set('groupname', 'Support groups');
$recordModel->set('description', 'Test description');
$recordModel->set('members', $recordModel->getFieldInstanceByName('members')->getDBValue($members));
$recordModel->set('modules', $recordModel->getFieldInstanceByName('modules')->getDBValue([\App\Module::getModuleId('HelpDesk')]));
$recordModel->save();
self::$groupId = $recordModel->getId();
}

/**
* Cleaning after tests.
*
* @return void
*/
public static function tearDownAfterClass(): void
{
foreach (self::$tickets as $recordModel) {
$recordModel->delete();
}
foreach (self::$users as $recordModel) {
\Users_Record_Model::deleteUserPermanently($recordModel->getId(), \App\User::getCurrentUserId());
}
\Users_Record_Model::deleteUserPermanently(self::$defaultUser->getId(), \App\User::getCurrentUserId());
}

/**
* Create user.
*
Expand Down Expand Up @@ -103,35 +144,6 @@ public static function createTicket(int $owner): \Vtiger_Record_Model
return $recordModel;
}

/**
* @codeCoverageIgnore
* Setting of tests.
*/
public static function setUpBeforeClass(): void
{
\App\User::setCurrentUserId(\App\User::getActiveAdminId());
self::$users['assignUserNo'] = self::createUserRecord('assignUserNo');
self::$users['assignUserYes'] = self::createUserRecord('assignUserYes', ['available' => '1', 'auto_assign' => '1']);
self::$users['assignUserYes2'] = self::createUserRecord('assignUserYes2', ['available' => '1', 'auto_assign' => '1']);
self::$defaultUser = self::createUserRecord('assignUserDefault');

self::$autoAssignUsers = array_filter(array_map(function ($userModel) {
return $userModel->get('auto_assign') ? $userModel->getId() : null;
}, self::$users));

$members = array_map(function ($userModel) {
return \App\PrivilegeUtil::MEMBER_TYPE_USERS . ':' . $userModel->getId();
}, self::$users);

$recordModel = \Settings_Groups_Record_Model::getCleanInstance();
$recordModel->set('groupname', 'Support groups');
$recordModel->set('description', 'Test description');
$recordModel->set('members', $recordModel->getFieldInstanceByName('members')->getDBValue($members));
$recordModel->set('modules', $recordModel->getFieldInstanceByName('modules')->getDBValue([\App\Module::getModuleId('HelpDesk')]));
$recordModel->save();
self::$groupId = $recordModel->getId();
}

/**
* Testing create auto assign record.
*/
Expand Down Expand Up @@ -170,6 +182,10 @@ public function testCreate()
*/
public function testHandler()
{
if (!\App\YetiForce\Shop::check('YetiForceAutoAssignment')) {
$this->markTestSkipped('No required access to test this functionality');
return;
}
$recordModel = self::createTicket(self::$groupId);
$owner = $recordModel->get('assigned_user_id');
$possibleOwners = self::$autoAssignUsers;
Expand Down Expand Up @@ -209,6 +225,10 @@ public function testUpdate()
*/
public function testRoundRobin()
{
if (!\App\YetiForce\Shop::check('YetiForceAutoAssignment')) {
$this->markTestSkipped('No required access to test this functionality');
return;
}
$assigned = [];
for ($i = 0; $i < \count(self::$autoAssignUsers); ++$i) {
$recordModel = self::createTicket(self::$groupId);
Expand Down Expand Up @@ -239,20 +259,4 @@ public function testDelete()
$handlers = (new \App\EventHandler())->setModuleName('HelpDesk')->getHandlers('EntityBeforeSave');
$this->assertFalse(isset($handlers['Vtiger_AutoAssign_Handler']), 'The handler should not be active');
}

/**
* Cleaning after tests.
*
* @return void
*/
public static function tearDownAfterClass(): void
{
foreach (self::$tickets as $recordModel) {
$recordModel->delete();
}
foreach (self::$users as $recordModel) {
\Users_Record_Model::deleteUserPermanently($recordModel->getId(), \App\User::getCurrentUserId());
}
\Users_Record_Model::deleteUserPermanently(self::$defaultUser->getId(), \App\User::getCurrentUserId());
}
}

0 comments on commit 407561e

Please sign in to comment.