2013-06-03 15:34:57 +02:00
|
|
|
<?php
|
2013-07-10 11:40:48 +02:00
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2013-06-03 15:34:57 +02:00
|
|
|
namespace Tests\Icinga\Application;
|
2013-07-10 11:40:48 +02:00
|
|
|
|
2014-04-10 10:32:50 +02:00
|
|
|
use Icinga\Test\BaseTestCase;
|
2014-08-27 15:51:49 +02:00
|
|
|
use Icinga\Application\Config as IcingaConfig;
|
2013-07-10 11:40:48 +02:00
|
|
|
|
2014-04-10 10:32:50 +02:00
|
|
|
class ConfigTest extends BaseTestCase
|
2013-06-03 15:34:57 +02:00
|
|
|
{
|
2013-08-12 15:02:25 +02:00
|
|
|
/**
|
|
|
|
* Set up config dir
|
|
|
|
*/
|
2013-07-10 11:40:48 +02:00
|
|
|
public function setUp()
|
2013-06-03 15:34:57 +02:00
|
|
|
{
|
2014-04-11 15:31:29 +02:00
|
|
|
parent::setUp();
|
|
|
|
$this->configDir = IcingaConfig::$configDir;
|
2014-04-23 15:44:26 +02:00
|
|
|
IcingaConfig::$configDir = dirname(__FILE__) . '/ConfigTest/files';
|
2013-06-03 15:34:57 +02:00
|
|
|
}
|
|
|
|
|
2014-04-11 15:31:29 +02:00
|
|
|
/**
|
|
|
|
* Reset config dir
|
|
|
|
*/
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
IcingaConfig::$configDir = $this->configDir;
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:40:48 +02:00
|
|
|
public function testAppConfig()
|
2013-06-03 15:34:57 +02:00
|
|
|
{
|
2014-04-25 16:39:54 +02:00
|
|
|
$config = IcingaConfig::app('config', true);
|
2013-08-12 15:02:25 +02:00
|
|
|
$this->assertEquals(1, $config->logging->enable, 'Unexpected value retrieved from config file');
|
2013-07-10 11:40:48 +02:00
|
|
|
// Test non-existent property where null is the default value
|
2013-08-12 15:02:25 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
null,
|
|
|
|
$config->logging->get('disable'),
|
|
|
|
'Unexpected default value for non-existent properties'
|
|
|
|
);
|
2013-07-10 11:40:48 +02:00
|
|
|
// Test non-existent property using zero as the default value
|
|
|
|
$this->assertEquals(0, $config->logging->get('disable', 0));
|
|
|
|
// Test retrieve full section
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'disable' => 1,
|
|
|
|
'db' => array(
|
|
|
|
'user' => 'user',
|
|
|
|
'password' => 'password'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
$config->backend->toArray()
|
|
|
|
);
|
|
|
|
// Test non-existent section using 'default' as default value
|
|
|
|
$this->assertEquals('default', $config->get('magic', 'default'));
|
|
|
|
// Test sub-properties
|
|
|
|
$this->assertEquals('user', $config->backend->db->user);
|
|
|
|
// Test non-existent sub-property using 'UTF-8' as the default value
|
|
|
|
$this->assertEquals('UTF-8', $config->backend->db->get('encoding', 'UTF-8'));
|
|
|
|
// Test invalid property names using false as default value
|
|
|
|
$this->assertEquals(false, $config->backend->get('.', false));
|
|
|
|
$this->assertEquals(false, $config->backend->get('db.', false));
|
|
|
|
$this->assertEquals(false, $config->backend->get('.user', false));
|
|
|
|
// Test retrieve array of sub-properties
|
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'user' => 'user',
|
|
|
|
'password' => 'password'
|
|
|
|
),
|
|
|
|
$config->backend->db->toArray()
|
|
|
|
);
|
|
|
|
// Test singleton
|
2014-04-25 16:39:54 +02:00
|
|
|
$this->assertEquals($config, IcingaConfig::app('config'));
|
2013-07-10 11:40:48 +02:00
|
|
|
$this->assertEquals(array('logging', 'backend'), $config->keys());
|
|
|
|
$this->assertEquals(array('enable'), $config->keys('logging'));
|
2013-06-03 15:34:57 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:40:48 +02:00
|
|
|
public function testAppExtraConfig()
|
2013-06-03 15:34:57 +02:00
|
|
|
{
|
2014-04-25 16:39:54 +02:00
|
|
|
$extraConfig = IcingaConfig::app('extra', true);
|
2013-07-10 11:40:48 +02:00
|
|
|
$this->assertEquals(1, $extraConfig->meta->version);
|
|
|
|
$this->assertEquals($extraConfig, IcingaConfig::app('extra'));
|
2013-06-03 15:34:57 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:40:48 +02:00
|
|
|
public function testModuleConfig()
|
2013-06-03 15:34:57 +02:00
|
|
|
{
|
2014-04-25 16:39:54 +02:00
|
|
|
$moduleConfig = IcingaConfig::module('amodule', 'config', true);
|
2013-07-10 11:40:48 +02:00
|
|
|
$this->assertEquals(1, $moduleConfig->menu->get('breadcrumb'));
|
|
|
|
$this->assertEquals($moduleConfig, IcingaConfig::module('amodule'));
|
2013-06-03 15:34:57 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:40:48 +02:00
|
|
|
public function testModuleExtraConfig()
|
|
|
|
{
|
2014-04-25 16:39:54 +02:00
|
|
|
$moduleExtraConfig = IcingaConfig::module('amodule', 'extra', true);
|
2013-07-10 11:40:48 +02:00
|
|
|
$this->assertEquals(
|
|
|
|
'inetOrgPerson',
|
|
|
|
$moduleExtraConfig->ldap->user->get('ldap_object_class')
|
|
|
|
);
|
|
|
|
$this->assertEquals($moduleExtraConfig, IcingaConfig::module('amodule', 'extra'));
|
|
|
|
}
|
2013-06-03 15:34:57 +02:00
|
|
|
}
|