Files
iTop/test/integration/iTopModulesPhpVersionChecklistTest.php
Pierre Goiffon b360514646 Merge remote-tracking branch 'origin/support/2.7' into support/3.0
# Conflicts:
#	application/displayblock.class.inc.php
#	application/ui.extkeywidget.class.inc.php
#	application/utils.inc.php
#	approot.inc.php
#	core/config.class.inc.php
#	css/css-variables.scss
#	datamodels/2.x/authent-cas/module.authent-cas.php
#	datamodels/2.x/authent-external/module.authent-external.php
#	datamodels/2.x/authent-ldap/module.authent-ldap.php
#	datamodels/2.x/authent-local/module.authent-local.php
#	datamodels/2.x/combodo-db-tools/module.combodo-db-tools.php
#	datamodels/2.x/itop-attachments/module.itop-attachments.php
#	datamodels/2.x/itop-backup/module.itop-backup.php
#	datamodels/2.x/itop-bridge-virtualization-storage/module.itop-bridge-virtualization-storage.php
#	datamodels/2.x/itop-change-mgmt-itil/module.itop-change-mgmt-itil.php
#	datamodels/2.x/itop-change-mgmt/module.itop-change-mgmt.php
#	datamodels/2.x/itop-config-mgmt/module.itop-config-mgmt.php
#	datamodels/2.x/itop-config/module.itop-config.php
#	datamodels/2.x/itop-core-update/module.itop-core-update.php
#	datamodels/2.x/itop-datacenter-mgmt/module.itop-datacenter-mgmt.php
#	datamodels/2.x/itop-endusers-devices/module.itop-endusers-devices.php
#	datamodels/2.x/itop-files-information/module.itop-files-information.php
#	datamodels/2.x/itop-full-itil/module.itop-full-itil.php
#	datamodels/2.x/itop-hub-connector/module.itop-hub-connector.php
#	datamodels/2.x/itop-incident-mgmt-itil/module.itop-incident-mgmt-itil.php
#	datamodels/2.x/itop-knownerror-mgmt/module.itop-knownerror-mgmt.php
#	datamodels/2.x/itop-portal-base/module.itop-portal-base.php
#	datamodels/2.x/itop-portal/module.itop-portal.php
#	datamodels/2.x/itop-problem-mgmt/module.itop-problem-mgmt.php
#	datamodels/2.x/itop-profiles-itil/module.itop-profiles-itil.php
#	datamodels/2.x/itop-request-mgmt-itil/module.itop-request-mgmt-itil.php
#	datamodels/2.x/itop-request-mgmt/module.itop-request-mgmt.php
#	datamodels/2.x/itop-service-mgmt-provider/module.itop-service-mgmt-provider.php
#	datamodels/2.x/itop-service-mgmt/module.itop-service-mgmt.php
#	datamodels/2.x/itop-sla-computation/module.itop-sla-computation.php
#	datamodels/2.x/itop-storage-mgmt/module.itop-storage-mgmt.php
#	datamodels/2.x/itop-tickets/module.itop-tickets.php
#	datamodels/2.x/itop-virtualization-mgmt/module.itop-virtualization-mgmt.php
#	datamodels/2.x/itop-welcome-itil/module.itop-welcome-itil.php
#	datamodels/2.x/version.xml
#	lib/composer/autoload_classmap.php
#	lib/composer/autoload_static.php
#	lib/composer/installed.php
#	setup/modelfactory.class.inc.php
#	setup/setuputils.class.inc.php
#	test/integration/iTopModulesPhpVersionChecklistTest.php
2022-02-08 13:18:50 +01:00

108 lines
3.2 KiB
PHP

<?php
/**
* Copyright (C) 2013-2021 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;
/**
* @group itop-community
*
* @package Combodo\iTop\Test\UnitTest\Setup
*/
class iTopModulesPhpVersionIntegrationTest extends ItopTestCase {
/**
* We had a problem when version was switched from 2.8.0 to 3.0.0, so this test aims to detect such problems
*
* @param string $sVersion
* @param string $sExpectedMinVersion if null the test will expects an exception to occur
*
* @throws \Exception
* @since 3.0.0
* @dataProvider GetItopMinorVersionProvider
*/
public function testGetItopMinorVersion($sVersion, $sExpectedMinVersion) {
if (is_null($sExpectedMinVersion)) {
$this->expectException(\Exception::class);
}
$sActualMinVersion = \utils::GetItopMinorVersion($sVersion);
if (!is_null($sExpectedMinVersion)) {
$this->assertEquals($sExpectedMinVersion, $sActualMinVersion);
}
}
public function GetItopMinorVersionProvider() {
return [['2.8.0', '2.8'], ['3.0.0', '3.0'], ['3.', null], ['3', null]];
}
/**
* @param string $sPhpFile iTop module file
*
* @return string module version
*/
private function GetItopModuleVersion(string $sPhpFile): ?string {
$sModulePath = realpath($sPhpFile);
$sModuleFileName = basename($sModulePath);
$sModuleName = preg_replace('/[^.]+\.([^.]+)\.php/', '$1', $sModuleFileName);
$sFileContent = file_get_contents($sPhpFile);
preg_match(
"#'$sModuleName/([^']+)'#",
$sFileContent,
$matches
);
return $matches[1] ?? '';
}
/**
* Verify if the datamodel.*.xml files refer to the current itop version
* This is an integration test
*
* @group skipPostBuild
* @uses utils::GetItopMinorVersion()
*
* @since 2.7.7 3.0.1 3.1.0 N°4714 uses new {@link ITOP_CORE_VERSION} constant
*/
public function testITopModulesPhpVersion(): void {
if (is_dir(APPROOT.'datamodels/2.x')) {
$DatamodelsPath = APPROOT.'datamodels/2.x';
} elseif (is_dir(APPROOT.'datamodels/1.x')) {
$DatamodelsPath = APPROOT.'datamodels/1.x';
} else {
throw new \Exception('Cannot local the datamodels directory');
}
require_once APPROOT.'core/config.class.inc.php';
$sPath = $DatamodelsPath.'/*/module.*.php';
$aPhpFiles = glob($sPath);
$sExpectedVersion = ITOP_CORE_VERSION;
$aModuleWithError = [];
foreach ($aPhpFiles as $sPhpFile) {
$sActualVersion = $this->GetItopModuleVersion($sPhpFile);
if (!preg_match($sExpectedVersion, $sActualVersion)) {
$aModuleWithError[$sPhpFile] = $sActualVersion;
}
}
self::assertEquals([], $aModuleWithError, 'Some modules have wrong versions ! They should match '.$sExpectedVersion);
}
}