2016-11-23 04:43:35 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\Icinga\Module\Businessprocess\Storage;
|
|
|
|
|
|
|
|
|
|
use Icinga\Module\Businessprocess\Test\BaseTestCase;
|
|
|
|
|
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
|
|
|
|
|
|
|
|
|
class LegacyStorageTest extends BaseTestCase
|
|
|
|
|
{
|
2016-11-24 04:57:30 -05:00
|
|
|
private $processClass = 'Icinga\\Module\\Businessprocess\\BusinessProcess';
|
|
|
|
|
|
2016-11-23 17:03:48 -05:00
|
|
|
public function testCanBeInstantiatedWithAnEmptyConfigSection()
|
2016-11-23 04:43:35 -05:00
|
|
|
{
|
|
|
|
|
$baseClass = 'Icinga\\Module\\Businessprocess\\Storage\\LegacyStorage';
|
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
|
$baseClass,
|
2016-11-23 17:03:48 -05:00
|
|
|
new LegacyStorage($this->emptyConfigSection())
|
2016-11-23 04:43:35 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 17:03:48 -05:00
|
|
|
public function testDefaultConfigDirIsDiscoveredCorrectly()
|
2016-11-23 04:43:35 -05:00
|
|
|
{
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$this->getTestsBaseDir('config/modules/businessprocess/processes'),
|
|
|
|
|
$this->makeInstance()->getConfigDir()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 17:03:48 -05:00
|
|
|
public function testAllAvailableProcessesAreListed()
|
2016-11-23 04:43:35 -05:00
|
|
|
{
|
|
|
|
|
$keys = array_keys($this->makeInstance()->listProcesses());
|
|
|
|
|
sort($keys);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
array(
|
|
|
|
|
'broken_wrong-operator',
|
|
|
|
|
'simple_with-header',
|
|
|
|
|
'simple_without-header',
|
2016-12-09 08:03:49 -05:00
|
|
|
),
|
|
|
|
|
$keys
|
2016-11-23 04:43:35 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 17:03:48 -05:00
|
|
|
public function testHeaderTitlesAreRespectedInProcessList()
|
2016-11-23 04:43:35 -05:00
|
|
|
{
|
|
|
|
|
$keys = array_values($this->makeInstance()->listProcesses());
|
|
|
|
|
sort($keys);
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
array(
|
|
|
|
|
'Simple with header (simple_with-header)',
|
|
|
|
|
'broken_wrong-operator',
|
|
|
|
|
'simple_without-header',
|
2016-12-09 08:03:49 -05:00
|
|
|
),
|
|
|
|
|
$keys
|
2016-11-23 04:43:35 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 17:03:48 -05:00
|
|
|
public function testProcessFilenameIsReturned()
|
2016-11-23 04:43:35 -05:00
|
|
|
{
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$this->getTestsBaseDir('config/modules/businessprocess/processes/simple_with-header.conf'),
|
|
|
|
|
$this->makeInstance()->getFilename('simple_with-header')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 17:03:48 -05:00
|
|
|
public function testAnExistingProcessExists()
|
2016-11-23 04:43:35 -05:00
|
|
|
{
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$this->makeInstance()->hasProcess('simple_with-header')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 17:03:48 -05:00
|
|
|
public function testAMissingProcessIsMissing()
|
2016-11-23 04:43:35 -05:00
|
|
|
{
|
|
|
|
|
$this->assertFalse(
|
|
|
|
|
$this->makeInstance()->hasProcess('simple_with-headerx')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 17:03:48 -05:00
|
|
|
public function testAValidProcessCanBeLoaded()
|
2016-11-23 04:43:35 -05:00
|
|
|
{
|
|
|
|
|
$this->assertInstanceOf(
|
2016-11-24 04:57:30 -05:00
|
|
|
$this->processClass,
|
2016-11-23 04:43:35 -05:00
|
|
|
$this->makeInstance()->loadProcess('simple_with-header')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 17:03:48 -05:00
|
|
|
public function testProcessConfigCanBeLoadedFromAString()
|
2016-11-23 04:43:35 -05:00
|
|
|
{
|
|
|
|
|
$this->assertInstanceOf(
|
2016-11-24 04:57:30 -05:00
|
|
|
$this->processClass,
|
2016-11-23 04:43:35 -05:00
|
|
|
$this->makeInstance()->loadFromString('dummy', 'a = Host1;ping & Host2;ping')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 17:03:48 -05:00
|
|
|
public function testFullProcessSourceCanBeFetched()
|
2016-11-23 04:43:35 -05:00
|
|
|
{
|
|
|
|
|
$this->assertEquals(
|
2016-11-23 17:03:48 -05:00
|
|
|
file_get_contents(
|
|
|
|
|
$this->getTestsBaseDir(
|
|
|
|
|
'config/modules/businessprocess/processes/simple_with-header.conf'
|
|
|
|
|
)
|
|
|
|
|
),
|
2016-11-23 04:43:35 -05:00
|
|
|
$this->makeInstance()->getSource('simple_with-header')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 08:03:49 -05:00
|
|
|
public function testTitleCanBeReadFromConfig()
|
|
|
|
|
{
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'Simple with header',
|
|
|
|
|
$this->makeInstance()->loadProcess('simple_with-header')->getMetadata()->get('Title')
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 04:57:30 -05:00
|
|
|
public function testAConfiguredLoopCanBeParsed()
|
2016-11-23 04:43:35 -05:00
|
|
|
{
|
2016-11-24 04:57:30 -05:00
|
|
|
$this->assertInstanceOf(
|
|
|
|
|
$this->processClass,
|
|
|
|
|
$this->makeLoop()
|
|
|
|
|
);
|
2016-11-23 04:43:35 -05:00
|
|
|
}
|
2016-11-23 17:03:48 -05:00
|
|
|
}
|