mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 19:48:49 +02:00
N°5608 - Move unit tests to a dedicated folder and start reorganizing to match iTop folder structure
This commit is contained in:
87
test/php-unit-tests/tests/setup/DBBackupTest.php
Normal file
87
test/php-unit-tests/tests/setup/DBBackupTest.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
|
||||
use CMDBSource;
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use DBBackup;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DBBackupTest extends ItopTestCase
|
||||
{
|
||||
/**
|
||||
* @throws \CoreException
|
||||
* @throws \MySQLException
|
||||
* @throws \ConfigException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
require_once(APPROOT.'setup/backup.class.inc.php');
|
||||
|
||||
// We need a connection to the DB, so let's open it !
|
||||
// We are using the default config file... as the server might not be configured for all the combination we are testing
|
||||
// For example dev env and ci env won't accept TLS connection
|
||||
$oConfigOnDisk = utils::GetConfig();
|
||||
CMDBSource::InitFromConfig($oConfigOnDisk);
|
||||
}
|
||||
|
||||
/**
|
||||
* No TLS connection = no additional CLI args !
|
||||
*
|
||||
* @throws \CoreException
|
||||
* @throws \ConfigException
|
||||
* @throws \MySQLException
|
||||
*/
|
||||
public function testGetMysqlCliTlsOptionsNoTls()
|
||||
{
|
||||
$oConfigToTest = utils::GetConfig();
|
||||
|
||||
$oConfigToTest->Set('db_tls.enabled', false);
|
||||
$sCliArgsNoTls = DBBackup::GetMysqlCliTlsOptions($oConfigToTest);
|
||||
|
||||
$this->assertEmpty($sCliArgsNoTls);
|
||||
}
|
||||
|
||||
/**
|
||||
* TLS connection configured = we need one CLI arg
|
||||
*
|
||||
* @return void
|
||||
* @throws \ConfigException
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function testGetMysqlCliTlsOptionsWithTlsNoCa()
|
||||
{
|
||||
$oConfigToTest = utils::GetConfig();
|
||||
$oConfigToTest->Set('db_tls.enabled', true);
|
||||
$sCliArgsMinCfg = DBBackup::GetMysqlCliTlsOptions($oConfigToTest);
|
||||
|
||||
// depending on the MySQL version, we would have `--ssl` or `--ssl-mode=VERIFY_CA`
|
||||
$this->assertStringStartsWith(' --ssl', $sCliArgsMinCfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* TLS connection configured + CA option = we need multiple CLI args
|
||||
*
|
||||
* @return void
|
||||
* @throws \ConfigException
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function testGetMysqlCliTlsOptionsWithTlsAndCa()
|
||||
{
|
||||
$oConfigToTest = utils::GetConfig();
|
||||
$sTestCa = 'my_test_ca';
|
||||
|
||||
$oConfigToTest->Set('db_tls.enabled', true);
|
||||
$oConfigToTest->Set('db_tls.ca', $sTestCa);
|
||||
$sCliArgsCapathCfg = DBBackup::GetMysqlCliTlsOptions($oConfigToTest);
|
||||
|
||||
$this->assertStringStartsWith(' --ssl', $sCliArgsCapathCfg);
|
||||
$this->assertStringEndsWith('--ssl-ca='.DBBackup::EscapeShellArg($sTestCa), $sCliArgsCapathCfg);
|
||||
}
|
||||
}
|
||||
68
test/php-unit-tests/tests/setup/SetupUtilsTest.php
Normal file
68
test/php-unit-tests/tests/setup/SetupUtilsTest.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Setup;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use SetupUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Class SetupUtilsTest
|
||||
*
|
||||
* @covers SetupUtils
|
||||
*
|
||||
* @since 2.7.4 N°3412
|
||||
* @package Combodo\iTop\Test\UnitTest\Setup
|
||||
*/
|
||||
class SetupUtilsTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
require_once APPROOT.'setup/setuputils.class.inc.php';
|
||||
require_once APPROOT.'setup/setuppage.class.inc.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider CheckGraphvizProvider
|
||||
*/
|
||||
public function testCheckGraphviz($sScriptPath, $iSeverity, $sLabel){
|
||||
/** @var \CheckResult $oCheck */
|
||||
$oCheck = SetupUtils::CheckGraphviz($sScriptPath);
|
||||
$this->assertEquals($iSeverity, $oCheck->iSeverity);
|
||||
$this->assertContains($sLabel, $oCheck->sLabel);
|
||||
}
|
||||
|
||||
public function CheckGraphvizProvider(){
|
||||
if (substr(PHP_OS,0,3) === 'WIN'){
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
"bash injection" => [
|
||||
"touch /tmp/toto",
|
||||
1,
|
||||
"could not be executed: Please make sure it is installed and in the path",
|
||||
],
|
||||
"command ok" => [
|
||||
"/usr/bin/whereis",
|
||||
2,
|
||||
"",
|
||||
],
|
||||
"empty command => dot by default" => [
|
||||
"",
|
||||
2,
|
||||
"",
|
||||
],
|
||||
"command failed" => [
|
||||
"/bin/ls",
|
||||
1,
|
||||
"dot could not be executed (retcode=2): Please make sure it is installed and in the path",
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.6">
|
||||
<menus>
|
||||
<menu id="WelcomeMenuLink1" xsi:type="WebPageMenuNode" _delta="define">
|
||||
<rank>100</rank>
|
||||
<parent>WelcomeMenu</parent>
|
||||
<url>$$http://fr.wikipedia.org/</url>
|
||||
</menu>
|
||||
<menu id="WelcomeMenuLink2" xsi:type="WebPageMenuNode" _delta="define">
|
||||
<rank>100</rank>
|
||||
<parent>WelcomeMenu</parent>
|
||||
<url>$$http://fr.wikipedia.org/</url>
|
||||
</menu>
|
||||
</menus>
|
||||
</itop_design>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.7">
|
||||
<menus>
|
||||
<menu id="WelcomeMenuLink1" xsi:type="WebPageMenuNode" _delta="define">
|
||||
<rank>100</rank>
|
||||
<parent>WelcomeMenu</parent>
|
||||
<url>$$http://fr.wikipedia.org/</url>
|
||||
<in_new_window>true</in_new_window>
|
||||
</menu>
|
||||
<menu id="WelcomeMenuLink2" xsi:type="WebPageMenuNode" _delta="define">
|
||||
<rank>100</rank>
|
||||
<parent>WelcomeMenu</parent>
|
||||
<url>$$http://fr.wikipedia.org/</url>
|
||||
</menu>
|
||||
</menus>
|
||||
</itop_design>
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Setup;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use DOMDocument;
|
||||
use iTopDesignFormat;
|
||||
|
||||
|
||||
/**
|
||||
* @covers iTopDesignFormat
|
||||
*
|
||||
* @since 2.7.0 N°2586
|
||||
* @package Combodo\iTop\Test\UnitTest\Setup
|
||||
*/
|
||||
class iTopDesignFormatTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
require_once APPROOT.'setup/modelfactory.class.inc.php';
|
||||
require_once APPROOT.'setup/itopdesignformat.class.inc.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers iTopDesignFormat::Convert
|
||||
* @dataProvider MigrationMethodProvider
|
||||
*
|
||||
* @param string $sTargetVersion
|
||||
* @param string $sInputXmlFileName example "1.7_to_1.6.input"
|
||||
* @param string $sExpectedXmlFileName example "1.7_to_1.6.expected"
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testMigrationMethod($sTargetVersion, $sInputXmlFileName, $sExpectedXmlFileName)
|
||||
{
|
||||
$sInputXml = $this->GetFileContent($sInputXmlFileName);
|
||||
$sExpectedXml = $this->GetFileContent($sExpectedXmlFileName);
|
||||
|
||||
$oInputDocument = new DOMDocument();
|
||||
libxml_clear_errors();
|
||||
$oInputDocument->preserveWhiteSpace = false;
|
||||
$oInputDocument->loadXML($sInputXml);
|
||||
$oInputDocument->formatOutput = true;
|
||||
$oDesignFormat = new iTopDesignFormat($oInputDocument);
|
||||
$oDesignFormat->Convert($sTargetVersion);
|
||||
|
||||
$sConvertedXml = $oInputDocument->saveXML();
|
||||
|
||||
$this->assertEquals($sExpectedXml, $sConvertedXml);
|
||||
}
|
||||
|
||||
private function GetFileContent($sFileName)
|
||||
{
|
||||
$sCurrentPath = __DIR__;
|
||||
|
||||
return file_get_contents($sCurrentPath.DIRECTORY_SEPARATOR.$sFileName.'.xml');
|
||||
}
|
||||
|
||||
public function MigrationMethodProvider()
|
||||
{
|
||||
return array(
|
||||
'1.7 to 1.6' => array('1.6', '1.7_to_1.6.input', '1.7_to_1.6.expected'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user