N°3052 add the core/application XML files and rewrite the test for two benefits:

a - the latest XML version is currently not correlated with the the version of iTop (though it seems to be)
b - see the converted XML... that could be saved to fix the report
This commit is contained in:
rquetiez
2020-08-14 19:57:38 +02:00
parent 94ffcf4207
commit fcd4ad6872

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 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,
);
}