lsfilter: Add support for non-timestamp date formats
[ninja.git] / test / unit_test / tests / search_Test.php
blobb1b67ae841827d0fbb1424fbf20a5ac43060ebaf
1 <?php
2 /**
3 * @package NINJA
4 * @author op5
5 * @license GPL
6 */
7 class Search_Test extends PHPUnit_Framework_TestCase {
8 protected $controller = false; /* Controller to test */
10 public function setUp() {
11 global $_SESSION;
12 $_SESSION = array();
13 $this->controller = new Search_Controller();
17 * Those tests should test how the search from the ExpParser filter is converted to a live status query
19 * Tests handling the syntax of the filter shoudl be in expparser_searchfilter_Test,
20 * This is about columns and generation oh the query, and wildcard
23 /* *****
24 * Test simple table access
26 public function test_host() {
27 $this->run_test('h:kaka', array('hosts'=>'[hosts] (name ~~ "kaka" or display_name ~~ "kaka" or address ~~ "kaka" or alias ~~ "kaka" or notes ~~ "kaka")') );
29 public function test_service() {
30 $this->run_test('s:kaka', array('services'=>'[services] (description ~~ "kaka" or display_name ~~ "kaka" or notes ~~ "kaka")') );
32 public function test_hostgroups() {
33 $this->run_test('hg:kaka', array('hostgroups'=>'[hostgroups] (name ~~ "kaka" or alias ~~ "kaka")') );
35 public function test_servicegroups() {
36 $this->run_test('sg:kaka', array('servicegroups'=>'[servicegroups] (name ~~ "kaka" or alias ~~ "kaka")') );
38 public function test_status_info() {
39 $this->run_test('si:kaka', array('hosts'=>'[hosts] (plugin_output ~~ "kaka" or long_plugin_output ~~ "kaka")','services'=>'[services] (plugin_output ~~ "kaka" or long_plugin_output ~~ "kaka")') );
42 /* ******
43 * Test wildcard search
45 public function test_wildcard() {
46 $this->run_test('h:aaa%bbb', array('hosts'=>'[hosts] (name ~~ "aaa.*bbb" or display_name ~~ "aaa.*bbb" or address ~~ "aaa.*bbb" or alias ~~ "aaa.*bbb" or notes ~~ "aaa.*bbb")') );
50 /* ******
51 * Test combined host/service (services by hosts)
53 public function test_host_serivce() {
54 $this->run_test('h:kaka and s:pong', array('services'=>'[services] (description ~~ "pong" or display_name ~~ "pong" or notes ~~ "pong") and (host.name ~~ "kaka" or host.display_name ~~ "kaka" or host.address ~~ "kaka" or host.alias ~~ "kaka" or host.notes ~~ "kaka")') );
57 /* ******
58 * Test limit
60 public function test_host_limit() {
61 $this->run_test('h:kaka limit=24', array('hosts'=>'[hosts] (name ~~ "kaka" or display_name ~~ "kaka" or address ~~ "kaka" or alias ~~ "kaka" or notes ~~ "kaka")', 'limit'=>24) );
64 protected function run_test( $query, $expect ) {
65 $result = $this->controller->queryToLSFilter( $query );
66 $this->assertEquals( $result, $expect, "SearchFilter query '$query' doesn't match expected result." );