mirror of
https://github.com/opnsense/core.git
synced 2026-02-03 20:39:42 -05:00
tests: restructure ConfigTest to allow for multiple test files
And add the failing test for the upcoming fix.
This commit is contained in:
parent
f372161b4c
commit
80d87f717b
4 changed files with 46 additions and 5 deletions
3
plist
3
plist
|
|
@ -1029,7 +1029,8 @@
|
|||
/usr/local/opnsense/mvc/script/run_migrations.php
|
||||
/usr/local/opnsense/mvc/script/run_validations.php
|
||||
/usr/local/opnsense/mvc/tests/app/config/config.php
|
||||
/usr/local/opnsense/mvc/tests/app/library/OPNsense/Core/ConfigConfig/backup/config.xml
|
||||
/usr/local/opnsense/mvc/tests/app/library/OPNsense/Core/ConfigConfig/backup/array.xml
|
||||
/usr/local/opnsense/mvc/tests/app/library/OPNsense/Core/ConfigConfig/backup/object.xml
|
||||
/usr/local/opnsense/mvc/tests/app/library/OPNsense/Core/ConfigTest.php
|
||||
/usr/local/opnsense/mvc/tests/app/models/OPNsense/ACL/AclConfig/config.xml
|
||||
/usr/local/opnsense/mvc/tests/app/models/OPNsense/ACL/AclTest.php
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<opnsense>
|
||||
<dhcpdv6>
|
||||
<lan>
|
||||
<ramode>disabled</ramode>
|
||||
</lan>
|
||||
</dhcpdv6>
|
||||
</opnsense>
|
||||
|
|
@ -43,19 +43,19 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
|
|||
/**
|
||||
* test construct
|
||||
*/
|
||||
public function testCanBeCreated()
|
||||
public function testCanBeArray()
|
||||
{
|
||||
self::cleanupTestFiles();
|
||||
|
||||
// switch config to test set for this type
|
||||
(new AppConfig())->update('application.configDir', self::$configDir);
|
||||
(new AppConfig())->update('application.configDefault', self::$configDir . '/backup/array.xml');
|
||||
Config::getInstance()->forceReload();
|
||||
|
||||
$this->assertNotEmpty(Config::getInstance()->toArray(['rule']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCanBeCreated
|
||||
* @depends testCanBeArray
|
||||
*/
|
||||
public function test_to_from_array()
|
||||
{
|
||||
|
|
@ -69,7 +69,39 @@ class ConfigTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
$cnf->fromArray($test);
|
||||
|
||||
$this->assertEquals(file_get_contents(self::$configDir . '/backup/config.xml'), (string)$cnf);
|
||||
$this->assertEquals(file_get_contents(self::$configDir . '/backup/array.xml'), (string)$cnf);
|
||||
}
|
||||
|
||||
/**
|
||||
* test construct
|
||||
*/
|
||||
public function testCanBeObject()
|
||||
{
|
||||
self::cleanupTestFiles();
|
||||
|
||||
(new AppConfig())->update('application.configDir', self::$configDir);
|
||||
(new AppConfig())->update('application.configDefault', self::$configDir . '/backup/object.xml');
|
||||
Config::getInstance()->forceReload();
|
||||
|
||||
$this->assertNotEmpty(Config::getInstance()->object());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCanBeObject
|
||||
*/
|
||||
public function test_to_from_object()
|
||||
{
|
||||
$cnf = Config::getInstance();
|
||||
|
||||
$ramode = (string)$cnf->object()->dhcpdv6->lan->ramode;
|
||||
|
||||
/* test that deleting items does not leave whitespace behind and closes parent */
|
||||
unset($cnf->object()->dhcpdv6->lan->ramode);
|
||||
$this->assertEquals($cnf->object()->dhcpdv6->lan->asXml(), '<lan/>');
|
||||
|
||||
/* put the node back with the previous value and check that it opens again too */
|
||||
$cnf->object()->dhcpdv6->lan->addChild('ramode', $ramode);
|
||||
$this->assertEquals(file_get_contents(self::$configDir . '/backup/object.xml'), (string)$cnf);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue