lsfilter: Add support for non-timestamp date formats
[ninja.git] / test / unit_test / tests / livestatus_Test.php
blobfc4ed7ecaf3ad9646865ee6990d7a421a8a9a5f2
1 <?php
2 /**
3 * @package NINJA
4 * @author op5
5 * @license GPL
6 */
7 class Livestatus_Test extends PHPUnit_Framework_TestCase {
8 public function setUp() {
9 Auth::instance(array('session_key' => false))->force_user(new Op5User_AlwaysAuth());
10 $this->ls = Livestatus::instance();
11 $this->assertTrue(is_object($this->ls), 'created livestatus object');
12 $this->lsb = $this->ls->getBackend();
13 $this->assertTrue(is_object($this->lsb), 'fetched livestatus backend');
16 public function test_basic_filter() {
17 # basic filter 1
18 $filter = array('name' => 'test');
19 $expect = 'Filter: name = test';
20 $filter = chop($this->lsb->getQueryFilter($filter));
21 $this->assertTrue($filter === $expect, "basic filter 1: \nexpect:\n".$expect."\n\ngot:\n".$filter);
23 # basic filter 2
24 $filter = array('name' => array('!=' => 'test'));
25 $expect = 'Filter: name != test';
26 $filter = chop($this->lsb->getQueryFilter($filter));
27 $this->assertTrue($filter === $expect, "basic filter 2: \nexpect:\n".$expect."\n\ngot:\n".$filter);
29 # basic filter 3
30 $filter = "";
31 $expect = '';
32 $filter = chop($this->lsb->getQueryFilter($filter));
33 $this->assertTrue($filter === $expect, "basic filter 3: \nexpect:\n".$expect."\n\ngot:\n".$filter);
35 # basic filter 4
36 $filter = array('', 'num_hosts' => array('>' => 0));
37 $expect = 'Filter: num_hosts > 0';
38 $filter = chop($this->lsb->getQueryFilter($filter));
39 $this->assertTrue($filter === $expect, "basic filter 4: \nexpect:\n".$expect."\n\ngot:\n".$filter);
42 public function test_and_filter() {
43 # and filter 1
44 $filter = $filter = array(
45 'name' => array('-and' => array( 'test1' ) )
47 $expect = "Filter: name = test1";
48 $filter = chop($this->lsb->getQueryFilter($filter));
49 $this->assertTrue($filter === $expect, "and filter 1: \nexpect:\n".$expect."\n\ngot:\n".$filter);
51 # and filter 2
52 $filter = array( 'host_has_been_checked' => 1, 'host_state' => 0 );
53 $expect = "Filter: host_has_been_checked = 1\nFilter: host_state = 0\nAnd: 2";
54 $filter = chop($this->lsb->getQueryFilter($filter));
55 $this->assertTrue($filter === $expect, "and filter 2: \nexpect:\n".$expect."\n\ngot:\n".$filter);
57 # and filter 3
58 $filter = array(
59 '-and' => array(
60 array( 'host_has_been_checked' => 1, 'host_state' => 0 ),
61 array( 'has_been_checked' => 1, 'state' => 3 )
64 $expect = "Filter: host_has_been_checked = 1\nFilter: host_state = 0\nAnd: 2\nFilter: has_been_checked = 1\nFilter: state = 3\nAnd: 2\nAnd: 2";
65 $filter = chop($this->lsb->getQueryFilter($filter));
66 $this->assertTrue($filter === $expect, "and filter 3: \nexpect:\n".$expect."\n\ngot:\n".$filter);
69 public function test_or_filter() {
70 # or filter 1
71 $filter = $filter = array(
72 'name' => array('-or' => array( 'test1', 'test2' ) )
74 $expect = "Filter: name = test1\nFilter: name = test2\nOr: 2";
75 $filter = chop($this->lsb->getQueryFilter($filter));
76 $this->assertTrue($filter === $expect, "or filter 1: \nexpect:\n".$expect."\n\ngot:\n".$filter);
78 # or filter 2
79 $filter = $filter = array(
80 'name' => array('-or' => array(
81 'test1',
82 array( '!=' => 'test2')
86 $expect = "Filter: name = test1\nFilter: name != test2\nOr: 2";
87 $filter = chop($this->lsb->getQueryFilter($filter));
88 $this->assertTrue($filter === $expect, "or filter 2: \nexpect:\n".$expect."\n\ngot:\n".$filter);
90 # or filter 3
91 $filter = $filter = array(
92 '-or' => array('name1' => 'test1',
93 'name2' => 'test2')
95 $expect = "Filter: name1 = test1\nFilter: name2 = test2\nOr: 2";
96 $filter = chop($this->lsb->getQueryFilter($filter));
97 $this->assertTrue($filter === $expect, "or filter 3: \nexpect:\n".$expect."\n\ngot:\n".$filter);
99 # or filter 4
100 $filter = $filter = array(
101 '-or' => array('name1' => 'test1',
102 'name2' => array('!=' => 'test2'))
104 $expect = "Filter: name1 = test1\nFilter: name2 != test2\nOr: 2";
105 $filter = chop($this->lsb->getQueryFilter($filter));
106 $this->assertTrue($filter === $expect, "or filter 4: \nexpect:\n".$expect."\n\ngot:\n".$filter);