mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-19 00:28:47 +02:00
N°8612 - add unitary test
This commit is contained in:
@@ -9,6 +9,7 @@ namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use InlineImage;
|
||||
use ormDocument;
|
||||
|
||||
class InlineImageTest extends ItopDataTestCase
|
||||
{
|
||||
@@ -98,4 +99,36 @@ HTML;
|
||||
$this->assertStringContainsString(\utils::EscapeHtml(\utils::GetAbsoluteUrlAppRoot().INLINEIMAGE_DOWNLOAD_URL.'123&s=abc'), $sResult);
|
||||
$this->assertStringContainsString(\utils::EscapeHtml(\utils::GetAbsoluteUrlAppRoot().INLINEIMAGE_DOWNLOAD_URL.'456&s=def'), $sResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers InlineImage::ReplaceInlineImagesWithBase64Representation
|
||||
*/
|
||||
public function testReplaceInlineImagesWithBase64Representation()
|
||||
{
|
||||
// create an inline image in the database
|
||||
$oInlineImage = $this->createObject(InlineImage::class, [
|
||||
'expire' => (new \DateTime('+1 day'))->format('Y-m-d H:i:s'),
|
||||
'item_class' => 'UserRequest',
|
||||
'item_id' => 999,
|
||||
'item_org_id' => 1,
|
||||
'contents' => new ormDocument('0x89504E470D0A1A0A0000000D494844520000000E0000000E08060000001F482DD1000000017352474200AECE1CE90000000467414D410000B18F0BFC6105000000097048597300000EC300000EC301C76FA8640000001E49444154384F63782BA3F29F1CCC802E402C1ED588078F6AC483E9AF11008B8BA9C08A7A3F290000000049454E44AE426082', 'image/png', 'square_red.png'),
|
||||
'secret' => 'a94bff3ea6a872bdbc359a1704cdddb3',
|
||||
]);
|
||||
$sInlineImageId = $oInlineImage->GetKey();
|
||||
$sInlineImageSecret = $oInlineImage->Get('secret');
|
||||
|
||||
// HTML with inline image
|
||||
$sHtml = <<<HTML
|
||||
<img src="http://host/iTop/pages/ajax.document.php?operation=download_inlineimage&id=$sInlineImageId&s=$sInlineImageSecret" data-img-id="$sInlineImageId" data-img-secret="$sInlineImageSecret" />
|
||||
HTML;
|
||||
|
||||
// expected HTML with base64 representation of the image
|
||||
$sExpected = <<<HTML
|
||||
<img src="data:image/png;base64,MHg4OTUwNEU0NzBEMEExQTBBMDAwMDAwMEQ0OTQ4NDQ1MjAwMDAwMDBFMDAwMDAwMEUwODA2MDAwMDAwMUY0ODJERDEwMDAwMDAwMTczNTI0NzQyMDBBRUNFMUNFOTAwMDAwMDA0Njc0MTRENDEwMDAwQjE4RjBCRkM2MTA1MDAwMDAwMDk3MDQ4NTk3MzAwMDAwRUMzMDAwMDBFQzMwMUM3NkZBODY0MDAwMDAwMUU0OTQ0NDE1NDM4NEY2Mzc4MkJBM0YyOUYxQ0NDODAyRTQwMkMxRUQ1ODgwNzhGNkFDNDgzRTlBRjExMDA4QjhCQTlDMDhBN0EzRjI5MDAwMDAwMDA0OTQ1NEU0NEFFNDI2MDgy" />
|
||||
HTML;
|
||||
|
||||
// test the method
|
||||
$sResult = InlineImage::ReplaceInlineImagesWithBase64Representation($sHtml);
|
||||
$this->assertEquals($sExpected, $sResult);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user