Add comments to tests for clarity
Add setUp and tearDown methods on tests
Add classes on history and popular sections
This commit is contained in:
xavier.guiboud-ribaud@combodo.com
2024-11-25 12:10:10 +01:00
parent 44fa08278d
commit b9ad9dcded
2 changed files with 23 additions and 8 deletions

View File

@@ -2,11 +2,22 @@
namespace Application\UI\Base\Components\QuickCreate;
use appUserPreferences;
use Combodo\iTop\Application\UI\Base\Component\QuickCreate\QuickCreateHelper;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
class QuickCreateHelperTest extends ItopDataTestCase
{
private array $aInitialUserPref = [];
protected function setUp(): void {
parent::setUp();
$this->aInitialUserPref = appUserPreferences::GetPref(QuickCreateHelper::USER_PREF_CODE, []);
}
protected function tearDown(): void{
parent::tearDown();
appUserPreferences::SetPref(QuickCreateHelper::USER_PREF_CODE, $this->aInitialUserPref);
}
/**
* Test class removal from popular when it is in recent classes
@@ -14,10 +25,12 @@ class QuickCreateHelperTest extends ItopDataTestCase
public function testNoDuplicateInPopularAndLast()
{
$aClasses = ['ApplicationSolution', 'BusinessProcess', 'DatabaseSchema', 'MiddlewareInstance', 'Enclosure'];
$aPopularClassesInitial = QuickCreateHelper::GetPopularClasses(); // Should contain the first Popular class (FunctionalCI if default)
// Should contain the first Popular class (FunctionalCI if default)
$aPopularClassesInitial = QuickCreateHelper::GetPopularClasses();
$sPopularClass = $aPopularClassesInitial[0]['class'];
QuickCreateHelper::AddClassToHistory($sPopularClass);
$aPopularClassNoParam = QuickCreateHelper::GetPopularClasses(); // Popular class should now be in Recents and no longer in Popular
// Popular class should now be in Recents and no longer in Popular
$aPopularClassNoParam = QuickCreateHelper::GetPopularClasses();
for($iIdx = 0; $iIdx < count($aPopularClassNoParam); $iIdx++)
{
@@ -36,9 +49,11 @@ class QuickCreateHelperTest extends ItopDataTestCase
foreach($aClasses as $sClass)
{
QuickCreateHelper::AddClassToHistory($sClass); // Creating as many classes as needed for UserRequest to no longer be in the Recent classes (at least equal to 'quick_create.max_history_results')
// Creating as many classes as needed for UserRequest to no longer be in the Recent classes (at least equal to 'quick_create.max_history_results')
QuickCreateHelper::AddClassToHistory($sClass);
}
$aPopularClassesFinal = QuickCreateHelper::GetPopularClasses(); // Should contain UserRequest
// Should contain the first Popular class (FunctionalCI if default)
$aPopularClassesFinal = QuickCreateHelper::GetPopularClasses();
$this->assertEquals($aPopularClassesInitial, $aPopularClassesFinal);
}
}