IcingaArguments: test and fix modification tracking
This fixes related behaviour when working on CLI, API or through Sync Rules - but not web forms refs #12266
This commit is contained in:
parent
a4d6ed1b6e
commit
6258230fdb
|
@ -91,6 +91,12 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
|
|||
if ($this->arguments[$key]->hasBeenModified()) {
|
||||
$this->modified = true;
|
||||
}
|
||||
} elseif (array_key_exists($key, $this->storedArguments)) {
|
||||
$this->arguments[$key] = clone($this->storedArguments[$key]);
|
||||
$this->arguments[$key]->replaceWith($argument);
|
||||
if ($this->arguments[$key]->hasBeenModified()) {
|
||||
$this->modified = true;
|
||||
}
|
||||
} else {
|
||||
$this->add($argument);
|
||||
$this->modified = true;
|
||||
|
@ -191,8 +197,12 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
|
|||
array_keys($this->arguments),
|
||||
array_keys($arguments)
|
||||
) as $arg) {
|
||||
$this->arguments[$arg]->markForRemoval();
|
||||
$this->modified = true;
|
||||
if ($this->arguments[$arg]->hasBeenLoadedFromDb()) {
|
||||
$this->arguments[$arg]->markForRemoval();
|
||||
$this->modified = true;
|
||||
} else {
|
||||
unset($this->arguments[$arg]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
@ -336,6 +346,7 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
|
|||
unset($this->arguments[$key]);
|
||||
}
|
||||
|
||||
$this->cloneStored();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,76 @@ class IcingaCommandTest extends BaseTestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testCanBePersistedToDb()
|
||||
{
|
||||
if ($this->skipForMissingDb()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$db = $this->getDb();
|
||||
|
||||
$command = $this->newCommandWithArguments();
|
||||
|
||||
$this->assertEquals(
|
||||
$command->store($db),
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
$command->delete();
|
||||
}
|
||||
|
||||
public function testCanBeLoadedFromDb()
|
||||
{
|
||||
if ($this->skipForMissingDb()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$db = $this->getDb();
|
||||
|
||||
$name = $this->testCommandName;
|
||||
$command = $this->newCommandWithArguments($db);
|
||||
$command->store($db);
|
||||
|
||||
$command = IcingaCommand::load($name, $db);
|
||||
$this->assertEquals(
|
||||
$command->object_name,
|
||||
$name
|
||||
);
|
||||
|
||||
$command->delete();
|
||||
}
|
||||
|
||||
public function testArgumentMotificationsAreDetected()
|
||||
{
|
||||
if ($this->skipForMissingDb()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$db = $this->getDb();
|
||||
|
||||
$command = $this->newCommandWithArguments($db);
|
||||
$command->store($db);
|
||||
$command->arguments()->set('-H', 'no-host');
|
||||
$this->assertTrue($command->hasBeenModified());
|
||||
$this->assertTrue($command->store());
|
||||
$command->delete();
|
||||
}
|
||||
|
||||
protected function newCommandWithArguments()
|
||||
{
|
||||
$command = $this->command();
|
||||
$command->arguments = array(
|
||||
'-H' => '$host$',
|
||||
'-x' => (object) array(
|
||||
'required' => true,
|
||||
'value' => 'bal'
|
||||
)
|
||||
);
|
||||
|
||||
return $command;
|
||||
}
|
||||
|
||||
public function testAbsolutePathsAreDetected()
|
||||
{
|
||||
$command = $this->command();
|
||||
|
|
Loading…
Reference in New Issue