mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
N°3677 - Fix AttributeImage.default_image URLs not up to date after app_root_url change (#526)
Many thanks to @sg-gcouronne for this contribution !
This commit is contained in:
@@ -248,6 +248,9 @@ class utilsTest extends ItopTestCase
|
||||
*/
|
||||
public function testGetAbsoluteUrlAppRootPersistency($bBehindReverseProxy,$bForceTrustProxy1 ,$sExpectedAppRootUrl1,$bForceTrustProxy2 , $sExpectedAppRootUrl2,$bForceTrustProxy3 , $sExpectedAppRootUrl3)
|
||||
{
|
||||
// resetting static property for each test pass
|
||||
$this->SetNonPublicStaticProperty(utils::class, 'sAbsoluteUrlAppRootCache', null);
|
||||
|
||||
utils::GetConfig()->Set('behind_reverse_proxy', $bBehindReverseProxy);
|
||||
utils::GetConfig()->Set('app_root_url', '');
|
||||
|
||||
@@ -272,9 +275,6 @@ class utilsTest extends ItopTestCase
|
||||
$this->assertEquals($sExpectedAppRootUrl2, utils::GetAbsoluteUrlAppRoot($bForceTrustProxy2));
|
||||
|
||||
$this->assertEquals($sExpectedAppRootUrl3, utils::GetAbsoluteUrlAppRoot($bForceTrustProxy3));
|
||||
|
||||
// Leave the place clean
|
||||
static::SetNonPublicStaticProperty('utils', 'm_sAppRootUrl', null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use Config;
|
||||
use MetaModel;
|
||||
use Person;
|
||||
use utils;
|
||||
|
||||
class AttributeImageTest extends ItopDataTestCase
|
||||
{
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->RequireOnceItopFile('core/attributedef.class.inc.php');
|
||||
}
|
||||
|
||||
public function testGet(): void
|
||||
{
|
||||
$oConfig = utils::GetConfig();
|
||||
$oPersonPictureAttDef = MetaModel::GetAttributeDef(Person::class, 'picture');
|
||||
|
||||
$sAppRootUrl1 = 'http://localhost/iTop/';
|
||||
$this->SetNewAppRootUrl($oConfig, $sAppRootUrl1);
|
||||
$sPersonPictureDefaultImageUrl = $oPersonPictureAttDef->Get('default_image');
|
||||
$this->assertStringStartsWith($sAppRootUrl1, $sPersonPictureDefaultImageUrl);
|
||||
|
||||
$sAppRootUrl2 = 'https://demo.combodo.com/simple/';
|
||||
$this->SetNewAppRootUrl($oConfig, $sAppRootUrl2);
|
||||
$oConfig->Set('app_root_url', $sAppRootUrl2);
|
||||
$sPersonPictureDefaultImageUrl = $oPersonPictureAttDef->Get('default_image');
|
||||
$this->assertStringStartsWith($sAppRootUrl2, $sPersonPictureDefaultImageUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that we need to reset manually the cache in \utils::GetAbsoluteUrlAppRoot, which is called from \AttributeImage::Get
|
||||
*/
|
||||
private function SetNewAppRootUrl(Config $oConfig, string $sAppRootUrl):void {
|
||||
$oConfig->Set('app_root_url', $sAppRootUrl);
|
||||
$this->SetNonPublicStaticProperty(utils::class, 'sAbsoluteUrlAppRootCache', null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user