mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Merge branch 'support/3.2' into develop
# Conflicts: # core/attributedef.class.inc.php # datamodels/2.x/version.xml # tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php # tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php
This commit is contained in:
@@ -6464,6 +6464,7 @@ class AttributeDateTime extends AttributeDBField
|
||||
$sDefaultDate = Expression::FromOQL('"'.$sDefaultValue.'"')->Evaluate([]);
|
||||
} catch (Exception $e) {
|
||||
IssueLog::Error("Invalid default value '$sDefaultValue' for field '{$this->GetCode()}' on class '{$this->GetHostClass()}', defaulting to null");
|
||||
|
||||
return $this->GetNullValue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ class NavigationMenu extends UIBlock implements iKeyboardShortcut
|
||||
<<<JS
|
||||
$sPageJS
|
||||
$sPageReadyJS
|
||||
$(window).on('load', function() {
|
||||
$(document).ready(function() {
|
||||
$('[data-role="ibo-navigation-menu--silo-selection--form"] #org_id').on('extkeychange', function() {
|
||||
$('[data-role="ibo-navigation-menu--silo-selection--form"]').submit();
|
||||
});
|
||||
|
||||
@@ -22,6 +22,7 @@ class InterfaceDiscovery
|
||||
private static InterfaceDiscovery $oInstance;
|
||||
private DataModelDependantCache $oCacheService;
|
||||
private ?array $aForcedClassMap = null; // For testing purposes
|
||||
private bool $bCheckInterfaceImplementation = true; // false only for testing purposes
|
||||
|
||||
const CACHE_NONE = 'CACHE_NONE';
|
||||
const CACHE_DYNAMIC = 'CACHE_DYNAMIC'; // rebuild cache when files changes
|
||||
@@ -86,9 +87,15 @@ class InterfaceDiscovery
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->IsInterfaceImplementation($sPHPClass, $sInterface)) {
|
||||
$aMatchingClasses[] = $sPHPClass;
|
||||
if ($this->bCheckInterfaceImplementation && ! $this->IsInterfaceImplementation($sPHPClass, $sInterface)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (! class_exists($sPHPClass)){
|
||||
continue;
|
||||
}
|
||||
|
||||
$aMatchingClasses[] = $sPHPClass;
|
||||
}
|
||||
|
||||
if ($this->GetCacheMode() !== self::CACHE_NONE) {
|
||||
@@ -241,7 +248,17 @@ class InterfaceDiscovery
|
||||
|
||||
public function ReadClassesFromCache(string $sKey): array
|
||||
{
|
||||
return $this->oCacheService->Fetch('InterfaceDiscovery', $sKey);
|
||||
$aClasses = $this->oCacheService->Fetch('InterfaceDiscovery', $sKey);
|
||||
|
||||
$aRealClasses = [];
|
||||
foreach ($aClasses as $sPHPClass){
|
||||
if (! class_exists($sPHPClass)){
|
||||
continue;
|
||||
}
|
||||
|
||||
$aRealClasses[]=$sPHPClass;
|
||||
}
|
||||
return $aRealClasses;
|
||||
}
|
||||
|
||||
protected function SaveClassesToCache(string $sKey, array $aMatchingClasses, array $aMoreInfo): void
|
||||
|
||||
@@ -992,6 +992,14 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
}
|
||||
}
|
||||
|
||||
protected function AssertLastErrorLogEntryContains(string $sNeedle, string $sMessage = ''): void
|
||||
{
|
||||
$aLastLines = self::ReadTail(APPROOT.'/log/error.log');
|
||||
$this->assertStringContainsString($sNeedle, $aLastLines[0], $sMessage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Import a set of XML files describing a consistent set of iTop objects
|
||||
* @param string[] $aFiles
|
||||
|
||||
@@ -557,10 +557,8 @@ abstract class ItopTestCase extends TestCase
|
||||
static protected function AssertDateEqualsNow($sActualDate, $sMessage = ''): void
|
||||
{
|
||||
$oActualDate = \DateTime::createFromFormat(\AttributeDate::GetInternalFormat(), $sActualDate);
|
||||
$oNow = new DateTime();
|
||||
|
||||
$oNow = new \DateTime();
|
||||
$iTimeInterval = $oNow->diff($oActualDate)->s;
|
||||
|
||||
self::assertLessThan(2, $iTimeInterval, $sMessage);
|
||||
}
|
||||
/**
|
||||
@@ -569,10 +567,8 @@ abstract class ItopTestCase extends TestCase
|
||||
static protected function AssertDateTimeEqualsNow($sActualDate, $sMessage = ''): void
|
||||
{
|
||||
$oActualDateTime = \DateTime::createFromFormat(\AttributeDateTime::GetInternalFormat(), $sActualDate);
|
||||
$oNow = new DateTime();
|
||||
|
||||
$oNow = new \DateTime();
|
||||
$iTimeInterval = $oNow->diff($oActualDateTime)->s;
|
||||
|
||||
self::assertLessThan(2, $iTimeInterval, $sMessage);
|
||||
}
|
||||
|
||||
|
||||
@@ -273,12 +273,13 @@ PHP
|
||||
{
|
||||
$oDateAttribute = $this->GivenAttribute(\WorkOrder::class, 'start_date', AttributeDate::class, 'zabugomeuh', false);
|
||||
|
||||
$defaultValue = $oDateAttribute->GetDefaultValue();
|
||||
|
||||
$defaultValue = $oDateAttribute->GetDefaultValue()
|
||||
self::AssertLastErrorLogEntryContains("Invalid default value 'zabugomeuh' for field 'start_date' on class 'WorkOrder', defaulting to null", "Last error log entry should contain a meaningful message");
|
||||
|
||||
self::assertNull($defaultValue, 'Invalid default value for Date attribute should give null default value');
|
||||
}
|
||||
|
||||
|
||||
public function testDateInvalidDefaultReturnsNullAsDefaultValue_Case2()
|
||||
{
|
||||
$oDateAttribute = $this->GivenAttribute(\WorkOrder::class, 'start_date', AttributeDate::class, '"27/01/2025"', false);
|
||||
@@ -292,18 +293,18 @@ PHP
|
||||
public function testDateTimeNowAsDefaultGivesCurrentDateAsDefaultValue()
|
||||
{
|
||||
$oDateAttribute = $this->GivenAttribute(\WorkOrder::class, 'start_date', AttributeDateTime::class, 'NOW()', false);
|
||||
|
||||
$sDefaultValue = $oDateAttribute->GetDefaultValue();
|
||||
|
||||
self::AssertDateTimeEqualsNow($sDefaultValue, 'NOW() should be evaluated as the current date and time');
|
||||
}
|
||||
|
||||
public function testDateNowAsDefaultGivesCurrentDateAsDefaultValue()
|
||||
{
|
||||
$oDateAttribute = $this->GivenAttribute(\WorkOrder::class, 'start_date', AttributeDate::class, 'NOW()', false);
|
||||
|
||||
$sDefaultValue = $oDateAttribute->GetDefaultValue();
|
||||
$defaultValue = $oDateAttribute->GetDefaultValue();
|
||||
|
||||
self::AssertDateEqualsNow($sDefaultValue, 'NOW() should be evaluated as the current date');
|
||||
self::AssertDateEqualsNow($defaultValue, 'NOW() should be evaluated as the current date');
|
||||
}
|
||||
|
||||
public function testDateTimeIntervalAsDefaultGivesCorrectDateAsDefaultValue()
|
||||
|
||||
@@ -26,6 +26,7 @@ class InterfaceDiscoveryTest extends ItopDataTestCase
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->SetNonPublicProperty($this->oInterfaceDiscovery, 'bCheckInterfaceImplementation', true);
|
||||
$this->SetNonPublicProperty(InterfaceDiscovery::GetInstance(), 'aForcedClassMap', null);
|
||||
$this->oCacheService->SetStorageRootDir(null);
|
||||
self::RecurseRmdir($this->sCacheRootDir);
|
||||
@@ -49,6 +50,40 @@ class InterfaceDiscoveryTest extends ItopDataTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers N°8143 - Setup page in error
|
||||
*/
|
||||
public function testShouldSelectTheRequestedItopClassesAndExcludeUnexistingOnes()
|
||||
{
|
||||
$this->SetNonPublicProperty($this->oInterfaceDiscovery, 'bCheckInterfaceImplementation', false);
|
||||
$this->GivenClassMap([
|
||||
'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory2' => APPROOT . '/sources/Application/UI/Base/Component/Alert/AlertUIBlockFactory.php',
|
||||
'Combodo\iTop\Application\UI\Base\Component\ButtonGroup\ButtonGroupUIBlockFactory2' => APPROOT . '/sources/Application/UI/Base/Component/ButtonGroup/ButtonGroupUIBlockFactory.php',
|
||||
]);
|
||||
|
||||
$this->AssertArraysHaveSameItems([], $this->oInterfaceDiscovery->FindItopClasses(iUIBlockFactory::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers N°8143 - Setup page in error
|
||||
*/
|
||||
public function testReadClassesFromCache_ShouldExcludeUnexistingClasses()
|
||||
{
|
||||
$oCacheService = $this->createMock(DataModelDependantCache::class);
|
||||
$aCachedRealClasses = [
|
||||
'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory',
|
||||
'Combodo\iTop\Application\UI\Base\Component\ButtonGroup\ButtonGroupUIBlockFactory2',
|
||||
];
|
||||
$oCacheService->expects($this->once())
|
||||
->method('Fetch')
|
||||
->with('InterfaceDiscovery', '123')
|
||||
->willReturn($aCachedRealClasses);
|
||||
|
||||
$this->oInterfaceDiscovery->SetCacheService($oCacheService);
|
||||
|
||||
$this->AssertArraysHaveSameItems([ 'Combodo\iTop\Application\UI\Base\Component\Alert\AlertUIBlockFactory'], $this->oInterfaceDiscovery->ReadClassesFromCache('123'));
|
||||
}
|
||||
|
||||
public function testShouldExcludeAliases()
|
||||
{
|
||||
$this->GivenClassMap([
|
||||
@@ -87,7 +122,7 @@ class InterfaceDiscoveryTest extends ItopDataTestCase
|
||||
$this->assertGreaterThan(0, count($this->oInterfaceDiscovery->FindItopClasses(iUIBlockFactory::class)));
|
||||
$this->AssertDirectoryListingEquals([
|
||||
'autoload_classmaps.php',
|
||||
'1ab1e62be3e9984a8176deeb20f049b1_iUIBlockFactory.php'
|
||||
'1ab1e62be3e9984a8176deeb20f049b1_iUIBlockFactory.php',
|
||||
],
|
||||
$this->sCacheRootDir.'/InterfaceDiscovery');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user