mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
N°7345 Accept DateTime objects for DBObject::Set() calls on AttributeDateTime and children (#618)
This commit is contained in:
@@ -20,9 +20,11 @@
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Attachment;
|
||||
use AttributeDateTime;
|
||||
use Combodo\iTop\Service\Events\EventData;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use CoreException;
|
||||
use DateTime;
|
||||
use DBObject;
|
||||
use InvalidExternalKeyValueException;
|
||||
use lnkContactToFunctionalCI;
|
||||
@@ -412,7 +414,55 @@ class DBObjectTest extends ItopDataTestCase
|
||||
$oObject->Set('org_id', 3);
|
||||
$this->assertDBQueryCount(1, function() use (&$oObject){
|
||||
static::assertNotEmpty($oObject->Get('org_name'));
|
||||
}); }
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers AttributeDateTime::MakeRealValue
|
||||
*/
|
||||
public function testSetAttributeDateTimeWithTimestamp(): void
|
||||
{
|
||||
$oUserRequest = $this->CreateUserRequest(0);
|
||||
$iNow = time();
|
||||
$oMyDate = new DateTime('2024-02-14 18:12');
|
||||
$sMyDate = $oMyDate->format(AttributeDateTime::GetInternalFormat());
|
||||
|
||||
// First test string obtained with Get() converts into a standard DateTime object
|
||||
$oUserRequest->Set('start_date', $iNow);
|
||||
$sSavedDate = $oUserRequest->Get('start_date');
|
||||
$oSavedDate = new DateTime($sSavedDate);
|
||||
$this->assertSame($iNow, $oSavedDate->getTimestamp());
|
||||
|
||||
// Second test that string obtained with Get() is of the \AttributeDateTime::GetInternalFormat format
|
||||
$oUserRequest->Set('start_date', $oMyDate->getTimestamp());
|
||||
$this->assertEquals($sMyDate, $oUserRequest->Get('start_date'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers AttributeDateTime::MakeRealValue
|
||||
*/
|
||||
public function testSetAttributeDateTimeWithString(): void
|
||||
{
|
||||
$oUserRequest = $this->CreateUserRequest(0);
|
||||
$oMyDate = new DateTime('2024-02-14 18:12');
|
||||
$sMyDate = $oMyDate->format(AttributeDateTime::GetInternalFormat());
|
||||
|
||||
$oUserRequest->Set('start_date', $sMyDate);
|
||||
$this->assertEquals($sMyDate, $oUserRequest->Get('start_date'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers AttributeDateTime::MakeRealValue
|
||||
*/
|
||||
public function testSetAttributeDateTimeWithDateTime(): void
|
||||
{
|
||||
$oUserRequest = $this->CreateUserRequest(0);
|
||||
$oMyDate = new DateTime('2024-02-14 18:12');
|
||||
$sMyDate = $oMyDate->format(AttributeDateTime::GetInternalFormat());
|
||||
|
||||
$oUserRequest->Set('start_date', $oMyDate);
|
||||
$this->assertEquals($sMyDate, $oUserRequest->Get('start_date'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Integration
|
||||
|
||||
@@ -127,7 +127,7 @@ class ImportTest extends ItopDataTestCase {
|
||||
'"first_name","name", "email", "org_id->name", obsolescence_date',
|
||||
sprintf('"%s", "%s", "%s", UID, toto', $sFirstName, $sLastName, $sEmail),
|
||||
sprintf(
|
||||
'Issue: Internal error: Exception, Wrong format for date attribute obsolescence_date, expecting "Y-m-d" and got "toto";n/a;n/a;n/a;%s;%s;%s;toto', $sFirstName, $sLastName, $sEmail
|
||||
'Issue: Internal error: CoreUnexpectedValue, Wrong format for date attribute obsolescence_date, expecting "Y-m-d" and got "toto";n/a;n/a;n/a;%s;%s;%s;toto', $sFirstName, $sLastName, $sEmail
|
||||
),
|
||||
null,
|
||||
1,
|
||||
@@ -174,7 +174,7 @@ CSVFILE;
|
||||
foreach (["ORGID" => $iOrgId, "UID" => $this->sUid] as $sSearch => $sReplace){
|
||||
$sLastLineNeedle = str_replace($sSearch, $sReplace, $sLastLineNeedle);
|
||||
}
|
||||
$this->assertStringContainsString($sLastLineNeedle, $sLastline, $sLastline);
|
||||
$this->assertStringContainsString($sLastLineNeedle, $sLastline, 'The script we launched in an external process returned a value different than the expected error message');
|
||||
|
||||
$sPattern = "/Person;(\d+);/";
|
||||
if (preg_match($sPattern,$sLastline,$aMatches)){
|
||||
|
||||
Reference in New Issue
Block a user