icingaweb2-module-director/test/php/library/Director/Objects/IcingaTimePeriodRangesTest.php

70 lines
1.8 KiB
PHP
Raw Normal View History

<?php
2016-02-25 18:56:39 +01:00
namespace Tests\Icinga\Modules\Director\Objects;
use Icinga\Module\Director\Objects\IcingaTimePeriodRange;
use Icinga\Module\Director\Objects\IcingaTimePeriodRanges;
use Icinga\Module\Director\Objects\IcingaTimePeriod;
2016-02-25 18:56:39 +01:00
use Icinga\Module\Director\Test\BaseTestCase;
2016-02-25 19:01:48 +01:00
class IcingaTimePeriodRangesTest extends BaseTestCase
{
2016-02-25 18:56:39 +01:00
protected $testPeriodName = '___TEST___timerange';
public function testWhetherUpdatedTimeperiodRangesAreCorrectlyStored()
{
2016-02-25 18:56:39 +01:00
$period = $this->createTestPeriod();
$newRanges = array(
'monday' => '00:00-24:00',
2016-02-25 18:56:39 +01:00
'tuesday' => '18:00-24:00',
'wednesday' => '00:00-24:00',
);
2016-02-25 18:56:39 +01:00
$period->ranges()->set($newRanges)->store();
2016-02-25 18:56:39 +01:00
$period = $this->loadTestPeriod();
$this->assertEquals(
'18:00-24:00',
$period->ranges()->get('tuesday')->timeperiod_value
);
}
2016-02-25 18:56:39 +01:00
protected function createTestPeriod()
{
$db = $this->getDb();
2016-02-25 18:56:39 +01:00
$object = IcingaTimePeriod::create(
array(
'object_name' => $this->testPeriodName,
'object_type' => 'object'
),
$db
);
$object->store();
$ranges = $object->ranges();
2016-02-25 18:56:39 +01:00
$testRanges = array(
'monday' => '00:00-24:00',
2016-02-25 18:56:39 +01:00
'tuesday' => '00:00-24:00',
'wednesday' => '00:00-24:00',
);
2016-02-25 18:56:39 +01:00
$ranges->set($testRanges);
$ranges->store();
2016-02-25 18:56:39 +01:00
return $object;
}
protected function loadTestPeriod()
{
return IcingaTimePeriod::load($this->testPeriodName, $this->getDb());
}
2016-02-25 18:56:39 +01:00
public function tearDown()
{
$db = $this->getDb();
if (IcingaTimePeriod::exists($this->testPeriodName, $db)) {
IcingaTimePeriod::load($this->testPeriodName, $db)->delete();
}
}
}