Source
xxxxxxxxxx
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
use PHPUnit\Framework\TestCase;
class CUpdateIntervalParserTest extends TestCase {
/**
* An array of update intervals and parsed results.
*/
public static function dataProvider() {
return [
// success
[
'333h', 0, [],
[
'rc' => CParser::PARSE_SUCCESS,
'match' => '333h',
'delay' => '333h',
'intervals' => []
]
],
[
'0;5m/1-5,09:00-18:00;wd6-7h9', 0, [],
[
'rc' => CParser::PARSE_SUCCESS,
'match' => '0;5m/1-5,09:00-18:00;wd6-7h9',
'delay' => '0',
'intervals' => [
[
'type' => ITEM_DELAY_FLEXIBLE,
'interval' => '5m/1-5,09:00-18:00',
'update_interval' => '5m',
'time_period' => '1-5,09:00-18:00'
],
['type' => ITEM_DELAY_SCHEDULING, 'interval' => 'wd6-7h9']
]
]
],
[
'{$SIMPLE_INTERVAL1}', 0, ['usermacros' => true],
[
'rc' => CParser::PARSE_SUCCESS,
'match' => '{$SIMPLE_INTERVAL1}',
'delay' => '{$SIMPLE_INTERVAL1}',
'intervals' => []
]
],
[
'{$SIMPLE_INTERVAL};{$FLEXIBLE_INTERVAL_DELAY}/{$FLEXIBLE_INTERVAL_PERIOD};{$SCHEDULING_INTERVAL}', 0,
['usermacros' => true],
[
'rc' => CParser::PARSE_SUCCESS,
'match' => '{$SIMPLE_INTERVAL};{$FLEXIBLE_INTERVAL_DELAY}/{$FLEXIBLE_INTERVAL_PERIOD};'.
'{$SCHEDULING_INTERVAL}',
'delay' => '{$SIMPLE_INTERVAL}',
'intervals' => [
[
'type' => ITEM_DELAY_FLEXIBLE,
'interval' => '{$FLEXIBLE_INTERVAL_DELAY}/{$FLEXIBLE_INTERVAL_PERIOD}',
'update_interval' => '{$FLEXIBLE_INTERVAL_DELAY}',
'time_period' => '{$FLEXIBLE_INTERVAL_PERIOD}'
],
[
'type' => ITEM_DELAY_SCHEDULING,
'interval' => '{$SCHEDULING_INTERVAL}'
]
]
]
],
[
'0;{$UPDATE_AT_NINE_A_M};{$UPDATE_EVERY_TEN_MINUTES}/{$ON_MONDAYS}', 0, ['usermacros' => true],
[
'rc' => CParser::PARSE_SUCCESS,
'match' => '0;{$UPDATE_AT_NINE_A_M};{$UPDATE_EVERY_TEN_MINUTES}/{$ON_MONDAYS}',
'delay' => '0',
'intervals' => [
['type' => ITEM_DELAY_SCHEDULING, 'interval' => '{$UPDATE_AT_NINE_A_M}'],