From 48e7e0309a44515dc296a6d6a91ab6d75573a3ee Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Tue, 8 Aug 2023 15:04:28 +0200 Subject: [PATCH 1/3] =?UTF-8?q?N=C2=B06638=20:white=5Fcheck=5Fmark:=20Fix?= =?UTF-8?q?=20DictionariesConsistencyTest::testImportCsvMessageStillOk=20n?= =?UTF-8?q?ot=20run=20on=20Jenkins=20Was=20contained=20in=20a=20class=20wi?= =?UTF-8?q?th=20a=20beforeSetup=20group=20annotation,=20whereas=20it=20tri?= =?UTF-8?q?es=20to=20read=20files=20in=20env-production=20(!)=20Plus=20the?= =?UTF-8?q?=20dataprovider=20was=20using=20APPROOT=20const=20+=20utils=20c?= =?UTF-8?q?lass,=20which=20aren't=20available=20by=20default=20:(=20=3D>?= =?UTF-8?q?=20Fixed=20by=20moving=20in=20a=20dedicated=20class=20(Compiled?= =?UTF-8?q?DictionariesConsistencyTest)=20and=20removing=20the=20dataprovi?= =?UTF-8?q?der?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CompiledDictionariesConsistencyTest.php | 74 +++++++++++++++++++ .../DictionariesConsistencyTest.php | 65 +--------------- 2 files changed, 75 insertions(+), 64 deletions(-) create mode 100644 tests/php-unit-tests/integration-tests/CompiledDictionariesConsistencyTest.php diff --git a/tests/php-unit-tests/integration-tests/CompiledDictionariesConsistencyTest.php b/tests/php-unit-tests/integration-tests/CompiledDictionariesConsistencyTest.php new file mode 100644 index 0000000000..bc79464216 --- /dev/null +++ b/tests/php-unit-tests/integration-tests/CompiledDictionariesConsistencyTest.php @@ -0,0 +1,74 @@ + [], + 'UI:CSVReport-Value-ChangeIssue' => ['arg1'], + 'UI:CSVReport-Value-NoMatch' => ['arg1'], + 'UI:CSVReport-Value-NoMatch-PossibleValues' => ['arg1', 'arg2'], + 'UI:CSVReport-Value-NoMatch-NoObject' => ['arg1'], + 'UI:CSVReport-Value-NoMatch-NoObject-ForCurrentUser' => ['arg1'], + 'UI:CSVReport-Value-NoMatch-SomeObjectNotVisibleForCurrentUser' => ['arg1'], + ]; + + $sCompiledLanguagesFilePath = APPROOT . 'env-' . \utils::GetCurrentEnvironment() . '/dictionaries/languages.php'; + $this->assertFileExists($sCompiledLanguagesFilePath, 'We must have an existing compiled language.php file in the current env !'); + require_once($sCompiledLanguagesFilePath); + $this->assertNotEmpty(Dict::GetLanguages(), 'the languages.php file exists but didn\'t load any language'); + + foreach (glob(APPROOT . 'env-' . \utils::GetCurrentEnvironment() . '/dictionaries/*.dict.php') as $sDictFile) { + if (preg_match('/.*\\/(.*).dict.php/', $sDictFile, $aMatches)) { + $sLangCode = $aMatches[1]; + $sLanguageCode = strtoupper(str_replace('-', ' ', $sLangCode)); + Dict::SetUserLanguage($sLanguageCode); + + foreach ($aLabelsToTest as $sLabelKey => $aLabelArgs) { + echo "Testing $sDictFile, label $sLabelKey with " . \var_export($aLabelArgs, true) . "\n"; + try { + $sLabelValue = Dict::Format($sLabelKey, ...$aLabelArgs); + //$this->debug($sLabelValue); + } catch (\ValueError $e) { + $aFailedLabels[] = $sLabelKey; + + $this->debug([ + 'exception' => $e->getMessage(), + 'trace' => $e->getTraceAsString(), + 'label_name' => $sLabelKey, + 'label_args' => $aLabelArgs, + ]); + } + } + $this->assertEquals([], $aFailedLabels, "$sDictFile : test fail for lang $sLangCode and labels (" . implode(", ", $aFailedLabels) . ')'); + } + } + } +} diff --git a/tests/php-unit-tests/integration-tests/DictionariesConsistencyTest.php b/tests/php-unit-tests/integration-tests/DictionariesConsistencyTest.php index 38fe83f2fe..55432aecab 100644 --- a/tests/php-unit-tests/integration-tests/DictionariesConsistencyTest.php +++ b/tests/php-unit-tests/integration-tests/DictionariesConsistencyTest.php @@ -16,9 +16,9 @@ namespace Combodo\iTop\Test\UnitTest\Integration; use Combodo\iTop\Test\UnitTest\ItopTestCase; -use Dict; /** + * For tests on compiled dict files, see {@see CompiledDictionariesConsistencyTest} * @group beforeSetup */ class DictionariesConsistencyTest extends ItopTestCase @@ -152,67 +152,4 @@ class DictionariesConsistencyTest extends ItopTestCase $sMessage = "File `{$sDictFile}` syntax didn't matched expectations\nparsing results=".var_export($output, true); self::assertEquals($bIsSyntaxValid, $bDictFileSyntaxOk, $sMessage); } - - /** - * @dataProvider ImportCsvMessageStillOkProvider - * make sure N°5305 dictionary changes are still here and UI remains unbroken for any lang - */ - public function testImportCsvMessageStillOk($sLangCode, $sDictFile) - { - $aFailedLabels = []; - $aLabelsToTest = [ - 'UI:CSVReport-Value-SetIssue' => [], - 'UI:CSVReport-Value-ChangeIssue' => [ 'arg1' ], - 'UI:CSVReport-Value-NoMatch' => [ 'arg1' ], - 'UI:CSVReport-Value-NoMatch-PossibleValues' => [ 'arg1', 'arg2' ], - 'UI:CSVReport-Value-NoMatch-NoObject' => [ 'arg1' ], - 'UI:CSVReport-Value-NoMatch-NoObject-ForCurrentUser' => [ 'arg1' ], - 'UI:CSVReport-Value-NoMatch-SomeObjectNotVisibleForCurrentUser' => [ 'arg1' ], - ]; - - $sLanguageCode = strtoupper(str_replace('-', ' ', $sLangCode)); - require_once(APPROOT.'env-'.\utils::GetCurrentEnvironment().'/dictionaries/languages.php'); - Dict::SetUserLanguage($sLanguageCode); - foreach ($aLabelsToTest as $sLabelKey => $aLabelArgs){ - try{ - $sLabelValue = Dict::Format($sLabelKey, ...$aLabelArgs); - //$this->debug($sLabelValue); - } catch (\ValueError $e){ - $aFailedLabels[] = $sLabelKey; - - $this->debug([ - 'exception' => $e->getMessage(), - 'trace' => $e->getTraceAsString(), - 'label_name' => $sLabelKey, - 'label_args' =>$aLabelArgs, - ]); - } - } - $this->assertEquals([], $aFailedLabels, "test fail for lang $sLangCode and labels (" . implode(", ", $aFailedLabels) . ')'); - } - - public function ImportCsvMessageStillOkProvider(){ - return $this->GetDictFiles(); - } - - /** - * return a map linked to *.dict.php files that are generated after setup - * each entry key is lang code (example 'en') - * each value is an array with lang code (again) and dict file path - * @return array - */ - private function GetDictFiles() : array { - $aDictFiles = []; - - foreach (glob(APPROOT.'env-'.\utils::GetCurrentEnvironment().'/dictionaries/*.dict.php') as $sDictFile){ - if (preg_match('/.*\\/(.*).dict.php/', $sDictFile, $aMatches)){ - $sLangCode = $aMatches[1]; - $aDictFiles[$sLangCode] = [ - 'lang' => $sLangCode, - 'file' => $sDictFile - ]; - } - } - return $aDictFiles; - } } From 6d13397ba1176db3beea410fa4f498c327f1b619 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Tue, 8 Aug 2023 15:33:09 +0200 Subject: [PATCH 2/3] :white_check_mark: Add other integration tests in the beforeSetup group All of those tests can be ran without a running iTop instance, and are blocking --- .../integration-tests/iTopModulesPhpVersionChecklistTest.php | 1 + .../integration-tests/iTopModulesXmlVersionChecklistTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/php-unit-tests/integration-tests/iTopModulesPhpVersionChecklistTest.php b/tests/php-unit-tests/integration-tests/iTopModulesPhpVersionChecklistTest.php index e4b7b5e824..5be950bf64 100644 --- a/tests/php-unit-tests/integration-tests/iTopModulesPhpVersionChecklistTest.php +++ b/tests/php-unit-tests/integration-tests/iTopModulesPhpVersionChecklistTest.php @@ -25,6 +25,7 @@ use utils; * @covers iTopDesignFormat * * @package Combodo\iTop\Test\UnitTest\Setup + * @group beforeSetup */ class iTopModulesPhpVersionIntegrationTest extends ItopTestCase { diff --git a/tests/php-unit-tests/integration-tests/iTopModulesXmlVersionChecklistTest.php b/tests/php-unit-tests/integration-tests/iTopModulesXmlVersionChecklistTest.php index de9bafa56e..37188dedb4 100644 --- a/tests/php-unit-tests/integration-tests/iTopModulesXmlVersionChecklistTest.php +++ b/tests/php-unit-tests/integration-tests/iTopModulesXmlVersionChecklistTest.php @@ -24,6 +24,7 @@ use iTopDesignFormat; * @covers iTopDesignFormat * * @package Combodo\iTop\Test\UnitTest\Setup + * @group beforeSetup */ class iTopModulesXmlVersionIntegrationTest extends ItopTestCase { From 13ad98b9b38638bc5196b42ea1ac946d74c744a3 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Tue, 8 Aug 2023 15:34:27 +0200 Subject: [PATCH 3/3] :white_check_mark: Add other integration tests in the beforeSetup group All of those tests can be ran without a running iTop instance, and are blocking --- .../integration-tests/iTopXmlVersionChecklistTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/php-unit-tests/integration-tests/iTopXmlVersionChecklistTest.php b/tests/php-unit-tests/integration-tests/iTopXmlVersionChecklistTest.php index 0e87f386f1..f8844de7ab 100644 --- a/tests/php-unit-tests/integration-tests/iTopXmlVersionChecklistTest.php +++ b/tests/php-unit-tests/integration-tests/iTopXmlVersionChecklistTest.php @@ -20,6 +20,7 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase; /** * @package Combodo\iTop\Test\UnitTest\Setup + * @group beforeSetup */ class iTopXmlVersionIntegrationTest extends ItopTestCase {