N°8259 - Problem with GetMaxSize on AttributeText

This commit is contained in:
jf-cbd
2025-03-13 15:29:00 +01:00
parent 0562563cbb
commit 29c75f626b
4 changed files with 69 additions and 5 deletions

View File

@@ -2,11 +2,19 @@
namespace Combodo\iTop\Test\UnitTest\Core;
use ArchivedObjectException;
use AttributeDate;
use AttributeDateTime;
use Change;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use CoreCannotSaveObjectException;
use CoreException;
use CoreUnexpectedValue;
use CoreWarning;
use EventRestService;
use MetaModel;
use MySQLException;
use OQLException;
use UserRequest;
class AttributeDefinitionTest extends ItopDataTestCase {
@@ -343,4 +351,23 @@ PHP
return $oAttribute;
}
/**
* @throws CoreException
* @throws CoreUnexpectedValue
* @throws OQLException
* @throws ArchivedObjectException
* @throws CoreCannotSaveObjectException
* @throws CoreWarning
* @throws MySQLException
*/
public function testTrimLogOnAttributeText()
{
// will throw MySQLException if GetMaxSize() of AttributeText is incorrect (should be number of bytes, not of characters)
$oLog = new EventRestService();
$sLongString = json_encode(array_fill(0, 5000, 'é😃 '),
JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
$oLog->SetTrim('json_input', $sLongString);
static::assertNotEquals($oLog->Get('json_input'), $sLongString);
static::assertStringContainsString('truncated', $oLog->Get('json_input'));
}
}

View File

@@ -22,6 +22,7 @@ namespace Combodo\iTop\Test\UnitTest\Core;
use Attachment;
use AttributeDateTime;
use Combodo\iTop\Service\Events\EventData;
use EventRestService;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use CoreException;
use DateTime;
@@ -1415,4 +1416,22 @@ class DBObjectTest extends ItopDataTestCase
$this->assertEquals("2024-01-15 09:45:00", $oObject->Get('end_date'), 'SetComputedDate +2 weeks on a WorkOrder DateTimeAttribute');
}
public function testStringFitsInField()
{
//🎁 character is 4 bytes long
$sTooLongText = str_repeat('🎁', 17000);
$oLog = new EventRestService();
$this->assertFalse($oLog->StringFitsInField('json_output', $sTooLongText));
$sCorrectLengthText = str_repeat('🎁', 16383);
$this->assertTrue($oLog->StringFitsInField('json_output', $sCorrectLengthText));
$sCorrectLengthString = str_repeat('🎁', 255);
$this->assertTrue($oLog->StringFitsInField('operation', $sCorrectLengthString));
$sTooLongString = str_repeat('🎁', 256);
$this->assertFalse($oLog->StringFitsInField('operation', $sTooLongString));
}
}