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() {
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);
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);
32 $filter = chop($this->lsb
->getQueryFilter($filter));
33 $this->assertTrue($filter === $expect, "basic filter 3: \nexpect:\n".$expect."\n\ngot:\n".$filter);
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() {
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);
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);
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() {
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);
79 $filter = $filter = array(
80 'name' => array('-or' => array(
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);
91 $filter = $filter = array(
92 '-or' => array('name1' => 'test1',
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);
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);