Merge remote-tracking branch 'origin/support/2.7' into develop

# Conflicts:
#	core/log.class.inc.php
#	datamodels/2.x/itop-attachments/renderers.itop-attachments.php
#	js/search/search_form_criteria_enum.js
#	lib/composer/autoload_classmap.php
#	lib/composer/autoload_static.php
#	test/core/dictTest.php
This commit is contained in:
Pierre Goiffon
2021-12-08 18:30:20 +01:00
11 changed files with 579 additions and 30 deletions

View File

@@ -38,19 +38,83 @@ use Exception;
*/
class dictTest extends ItopTestCase
{
private $sEnvName;
protected function setUp()
{
parent::setUp();
require_once (APPROOT.'core/dict.class.inc.php');
require_once 'mockDict.incphp';
require_once(APPROOT.'core'.DIRECTORY_SEPARATOR.'apc-service.class.inc.php');
$this->sEnvName = time();
$sDictionaryFolder = APPROOT."env-$this->sEnvName".DIRECTORY_SEPARATOR."dictionaries";
@mkdir($sDictionaryFolder, 0777, true);
$sContent = <<<PHP
<?php
//
// Dictionary built by the compiler for the language "FR FR"
//
Dict::SetEntries('FR FR', array(
'label1' => 'gabu',
));
PHP;
file_put_contents($sDictionaryFolder.DIRECTORY_SEPARATOR."fr-fr.dict.php", $sContent);
$sContent = <<<PHP
<?php
//
// Dictionary built by the compiler for the language "FR FR"
//
Dict::SetEntries('EN EN', array(
'label1' => 'zomeu',
));
PHP;
file_put_contents($sDictionaryFolder.DIRECTORY_SEPARATOR."en-en.dict.php", $sContent);
$_SESSION['itop_env'] = $this->sEnvName;
}
/**
* @throws Exception
*/
public function testType()
protected function tearDown()
{
foreach (glob(APPROOT."env-$this->sEnvName".DIRECTORY_SEPARATOR."dictionaries".DIRECTORY_SEPARATOR."*") as $sFile) {
unlink($sFile);
}
rmdir(APPROOT."env-$this->sEnvName".DIRECTORY_SEPARATOR."dictionaries");
rmdir(APPROOT."env-$this->sEnvName");
}
/**
* @throws Exception
*/
public function testType()
{
$_SESSION['itop_env'] = 'production';
$this->assertInternalType('string', Dict::S('Core:AttributeURL'));
$this->assertInternalType('string', Dict::Format('Change:AttName_SetTo', '1', '2'));
}
public function testInitLangIfNeeded_NoApc()
{
$oApcService = $this->createMock(\ApcService::class);
Dict::SetApcService($oApcService);
Dict::EnableCache('toto');
$oApcService->expects($this->any())
->method('function_exists')
->willReturn(false);
$oApcService->expects($this->never())
->method('apc_fetch')
->willReturn(false);
$oApcService->expects($this->never())
->method('apc_store')
->willReturn(false);
Dict::SetLanguagesList(['FR FR' => 'fr', 'EN EN' => 'en']);
Dict::SetUserLanguage('FR FR');
$this->assertEquals('gabu', Dict::S('label1'));
Dict::SetUserLanguage('EN EN');
$this->assertEquals('zomeu', Dict::S('label1'));
}
}