mirror of
https://github.com/Combodo/iTop.git
synced 2026-03-06 17:44:12 +01: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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user