From 04c86e4b9ac958b97987f9338a34fa7759fb16b0 Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Thu, 25 Sep 2025 10:55:50 +0200 Subject: [PATCH 1/2] Remove special rule for help_ files # Conflicts: # src/Phpbb/TranslationValidator/Validator/FileValidator.php --- .../Validator/FileValidator.php | 111 +++++++++--------- 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/src/Phpbb/TranslationValidator/Validator/FileValidator.php b/src/Phpbb/TranslationValidator/Validator/FileValidator.php index 5bec8d0..83c8f8c 100644 --- a/src/Phpbb/TranslationValidator/Validator/FileValidator.php +++ b/src/Phpbb/TranslationValidator/Validator/FileValidator.php @@ -248,9 +248,13 @@ public function validate($sourceFile, $originFile) { $this->validateEmail($sourceFile, $originFile); } - else if (strpos($originFile, $this->originLanguagePath . 'help_') === 0 && substr($originFile, -4) === '.php') + else if ($originFile == $this->originLanguagePath . 'search_synonyms.php') { - $this->validateHelpFile($sourceFile, $originFile); + $this->validateSearchSynonymsFile($originFile); + } + else if ($originFile == $this->originLanguagePath . 'search_ignore_words.php') + { + $this->validateSearchIgnoreWordsFile($originFile); } else if (substr($originFile, -4) === '.php') { @@ -488,96 +492,91 @@ public function validateEmail($sourceFile, $originFile) } /** - * Validates a help_*.php file - * - * Files must only contain the variable $help. - * This variable must be an array of arrays. - * Subarrays must only have the indexes 0 and 1, - * with 0 being the headline and 1 being the description. + * Validates the search_synonyms.php file * - * Files must contain an entry with 0 and 1 being '--', - * causing the column break in the page. + * Files must only contain the variable $synonyms. + * This variable must be an array of string => string entries. * * @todo Check for template vars and html - * @todo Check for triple --- and other typos of it. * - * @param string $sourceFile Source file for comparison * @param string $originFile File to validate * @return null */ - public function validateHelpFile($sourceFile, $originFile) + public function validateSearchSynonymsFile($originFile) { $originFilePath = $this->originPath . '/' . $originFile; - $sourceFilePath = $this->sourcePath . '/' . $sourceFile; if (!$this->safeMode) { - /** @var $help */ + /** @var $synonyms */ include($originFilePath); $defined_variables = get_defined_vars(); - if (sizeof($defined_variables) != 5 || !isset($defined_variables['help']) || gettype($defined_variables['help']) != 'array') + if (sizeof($defined_variables) != 3 || !isset($defined_variables['synonyms']) || gettype($defined_variables['synonyms']) != 'array') { - $this->output->addMessage(Output::FATAL, 'Should only contain the help-array', $originFile); + $this->output->addMessage(Output::FATAL, 'Must only contain the synonyms-array', $originFile); return; } } else { - /** @var $help */ - $help = ValidatorRunner::langParser($originFilePath); - $this->output->addMessage(Output::NOTICE, '[Safe Mode] Manually run the translation validator to check help variables.', $originFile); - } - - $validate = $help; - unset($help); - - if (!$this->safeMode) - { - /** @var $help */ - include($sourceFilePath); + /** @var $synonyms */ + $synonyms = ValidatorRunner::langParser($originFilePath); + $this->output->addMessage(Output::NOTICE, '[Safe Mode] Manually run the translation validator to check synonym variables.', $originFile); } - else + foreach ($synonyms as $synonym1 => $synonym2) { - /** @var $help */ - $help = ValidatorRunner::langParser($sourceFilePath); + if (gettype($synonym1) != 'string' || gettype($synonym2) != 'string') + { + $this->output->addMessage(Output::FATAL, 'Must only contain entries of type string => string: ' . serialize($synonym1) . ' => ' . serialize($synonym2), $originFile); + } } + } - $against = $help; - unset($help); + /** + * Validates the search_ignore_words.php file + * + * Files must only contain the variable $words. + * This variable must be an array of string entries. + * + * @todo Check for template vars and html + * + * @param string $originFile File to validate + * @return null + */ + public function validateSearchIgnoreWordsFile($originFile) + { + $originFilePath = $this->originPath . '/' . $originFile; - $column_breaks = 0; - $entry = 0; - foreach ($validate as $help) + if (!$this->safeMode) { - if (gettype($help) != 'array' || sizeof($help) != 2 || !isset($help[0]) || !isset($help[1])) - { - $this->output->addMessage(Output::FATAL, 'Found invalid entry: ' . serialize($help), $originFile, $entry); - } - else if ($help[0] == '--' && $help[1] == '--') - { - $column_breaks++; - } + /** @var $words */ + include($originFilePath); - if (isset($help[0])) + $defined_variables = get_defined_vars(); + if (sizeof($defined_variables) != 3 || !isset($defined_variables['words']) || gettype($defined_variables['words']) != 'array') { - $compare = isset($against[$entry][0]) ? $against[$entry][0] : ''; - $this->langKeyValidator->validate($originFile, $entry . '.0', $compare, $help[0]); + $this->output->addMessage(Output::FATAL, 'Must only contain the words-array', $originFile); + return; } + } - if (isset($help[1])) - { - $compare = isset($against[$entry][1]) ? $against[$entry][1] : ''; - $this->langKeyValidator->validate($originFile, $entry . '.1', $compare, $help[1]); - } - $entry++; + else + { + /** @var $words */ + $words = ValidatorRunner::langParser($originFilePath); + $this->output->addMessage(Output::NOTICE, '[Safe Mode] Manually run the translation validator to check word variables.', $originFile); } - if ($column_breaks != 1) + foreach ($words as $word) { - $this->output->addMessage(Output::FATAL, 'Must have exactly one column break entry', $originFile); + if (gettype($word) != 'string') + { + //@todo use $i + $this->output->addMessage(Output::FATAL, 'Must only contain entries of type string: ' . serialize($word), $originFile); + } } } From a2fb73f4118f9e425846c20ca0aa6044d11de18e Mon Sep 17 00:00:00 2001 From: Christian Schnegelberger Date: Thu, 25 Sep 2025 10:56:42 +0200 Subject: [PATCH 2/2] Remove tests for help_ files --- .../Validator/FileValidator.php | 99 +------------------ tests/FileValidator/ValidateHelpTest.php | 46 --------- 2 files changed, 1 insertion(+), 144 deletions(-) delete mode 100644 tests/FileValidator/ValidateHelpTest.php diff --git a/src/Phpbb/TranslationValidator/Validator/FileValidator.php b/src/Phpbb/TranslationValidator/Validator/FileValidator.php index 83c8f8c..784f275 100644 --- a/src/Phpbb/TranslationValidator/Validator/FileValidator.php +++ b/src/Phpbb/TranslationValidator/Validator/FileValidator.php @@ -248,14 +248,6 @@ public function validate($sourceFile, $originFile) { $this->validateEmail($sourceFile, $originFile); } - else if ($originFile == $this->originLanguagePath . 'search_synonyms.php') - { - $this->validateSearchSynonymsFile($originFile); - } - else if ($originFile == $this->originLanguagePath . 'search_ignore_words.php') - { - $this->validateSearchIgnoreWordsFile($originFile); - } else if (substr($originFile, -4) === '.php') { $this->validateLangFile($sourceFile, $originFile); @@ -490,96 +482,7 @@ public function validateEmail($sourceFile, $originFile) $this->output->addMessage(Output::FATAL, 'Missing new line at the end of the file', $originFile); } } - - /** - * Validates the search_synonyms.php file - * - * Files must only contain the variable $synonyms. - * This variable must be an array of string => string entries. - * - * @todo Check for template vars and html - * - * @param string $originFile File to validate - * @return null - */ - public function validateSearchSynonymsFile($originFile) - { - $originFilePath = $this->originPath . '/' . $originFile; - - if (!$this->safeMode) - { - /** @var $synonyms */ - include($originFilePath); - - $defined_variables = get_defined_vars(); - if (sizeof($defined_variables) != 3 || !isset($defined_variables['synonyms']) || gettype($defined_variables['synonyms']) != 'array') - { - $this->output->addMessage(Output::FATAL, 'Must only contain the synonyms-array', $originFile); - return; - } - } - - else - { - /** @var $synonyms */ - $synonyms = ValidatorRunner::langParser($originFilePath); - $this->output->addMessage(Output::NOTICE, '[Safe Mode] Manually run the translation validator to check synonym variables.', $originFile); - } - - foreach ($synonyms as $synonym1 => $synonym2) - { - if (gettype($synonym1) != 'string' || gettype($synonym2) != 'string') - { - $this->output->addMessage(Output::FATAL, 'Must only contain entries of type string => string: ' . serialize($synonym1) . ' => ' . serialize($synonym2), $originFile); - } - } - } - - /** - * Validates the search_ignore_words.php file - * - * Files must only contain the variable $words. - * This variable must be an array of string entries. - * - * @todo Check for template vars and html - * - * @param string $originFile File to validate - * @return null - */ - public function validateSearchIgnoreWordsFile($originFile) - { - $originFilePath = $this->originPath . '/' . $originFile; - - if (!$this->safeMode) - { - /** @var $words */ - include($originFilePath); - - $defined_variables = get_defined_vars(); - if (sizeof($defined_variables) != 3 || !isset($defined_variables['words']) || gettype($defined_variables['words']) != 'array') - { - $this->output->addMessage(Output::FATAL, 'Must only contain the words-array', $originFile); - return; - } - } - - else - { - /** @var $words */ - $words = ValidatorRunner::langParser($originFilePath); - $this->output->addMessage(Output::NOTICE, '[Safe Mode] Manually run the translation validator to check word variables.', $originFile); - } - - foreach ($words as $word) - { - if (gettype($word) != 'string') - { - //@todo use $i - $this->output->addMessage(Output::FATAL, 'Must only contain entries of type string: ' . serialize($word), $originFile); - } - } - } - + /** * Validates the LICENSE file * diff --git a/tests/FileValidator/ValidateHelpTest.php b/tests/FileValidator/ValidateHelpTest.php deleted file mode 100644 index f4c811b..0000000 --- a/tests/FileValidator/ValidateHelpTest.php +++ /dev/null @@ -1,46 +0,0 @@ -validator->validateHelpFile($file, $file); - $this->assertOutputMessages($expected); - } -}