mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
Merge remote-tracking branch 'origin/support/3.1' into support/3.2
This commit is contained in:
@@ -5,9 +5,11 @@ namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use CMDBObject;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use CoreException;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
|
||||
|
||||
/**
|
||||
* @since 2.7.7 3.0.2 3.1.0 N°3717 tests history objects creation
|
||||
*
|
||||
@@ -168,6 +170,53 @@ class CMDBObjectTest extends ItopDataTestCase
|
||||
CMDBObject::SetTrackInfo($sInitialTrackInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test deletion
|
||||
* N°5547 - Object deletion fails if friendlyname too long
|
||||
*
|
||||
* @return array data
|
||||
*/
|
||||
public function RecordObjDeletionProvider()
|
||||
{
|
||||
return [
|
||||
'friendlyname longer than 255 characters which will be truncated on a multi-bytes characters' => [
|
||||
str_repeat('e', 250),
|
||||
'😁😂🤣😃😄😅😆😗🥰😘😍😎😋😊😉😙😚',
|
||||
],
|
||||
'friendlyname longer than 255 characters which will be truncated after a single byte characters' => [
|
||||
'😁😂🤣😃😄😅😆😗🥰😘😍😎😋😊😉😙😚',
|
||||
str_repeat('e', 250),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* N°5547 - Object deletion fails if friendlyname too long
|
||||
*
|
||||
* @dataProvider RecordObjDeletionProvider
|
||||
*
|
||||
*/
|
||||
public function testRecordObjDeletion( string $sFirstName, string $sName)
|
||||
{
|
||||
$oPerson = MetaModel::NewObject('Person', [
|
||||
'first_name' => $sFirstName,
|
||||
'name' => $sName,
|
||||
'org_id' => 1,
|
||||
]);
|
||||
$oPerson->DBWrite();
|
||||
|
||||
$bDeletionOK = true;
|
||||
try {
|
||||
$oDeletionPlan = $this->InvokeNonPublicMethod(CMDBObject::class, 'RecordObjDeletion', $oPerson, [$oPerson->GetKey()]);
|
||||
}
|
||||
catch (CoreException $e) {
|
||||
$bDeletionOK = false;
|
||||
}
|
||||
// We don't need to test the result (truncated string), it's already done in \DBObject::SetTrim() with N°3448
|
||||
$this->assertTrue($bDeletionOK);
|
||||
}
|
||||
|
||||
|
||||
private function ReplaceByFriendlyNames($sMessage, $oAdminUser, $oImpersonatedUser) : string {
|
||||
$sNewMessage = str_replace('AdminSurName AdminName', $oAdminUser->GetFriendlyName(), $sMessage);
|
||||
$sNewMessage = str_replace('ImpersonatedSurName ImpersonatedName', $oImpersonatedUser->GetFriendlyName(), $sNewMessage);
|
||||
|
||||
@@ -1133,6 +1133,54 @@ class DBObjectTest extends ItopDataTestCase
|
||||
return $oPerson;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test deletion
|
||||
* N°5547 - Object deletion fails if friendlyname too long
|
||||
*
|
||||
* @return array data
|
||||
*/
|
||||
public function getDeletionLongValueProvider()
|
||||
{
|
||||
return [
|
||||
'friendlyname longer than 255 chracters with smiley' => [
|
||||
'0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq',
|
||||
'😁😂🤣😃😄😅😆😗🥰😘😍😎😋😊😉😙😚',
|
||||
],
|
||||
'the same friendlyname in other order with error before fix 5547 ' => [
|
||||
'😁😂🤣😃😄😅😆😗🥰😘😍😎😋😊😉😙😚',
|
||||
'0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789-0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopq',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* N°5547 - Object deletion fails if friendlyname too long
|
||||
*
|
||||
* @covers DBObject::DBIncrement
|
||||
*
|
||||
* @dataProvider getDeletionLongValueProvider
|
||||
*
|
||||
*/
|
||||
public function testDeletionLongValue(string $sName, string $sFirstName)
|
||||
{
|
||||
// Create a UserRequest with 2 contacts
|
||||
$oPerson = MetaModel::NewObject('Person', [
|
||||
'name' => $sName,
|
||||
'first_name' => $sFirstName,
|
||||
'org_id' => 1,
|
||||
]);
|
||||
$oPerson->DBWrite();
|
||||
|
||||
$bDeletionOK = true;
|
||||
try {
|
||||
$oDeletionPlan = $oPerson->DBDelete();
|
||||
}
|
||||
catch (CoreException $e) {
|
||||
$bDeletionOK = false;
|
||||
}
|
||||
$this->assertTrue($bDeletionOK);
|
||||
}
|
||||
|
||||
public function ResetReloadCount()
|
||||
{
|
||||
$this->aReloadCount = [];
|
||||
@@ -1211,8 +1259,14 @@ class DBObjectTest extends ItopDataTestCase
|
||||
$fTotalDuration = microtime(true) - $fStart;
|
||||
echo 'Total duration: '.sprintf('%.3f s', $fTotalDuration)."\n\n";
|
||||
}
|
||||
|
||||
public function CheckLongValueInAttributeProvider() {
|
||||
/**
|
||||
* Data provider for test deletion
|
||||
* N°5547 - Object deletion fails if friendlyname too long
|
||||
*
|
||||
* @return array data
|
||||
*/
|
||||
public function DeletionLongValueProvider()
|
||||
{
|
||||
return [
|
||||
// UserRequest.title is an AttributeString (maxsize = 255)
|
||||
'title 250 chars' => ['title', 250],
|
||||
@@ -1234,11 +1288,9 @@ class DBObjectTest extends ItopDataTestCase
|
||||
/**
|
||||
* Test check long field with non ascii characters
|
||||
*
|
||||
* @covers DBObject::Set
|
||||
* @covers DBObject::CheckToWrite
|
||||
* @covers DBObject::SetTrim
|
||||
* @covers DBObject::DBDelete
|
||||
*
|
||||
* @dataProvider CheckLongValueInAttributeProvider
|
||||
* @dataProvider DeletionLongValueProvider
|
||||
*
|
||||
* @since 3.1.2 N°3448 - Framework field size check not correctly implemented for multi-bytes languages/strings
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
namespace Combodo\iTop\Test\UnitTest\Module\ItopAttachment;
|
||||
|
||||
use Combodo\iTop\Service\Events\EventData;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use MetaModel;
|
||||
|
||||
class TestAttachment extends ItopDataTestCase
|
||||
{
|
||||
private string $sAddAttachmentName;
|
||||
private string $sRemoveAttachmentName;
|
||||
const CREATE_TEST_ORG = true;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
//static::$DEBUG_UNIT_TEST = true;
|
||||
}
|
||||
|
||||
public function testAddAttachment()
|
||||
{
|
||||
$this->sAddAttachmentName = '';
|
||||
$this->sRemoveAttachmentName = '';
|
||||
|
||||
$_REQUEST['transaction_id'] = 'test_transaction';
|
||||
$_REQUEST['attachment_plugin'] = 'in_form';
|
||||
|
||||
$oDocument = new \ormDocument('Test', 'text/plain', 'test.txt');
|
||||
|
||||
$this->EventService_RegisterListener(EVENT_ADD_ATTACHMENT_TO_OBJECT, [$this, 'OnAddAttachment']);
|
||||
$this->EventService_RegisterListener(EVENT_REMOVE_ATTACHMENT_FROM_OBJECT, [$this, 'OnRemoveAttachment']);
|
||||
|
||||
$oAttachment = MetaModel::NewObject('Attachment', [
|
||||
'item_class' => 'UserRequest',
|
||||
'temp_id' => 'test_transaction',
|
||||
'contents' => $oDocument,
|
||||
]);
|
||||
|
||||
$oAttachment->DBInsert();
|
||||
$oTicket = $this->CreateTicket(1);
|
||||
|
||||
$_REQUEST['removed_attachments'] = [$oAttachment->GetKey()];
|
||||
$this->InvokeNonPublicStaticMethod(\AttachmentPlugIn::class, 'UpdateAttachments', [$oTicket]);
|
||||
|
||||
$this->assertEquals('test.txt', $this->sAddAttachmentName);
|
||||
$this->assertEquals('test.txt', $this->sRemoveAttachmentName);
|
||||
}
|
||||
|
||||
public function OnAddAttachment(EventData $oData)
|
||||
{
|
||||
$this->debug('OnAddAttachment');
|
||||
$this->assertEquals('UserRequest', get_class($oData->Get('object')));
|
||||
$oAttachment = $oData->Get('attachment');
|
||||
/** @var \ormDocument $oDocument */
|
||||
$oDocument = $oAttachment->Get('contents');
|
||||
$this->sAddAttachmentName = $oDocument->GetFileName();
|
||||
}
|
||||
|
||||
public function OnRemoveAttachment(EventData $oData)
|
||||
{
|
||||
$this->debug('OnRemoveAttachment');
|
||||
$this->assertEquals('UserRequest', get_class($oData->Get('object')));
|
||||
$oAttachment = $oData->Get('attachment');
|
||||
/** @var \ormDocument $oDocument */
|
||||
$oDocument = $oAttachment->Get('contents');
|
||||
$this->sRemoveAttachmentName = $oDocument->GetFileName();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user