mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 15:34:12 +01:00
- add possibility to inject var using string patterns (ie: `'%env(DB_HOST)?:localhost%`) - on WriteToFile, preserve the non interpreted value when the interpreted value is kept the same - added unit tests for both behaviours - minor bugfix (default value in comment was wrong) and code readability improvements
101 lines
3.0 KiB
PHP
101 lines
3.0 KiB
PHP
<?php
|
|
/**
|
|
* Copyright (C) 2010-2020 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
|
|
* along with iTop. If not, see <http: *www.gnu.org/licenses/>
|
|
*
|
|
*/
|
|
|
|
namespace Combodo\iTop\Test\UnitTest\Core;
|
|
|
|
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
|
use Config;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* @runTestsInSeparateProcesses
|
|
* @preserveGlobalState disabled
|
|
* @backupGlobals disabled
|
|
*/
|
|
class ConfigTest extends ItopTestCase
|
|
{
|
|
protected function setUp()
|
|
{
|
|
parent::setUp();
|
|
require_once (APPROOT.'core/config.class.inc.php');
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @dataProvider ProviderPreserveVarOnWriteToFile
|
|
*
|
|
* @throws \ConfigException
|
|
* @throws \CoreException
|
|
*
|
|
*/
|
|
public function testPreserveVarOnWriteToFile($sConfigFile, $sExpectedContains, $aChanges)
|
|
{
|
|
$sTmpFile = tempnam(sys_get_temp_dir(), "target");
|
|
|
|
$oConfig = new Config($sConfigFile);
|
|
|
|
foreach ($aChanges as $key => $val)
|
|
{
|
|
$oConfig->Set($key, $val);
|
|
}
|
|
|
|
$oConfig->WriteToFile($sTmpFile);
|
|
|
|
$this->assertFileExists($sTmpFile);
|
|
$sFileContent = file_get_contents($sTmpFile);
|
|
|
|
$this->assertContains($sExpectedContains, $sFileContent);
|
|
}
|
|
|
|
public function ProviderPreserveVarOnWriteToFile()
|
|
{
|
|
return array(
|
|
'preserve var' => array(
|
|
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-var.php',
|
|
'sExpectedContains' => "'app_root_url' => 'http://' . (isset(\$_SERVER['SERVER_NAME']) ? \$_SERVER['SERVER_NAME'] : 'localhost') . '/itop/iTop/'",
|
|
'aChanges' => array(),
|
|
),
|
|
'preserve joker' => array(
|
|
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-joker.php',
|
|
'sExpectedContains' => "'app_root_url' => 'http://%server(SERVER_NAME)?:localhost%/itop/iTop/'",
|
|
'aChanges' => array(),
|
|
),
|
|
|
|
'preserve set same value' => array(
|
|
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-var.php',
|
|
'sExpectedContains' => "'app_root_url' => 'http://' . (isset(\$_SERVER['SERVER_NAME']) ? \$_SERVER['SERVER_NAME'] : 'localhost') . '/itop/iTop/'",
|
|
'aChanges' => array('app_root_url' => 'http://localhost/itop/iTop/'),
|
|
),
|
|
|
|
'overwrite var' => array(
|
|
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-var.php',
|
|
'sExpectedContains' => "'app_root_url' => 'foo",
|
|
'aChanges' => array('app_root_url' => 'foo'),
|
|
),
|
|
'overwrite joker' => array(
|
|
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-joker.php',
|
|
'sExpectedContains' => "'app_root_url' => 'foo",
|
|
'aChanges' => array('app_root_url' => 'foo'),
|
|
),
|
|
);
|
|
}
|
|
}
|