From fd336ffd9255f3485575c35c8ce437896bf6e417 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Wed, 12 Jul 2023 08:36:06 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B06558=20:white=5Fcheck=5Fmark:=20Test=20f?= =?UTF-8?q?or=20iTopDesignFormat::$aVersions=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iTopDesignFormat/iTopDesignFormatTest.php | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/iTopDesignFormatTest.php b/tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/iTopDesignFormatTest.php index de580a4a9..52f356f04 100644 --- a/tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/iTopDesignFormatTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/iTopDesignFormat/iTopDesignFormatTest.php @@ -6,6 +6,8 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase; use DOMDocument; use DOMXPath; use iTopDesignFormat; +use ReflectionException; +use utils; /** @@ -256,6 +258,53 @@ class iTopDesignFormatTest extends ItopTestCase { $sCurrentPath = __DIR__; - return file_get_contents($sCurrentPath.DIRECTORY_SEPARATOR.$sFileName.'.xml'); + return file_get_contents($sCurrentPath . DIRECTORY_SEPARATOR . $sFileName . '.xml'); + } + + /** + * @since 3.2.0 N°6558 method creation + */ + public function testAVersionsContent(): void + { + $aAVersionsErrors = []; + + foreach (iTopDesignFormat::$aVersions as $sXmlVersion => $aXmlVersionData) { + foreach (['previous', 'go_to_previous', 'next', 'go_to_next'] as $sVersionParamKey) { + if (false === array_key_exists($sVersionParamKey, $aXmlVersionData)) { + $aAVersionsErrors[] = "$sXmlVersion version: missing `$sVersionParamKey` key !"; + } + } + + foreach (['previous', 'next'] as $sXmlVersionPointingToKey) { + if (false === array_key_exists($sXmlVersionPointingToKey, $aXmlVersionData)) { + continue; + } + if (utils::IsNullOrEmptyString($aXmlVersionData[$sXmlVersionPointingToKey])) { + continue; + } + if (false === \array_key_exists($aXmlVersionData[$sXmlVersionPointingToKey], iTopDesignFormat::$aVersions)) { + $aAVersionsErrors[] = "$sXmlVersion version: invalid value for `$sXmlVersionPointingToKey` key ! Value=" . $aXmlVersionData[$sXmlVersionPointingToKey]; + } + } + + $oItopDesignFormatClass = new \ReflectionClass(iTopDesignFormat::class); + foreach (['go_to_previous', 'go_to_next'] as $sXmlConversionMethodKey) { + if (false === array_key_exists($sXmlConversionMethodKey, $aXmlVersionData)) { + continue; + } + $sXmlConversionMethod = $aXmlVersionData[$sXmlConversionMethodKey]; + if (utils::IsNullOrEmptyString($sXmlConversionMethod)) { + continue; + } + try { + /** @noinspection PhpExpressionResultUnusedInspection */ + $oItopDesignFormatClass->getMethod($sXmlConversionMethod); + } catch (ReflectionException $e) { + $aAVersionsErrors[] = "$sXmlVersion version: conversion method `$sXmlConversionMethod` for key `$sXmlConversionMethodKey` does not exist"; + } + } + } + + $this->assertCount(0, $aAVersionsErrors, 'There were errors detected in iTopDesignFormat::$aVersions : ' . var_export($aAVersionsErrors, true)); } } \ No newline at end of file