mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-03 07:28:57 +02:00
2154 - preserve "var" in conf
- 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
This commit is contained in:
100
test/core/ConfigTest.php
Normal file
100
test/core/ConfigTest.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?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'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user