Files
iTop/tests/php-unit-tests/unitary-tests/setup/module/iTopModulesDependencyValidationServiceTest.php

100 lines
4.0 KiB
PHP

<?php
/**
* Copyright (C) 2013-2024 Combodo SAS
* 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\Setup\Module;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use iTopModulesDependencyValidationService;
/**
* @package Combodo\iTop\Test\UnitTest\Setup
*/
class iTopModulesDependencyValidationServiceTest extends ItopTestCase {
private iTopModulesDependencyValidationService $oiTopModulesDependencyValidationService;
private array $aFilesToRemove = [];
protected function setUp(): void
{
parent::setUp();
$this->RequireOnceItopFile('setup/module/iTopModulesDependencyValidationService.php');
}
protected function tearDown(): void
{
parent::tearDown(); // TODO: Change the autogenerated stub
foreach ($this->aFilesToRemove as $sTmpFile){
@unlink($sTmpFile);
}
iTopModulesDependencyValidationService::SetInstance(null);
}
public function testListDeclaredFullnameClassesFromPhpFile()
{
$aExpected = [
'CMDBChangeOp',
'CMDBChangeOpCreate',
'CMDBChangeOpDelete',
'CMDBChangeOpSetAttribute',
'CMDBChangeOpSetAttributeScalar',
'CMDBChangeOpSetAttributeTagSet',
'CMDBChangeOpSetAttributeURL',
'CMDBChangeOpSetAttributeBlob',
'CMDBChangeOpSetAttributeOneWayPassword',
'CMDBChangeOpSetAttributeEncrypted',
'CMDBChangeOpSetAttributeText',
'CMDBChangeOpSetAttributeLongText',
'CMDBChangeOpSetAttributeHTML',
'CMDBChangeOpSetAttributeCaseLog',
'CMDBChangeOpPlugin',
'CMDBChangeOpSetAttributeLinksAddRemove',
'CMDBChangeOpSetAttributeLinksTune',
'CMDBChangeOpSetAttributeCustomFields',
'iCMDBChangeOp',
];
$this->assertEquals($aExpected, iTopModulesDependencyValidationService::GetInstance()->ListDeclaredFullnameClassesFromPhpFile(APPROOT . 'core/cmdbchangeop.class.inc.php'));
}
public function testListDeclaredFullnameClassesFromAutoloadFile()
{
$aExpected = [
'Combodo\iTop\OAuthClient\Controller\AjaxOauthClientController',
'Combodo\iTop\OAuthClient\Controller\OAuthClientController',
'Combodo\iTop\OAuthClient\Service\ApplicationUIExtension',
'Combodo\iTop\OAuthClient\Service\PopupMenuExtension',
];
$this->assertEquals($aExpected, iTopModulesDependencyValidationService::GetInstance()->ListDeclaredFullnameClassesFromPhpFile(APPROOT . 'datamodels/2.x/itop-oauth-client/vendor/autoload.php'));
}
public function testGetFirstFoundDepsUID() {
$sOutput=<<<TXT
/var/www/html/Professional-3.2.1-16428/web/datamodels/2.x/authent-token/src/Hook/MyAccountSectionTabContentExtension.php:Combodo\iTop\MyAccount\Hook\iMyAccountTabContentExtension
TXT;
$this->assertEquals('Combodo\iTop\MyAccount\Hook\iMyAccountTabContentExtension', iTopModulesDependencyValidationService::GetInstance()->GetFirstFoundDepsUID($sOutput));
$sOutput=<<<TXT
/var/www/html/Professional-3.2.1-16428/web/datamodels/2.x/authent-token/src/Hook/MyAccountSectionTabContentExtension.php:Combodo\iTop\MyAccount\Hook\iMyAccountTabContentExtension
/var/www/html/Professional-3.2.1-16428/web/datamodels/2.x/authent-token/src/Hook/MyAccountSectionTabContentExtension2.php:Combodo\iTop\MyAccount\Hook\iMyAccountTabContentExtension2
/var/www/html/Professional-3.2.1-16428/web/datamodels/2.x/authent-token/src/Hook/MyAccountSectionTabContentExtension3.php:Combodo\iTop\MyAccount\Hook\iMyAccountTabContentExtension3
TXT;
$this->assertEquals('Combodo\iTop\MyAccount\Hook\iMyAccountTabContentExtension', iTopModulesDependencyValidationService::GetInstance()->GetFirstFoundDepsUID($sOutput));
}
}