mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-26 23:34:10 +02:00
ExtensibleSet: add and test renderer
This commit is contained in:
parent
da3b9246f1
commit
cc70193a56
@ -3,6 +3,7 @@
|
||||
namespace Icinga\Module\Director\IcingaConfig;
|
||||
|
||||
use Icinga\Exception\InvalidPropertyException;
|
||||
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
|
||||
|
||||
class ExtensibleSet
|
||||
{
|
||||
@ -89,6 +90,38 @@ class ExtensibleSet
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function renderAs($key, $prefix = ' ')
|
||||
{
|
||||
$parts = array();
|
||||
|
||||
if ($this->ownValues !== null) {
|
||||
$parts[] = c::renderKeyValue(
|
||||
$key,
|
||||
c::renderArray($this->ownValues),
|
||||
$prefix
|
||||
);
|
||||
}
|
||||
|
||||
if (! empty($this->plusValues)) {
|
||||
$parts[] = c::renderKeyOperatorValue(
|
||||
$key,
|
||||
'+=',
|
||||
c::renderArray($this->plusValues),
|
||||
$prefix
|
||||
);
|
||||
}
|
||||
if (! empty($this->minusValues)) {
|
||||
$parts[] = c::renderKeyOperatorValue(
|
||||
$key,
|
||||
'-=',
|
||||
c::renderArray($this->plusValues),
|
||||
$prefix
|
||||
);
|
||||
}
|
||||
|
||||
return implode('', $parts);
|
||||
}
|
||||
|
||||
protected function hasBeenResolved()
|
||||
{
|
||||
return $this->resolvedValues !== null;
|
||||
|
@ -132,4 +132,20 @@ class ExtensibleSetTest extends BaseTestCase
|
||||
$child->getResolvedValues()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCombinedDefinitionRendersCorrectly()
|
||||
{
|
||||
$set = new ExtensibleSet(array('pre', 'def', 'ined'));
|
||||
$set->blacklist('and', 'not', 'those');
|
||||
$set->extend('plus this');
|
||||
|
||||
$out = ' key_name = [ "pre", "def", "ined" ]' . "\n"
|
||||
. ' key_name += [ "plus this" ]' . "\n"
|
||||
. ' key_name -= [ "plus this" ]' . "\n";
|
||||
|
||||
$this->assertEquals(
|
||||
$out,
|
||||
$set->renderAs('key_name')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user