Reintegrate validation tests to ease iTop release management from develop

- N°3053 - Check XML conversion methods
     - N°3059 - Automatically set the documentation URLs
     - N°3052 - Check community modules XML version against latest version
     - N°3054 - Check community modules version against major version
     - N°3062 - setup.css file integrity test
     - N°3060 - Check consistency between the list of modules and installation.xml
     - N°3061 - Automatically check the installation.xml consistency
     - N°3268 Add test to check dictionary files: make sure that the Dict::Add declarations match the file name
This commit is contained in:
odain
2020-09-29 08:57:57 +02:00
parent d86e904e18
commit 20ce42b24b
9 changed files with 302 additions and 122 deletions

View File

@@ -916,7 +916,7 @@ class SetupUtils
$oPage, $bIsItopInstall, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $bTlsEnabled, $sTlsCA,
$sNewDBName = ''
) {
$sWikiVersion = '2_7_0';
$sWikiVersion = utils::GetItopVersionWikiSyntax(); //eg : '2_7_0';
$sMysqlTlsWikiPageUrl = 'https://wiki.openitop.org/doku.php?id='.$sWikiVersion.':install:php_and_mysql_tls';
$oPage->add('<tr><td colspan="2">');

View File

@@ -0,0 +1,108 @@
<?php
/**
* Copyright (C) 2013-2020 Combodo SARL
* This file is part of iTop.
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
*/
namespace Combodo\iTop\Test\UnitTest\Integration;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
class DictionariesConsistencyTest extends ItopTestCase
{
/**
* Verify that language declarations match the file names (same language codes)
*
* @dataProvider DictionaryFileProvider
*
* @param $sDictFile
*/
public function testDictionariesLanguage($sDictFile)
{
$aPrefixToLanguageData = array(
'cs' => array('CS CZ', 'Czech', 'Čeština'),
'da' => array('DA DA', 'Danish', 'Dansk'),
'de' => array('DE DE', 'German', 'Deutsch'),
'en' => array('EN US', 'English', 'English'),
'es_cr' => array('ES CR', 'Spanish', 'Español, Castellaño'),
'fr' => array('FR FR', 'French', 'Français'),
'hu' => array('HU HU', 'Hungarian', 'Magyar'),
'it' => array('IT IT', 'Italian', 'Italiano'),
'ja' => array('JA JP', 'Japanese', '日本語'),
'nl' => array('NL NL', 'Dutch', 'Nederlands'),
'pt_br' => array('PT BR', 'Brazilian', 'Brazilian'),
'ru' => array('RU RU', 'Russian', 'Русский'),
'sk' => array('SK SK', 'Slovak', 'Slovenčina'),
'tr' => array('TR TR', 'Turkish', 'Türkçe'),
'zh_cn' => array('ZH CN', 'Chinese', '简体中文')
);
if (!preg_match('/^(.*)\\.dict/', basename($sDictFile), $aMatches))
{
static::fail("Dictionary file '$sDictFile' not matching the naming convention");
}
$sLangPrefix = $aMatches[1];
if (!array_key_exists($sLangPrefix, $aPrefixToLanguageData))
{
static::fail("Unknown prefix '$sLangPrefix' for dictionary file '$sDictFile'");
}
$sExpectedLanguageCode = $aPrefixToLanguageData[$sLangPrefix][0];
$sExpectedEnglishLanguageDesc = $aPrefixToLanguageData[$sLangPrefix][1];
$sExpectedLocalizedLanguageDesc = $aPrefixToLanguageData[$sLangPrefix][2];
$sDictPHP = file_get_contents($sDictFile);
if ($iCount = preg_match_all("@Dict::Add\('(.*)'\s*,\s*'(.*)'\s*,\s*'(.*)'@", $sDictPHP, $aMatches) === false)
{
static::fail("Pattern not working");
}
if ($iCount == 0)
{
// Empty dictionary, that's fine!
static::assertTrue(true);
}
foreach ($aMatches[1] as $sLanguageCode)
{
static::assertSame($sExpectedLanguageCode, $sLanguageCode,
"Unexpected language code for Dict::Add in dictionary $sDictFile");
}
foreach ($aMatches[2] as $sEnglishLanguageDesc)
{
static::assertSame($sExpectedEnglishLanguageDesc, $sEnglishLanguageDesc,
"Unexpected language description (english) for Dict::Add in dictionary $sDictFile");
}
foreach ($aMatches[3] as $sLocalizedLanguageDesc)
{
static::assertSame($sExpectedLocalizedLanguageDesc, $sLocalizedLanguageDesc,
"Unexpected language description for Dict::Add in dictionary $sDictFile");
}
}
public function DictionaryFileProvider()
{
static::setUp();
$aDictFiles = array_merge(
glob(APPROOT.'datamodels/2.x/*/*.dict*.php'), // legacy form in modules
glob(APPROOT.'datamodels/2.x/*/dictionaries/*.dict*.php'), // modern form in modules
glob(APPROOT.'dictionaries/*.dict*.php') // framework
);
$aTestCases = array();
foreach ($aDictFiles as $sDictFile)
{
$aTestCases[$sDictFile] = array('sDictFile' => $sDictFile);
}
return $aTestCases;
}
}

View File

@@ -57,7 +57,7 @@ class iTopModulesPhpVersionIntegrationTest extends ItopTestCase
$matches
);
$this->assertRegExp("#$sExpectedVersion#", $matches[1], "$sPhpFile file refer does not refer to current itop version ($sModuleName/$matches[1] does not match regexp $sModuleName/$sExpectedVersion)");
$this->assertRegExp("#$sExpectedVersion#", $matches[1], " $sPhpFile:2 file refer does not refer to current itop version ($sModuleName/$matches[1] does not match regexp $sModuleName/$sExpectedVersion)");
}

View File

@@ -32,48 +32,57 @@ use iTopDesignFormat;
*/
class iTopModulesXmlVersionIntegrationTest extends ItopTestCase
{
protected function setUp()
{
parent::setUp();
require_once APPROOT.'setup/itopdesignformat.class.inc.php';
}
/**
* Verify if the datamodel.*.xml files refer to the current itop version
* Verify if the datamodel.*.xml files refer to the latest version of the design
* This is an integration test
*
* @group skipPostBuild
*
* @dataProvider DatamodelItopXmlVersionProvider
*/
public function testDatamodelItopXmlVersion($sExpectedXmlVersion, $sXmlFile)
public function testDatamodelItopXmlVersion($sXmlFile)
{
$sFileContent = file_get_contents($sXmlFile);
$oOriginalXml = new DOMDocument();
$oOriginalXml->load($sXmlFile);
preg_match(
'/<itop_design .* version="([^"]+)">/',
$sFileContent,
$matches
);
$oTransformedXml = new DOMDocument();
$oTransformedXml->load($sXmlFile);
$oFormat = new iTopDesignFormat($oTransformedXml);
$this->assertSame($sExpectedXmlVersion, $matches[1], "$sXmlFile file refer does not refer to current itop version ($matches[1] instead of expected $sExpectedXmlVersion)");
if ($oFormat->Convert())
{
// Compare the original and new format
$sExpectedXmlVersion = ITOP_DESIGN_LATEST_VERSION;
$this->assertSame($oTransformedXml->saveXML(), $oOriginalXml->saveXML(), "Datamodel file $sXmlFile:2 not in the latest format ($sExpectedXmlVersion)");
}
else
{
$this->fail("Failed to convert $sXmlFile into the latest format");
}
}
public function DatamodelItopXmlVersionProvider()
{
parent::setUp();
require_once APPROOT.'core/config.class.inc.php';
require_once APPROOT.'application/utils.inc.php';
static::setUp();
$sPath = APPROOT.'datamodels/2.x/*/datamodel.*.xml';
$aXmlFiles = glob($sPath);
$sItopVersionShort = \utils::GetItopPatchVersion();
$aItopVersion = explode('.', $sItopVersionShort);
$sExpectedXmlVersion = ($aItopVersion[0] - 1).'.'.($aItopVersion[1]); // eg: 2.7.0-dev become 1.7
$aXmlFiles[] = APPROOT.'core/datamodel.core.xml';
$aXmlFiles[] = APPROOT.'application/datamodel.application.xml';
$aTestCases = array();
foreach ($aXmlFiles as $sXmlFile)
{
$aTestCases[$sXmlFile] = array(
'sExpectedXmlVersion' => $sExpectedXmlVersion,
'sXmlFile' => $sXmlFile,
);
}

View File

@@ -41,8 +41,8 @@
verbose="false">
<testsuites>
<testsuite name="ReleaseChecklist">
<directory>releaseChecklist</directory>
<testsuite name="PostBuildIntegration">
<directory>postbuild_integration</directory>
</testsuite>
</testsuites>

View File

@@ -0,0 +1,164 @@
<?php
namespace Combodo\iTop\Test\UnitTest\ReleaseChecklist;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use iTopDesignFormat;
use PHPUnit\Exception;
/**
* Class iTopDesignFormatChecklistTest
* Ticket 3053 - Check XML conversion methods
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @backupGlobals disabled
*
* @covers iTopDesignFormat
*
* @package Combodo\iTop\Test\UnitTest\Setup
*/
class TestForITopDesignFormatClass extends ItopTestCase
{
protected function setUp()
{
parent::setUp();
require_once APPROOT.'setup/modelfactory.class.inc.php';
require_once APPROOT.'setup/itopdesignformat.class.inc.php';
}
/**
* release checklist step: make sure we have datamodel conversion functions for new iTop version
*/
public function testCurrentVersion_DataModelConversionFunctions()
{
$aErrors = [];
$aDatamodelCurrentVersions = array();
$aDataModelFiles = $this->GetDataModelFiles(APPROOT.'/datamodels');
//retrieve current XML version in datamoldels files
foreach ($aDataModelFiles as $sDataModelFile)
{
if (preg_match('/itop_design .* version="([\d\.]*)"/', file_get_contents($sDataModelFile), $aMatches))
{
$sVersion = $aMatches[1];
if (!array_key_exists($sVersion, $aDatamodelCurrentVersions))
{
if (trim($sVersion) === '')
{
$aErrors[] = "cannot retrieve itop_design datamodel version in $sDataModelFile:1";
continue;
}
$aDatamodelCurrentVersions[$sVersion] = $sVersion;
}
}
}
//make sure there is only one found
$this->assertTrue(is_array($aDatamodelCurrentVersions));
$sFirstVersion = array_keys(iTopDesignFormat::$aVersions)[0];
$sLatestVersion = array_keys(iTopDesignFormat::$aVersions)[count(iTopDesignFormat::$aVersions)-1];
foreach ($aDatamodelCurrentVersions as $sCurrentVersion)
{
try{
//check we have migration function from current version to previous
$this->CheckCondition(array_key_exists($sCurrentVersion, iTopDesignFormat::$aVersions), "Missing $sCurrentVersion conversion functions in iTopDesignFormat.");
$aCurrentVersionInfo = iTopDesignFormat::$aVersions[$sCurrentVersion];
$this->CheckCondition(is_array($aCurrentVersionInfo), "Wrong $sCurrentVersion config in iTopDesignFormat.");
$this->CheckCondition(array_key_exists('previous', $aCurrentVersionInfo), "Missing previous for $sCurrentVersion config in iTopDesignFormat.");
$this->TestDefinedFunction($aCurrentVersionInfo, 'go_to_next', $sCurrentVersion, ($sCurrentVersion=== $sLatestVersion));
$this->TestDefinedFunction($aCurrentVersionInfo, 'go_to_previous', $sCurrentVersion, ($sCurrentVersion==='1.0'));
//check we have migration function from N-1 version to current one
if (($sCurrentVersion!=='1.0')) {
$sPreviousVersion = $aCurrentVersionInfo['previous'];
$this->CheckCondition(array_key_exists($sPreviousVersion, iTopDesignFormat::$aVersions),
"$sCurrentVersion: Missing $sPreviousVersion config in iTopDesignFormat.");
$aPreviousVersionInfo = iTopDesignFormat::$aVersions[$sPreviousVersion];
$this->CheckCondition(is_array($aPreviousVersionInfo),
"$sCurrentVersion: wrong $sPreviousVersion config in iTopDesignFormat.");
$this->CheckCondition(array_key_exists('previous', $aPreviousVersionInfo),
"$sCurrentVersion: Missing previous for $sPreviousVersion config in iTopDesignFormat.");
$this->TestDefinedFunction($aPreviousVersionInfo, 'go_to_previous', $sPreviousVersion, ($sPreviousVersion === '1.0'));
$this->TestDefinedFunction($aPreviousVersionInfo, 'go_to_next', $sPreviousVersion, ($sPreviousVersion === $sLatestVersion));
}
//check we have migration function from current version to next one
if (($sCurrentVersion!== $sLatestVersion)) {
$sNextVersion = $aCurrentVersionInfo['next'];
$this->CheckCondition(array_key_exists($sNextVersion, iTopDesignFormat::$aVersions),
"$sCurrentVersion: Missing $sNextVersion config in iTopDesignFormat.");
$aNextVersionInfo = iTopDesignFormat::$aVersions[$sNextVersion];
$this->CheckCondition(is_array($aNextVersionInfo),
"$sCurrentVersion: wrong $sNextVersion config in iTopDesignFormat.");
$this->CheckCondition(array_key_exists('previous', $aNextVersionInfo),
"$sCurrentVersion: Missing previous for $sNextVersion config in iTopDesignFormat.");
$this->TestDefinedFunction($aNextVersionInfo, 'go_to_previous', $sNextVersion, ($sNextVersion === '1.0'));
$this->TestDefinedFunction($aNextVersionInfo, 'go_to_next', $sNextVersion, ($sNextVersion === $sLatestVersion));
}
}
catch(Exception $e)
{
$aErrors[] = $e->getMessage();
}
}
if (count($aErrors)!=0)
{
$sMsg = "Issue with conversion functions:\n";
$sMsg .= implode("\n", $aErrors);
$this->fail($sMsg);
}
else
{
$this->assertTrue(true);
}
}
private function CheckCondition($bCondition, $sMsg)
{
if ($bCondition === false)
{
throw new \Exception($sMsg);
}
}
private function TestDefinedFunction($aCurrentVersionInfo, $sFunctionKey, $sVersion, $bNullFunction=false)
{
$sInfo = json_encode($aCurrentVersionInfo, true);
$this->CheckCondition(array_key_exists($sFunctionKey, $aCurrentVersionInfo), "Missing $sFunctionKey in $sVersion config in iTopDesignFormat: " . $sInfo);
//echo $aCurrentVersionInfo[$sFunctionKey].'\n';
if ($bNullFunction === false)
{
$oReflectionClass = new \ReflectionClass(iTopDesignFormat::class);
$this->CheckCondition($oReflectionClass->hasMethod($aCurrentVersionInfo[$sFunctionKey]), "wrong go_to_previous function '".$aCurrentVersionInfo[$sFunctionKey]."'' for $sVersion config in iTopDesignFormat." . $sInfo);
}
else
{
$this->CheckCondition(is_null($aCurrentVersionInfo[$sFunctionKey]), "$sVersion $sFunctionKey function should be null");
}
}
public function GetDataModelFiles($sFolder)
{
$aDataModelFiles = array();
if (is_dir($sFolder))
{
foreach (glob($sFolder."/*") as $sPath)
{
if (is_dir($sPath))
{
$aDataModelFiles = array_merge($aDataModelFiles, $this->GetDataModelFiles($sPath));
}
else if (preg_match("/datamodel\..*\.xml/", basename($sPath)))
{
$aDataModelFiles[] = $sPath;
}
}
}
return $aDataModelFiles;
}
}

View File

@@ -1,101 +0,0 @@
<?php
namespace Combodo\iTop\Test\UnitTest\ReleaseChecklist;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use iTopDesignFormat;
/**
* Class iTopDesignFormatChecklistTest
* Ticket 3053 - Check XML conversion methods
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @backupGlobals disabled
*
* @covers iTopDesignFormat
*
* @package Combodo\iTop\Test\UnitTest\Setup
*/
class TestForITopDesignFormatClass extends ItopTestCase
{
protected function setUp()
{
parent::setUp();
require_once APPROOT.'setup/modelfactory.class.inc.php';
require_once APPROOT.'setup/itopdesignformat.class.inc.php';
}
/**
* release checklist step: make sure we have datamodel conversion functions for new iTop version
*/
public function testCurrentVersion_DataModelConversionFunctions()
{
$aDatamodelCurrentVersions = array();
$aDataModelFiles = $this->GetDataModelFiles(APPROOT.'/datamodels');
//retrieve current XML version in datamoldels files
foreach ($aDataModelFiles as $sDataModelFile)
{
if (preg_match('/itop_design .* version="([\d\.]*)"/', file_get_contents($sDataModelFile), $aMatches))
{
$sVersion = $aMatches[1];
if (!array_key_exists($sVersion, $aDatamodelCurrentVersions))
{
$aDatamodelCurrentVersions[$sVersion] = $sVersion;
}
}
}
//make sure there is only one found
$this->assertTrue(is_array($aDatamodelCurrentVersions));
$this->assertEquals(1, count($aDatamodelCurrentVersions), "Found too much XML versions: " . json_encode($aDatamodelCurrentVersions));
//check we have migration function from new version to previous one
$sCurrentVersion = array_values($aDatamodelCurrentVersions)[0];
$this->assertTrue(array_key_exists($sCurrentVersion, iTopDesignFormat::$aVersions), "Release checklist: missing $sCurrentVersion config in iTopDesignFormat ");
$aCurrentVersionInfo = iTopDesignFormat::$aVersions[$sCurrentVersion];
$this->assertTrue(is_array($aCurrentVersionInfo), "Release checklist: wrong $sCurrentVersion config in iTopDesignFormat ");
$this->assertTrue(array_key_exists('previous', $aCurrentVersionInfo), "Release checklist: missing previous for $sCurrentVersion config in iTopDesignFormat ");
$this->TestDefinedFunction($aCurrentVersionInfo, 'go_to_previous', $sCurrentVersion);
//check we have migration function from N-1 version to new one
$sPreviousVersion = $aCurrentVersionInfo['previous'];
$this->assertTrue(array_key_exists($sPreviousVersion, iTopDesignFormat::$aVersions), "Release checklist: missing $sPreviousVersion config in iTopDesignFormat ");
$aPreviousVersionInfo = iTopDesignFormat::$aVersions[$sPreviousVersion];
$this->assertTrue(is_array($aPreviousVersionInfo), "Release checklist: wrong $sPreviousVersion config in iTopDesignFormat ");
$this->assertTrue(array_key_exists('previous', $aPreviousVersionInfo), "Release checklist: missing previous for $sPreviousVersion config in iTopDesignFormat ");
$this->TestDefinedFunction($aPreviousVersionInfo, 'go_to_previous', $sPreviousVersion);
$this->TestDefinedFunction($aPreviousVersionInfo, 'go_to_next', $sPreviousVersion);
}
private function TestDefinedFunction($aCurrentVersionInfo, $sFunctionKey, $sVersion)
{
$sInfo = json_encode($aCurrentVersionInfo, true);
$this->assertTrue(array_key_exists($sFunctionKey, $aCurrentVersionInfo), "Release checklist: missing $sFunctionKey in $sVersion config in iTopDesignFormat: " . $sInfo);
echo $aCurrentVersionInfo[$sFunctionKey].'\n';
$oReflectionClass = new \ReflectionClass(iTopDesignFormat::class);
$this->assertTrue($oReflectionClass->hasMethod($aCurrentVersionInfo[$sFunctionKey]), "Release checklist: wrong go_to_previous function '".$aCurrentVersionInfo[$sFunctionKey]."'' for $sVersion config in iTopDesignFormat " . $sInfo);
}
public function GetDataModelFiles($sFolder)
{
$aDataModelFiles = array();
if (is_dir($sFolder))
{
foreach (glob($sFolder."/*") as $sPath)
{
if (is_dir($sPath))
{
$aDataModelFiles = array_merge($aDataModelFiles, $this->GetDataModelFiles($sPath));
}
else if (preg_match("/datamodel\..*\.xml/", basename($sPath)))
{
$aDataModelFiles[] = $sPath;
}
}
}
return $aDataModelFiles;
}
}