7 class Search_Ajax_Test
extends PHPUnit_Framework_TestCase
{
8 protected $controller = false; /* Controller to test */
10 public function setUp() {
13 $this->controller
= new Ajax_Controller();
17 * Those tests should test how the livesearch generates queries.
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
24 * Test simple table access
26 public function test_host() {
27 $this->run_test('h:kaka', array( 'hosts', 'kaka', array(
28 'columns' => array( 'name' ),
29 'filter' => array( 'name' => array( '~~' => 'kaka' ) )
32 public function test_service() {
33 $this->run_test('s:kaka', array( 'services', 'kaka', array(
34 'columns' => array( 'description', 'host_name' ),
35 'filter' => array( 'description' => array( '~~' => 'kaka' ) )
38 public function test_hostgroup() {
39 $this->run_test('hg:kaka', array( 'hostgroups', 'kaka', array(
40 'columns' => array( 'name' ),
41 'filter' => array( 'name' => array( '~~' => 'kaka' ) )
44 public function test_servicgroup() {
45 $this->run_test('sg:kaka', array( 'servicegroups', 'kaka', array(
46 'columns' => array( 'name' ),
47 'filter' => array( 'name' => array( '~~' => 'kaka' ) )
50 public function test_comment() {
51 $this->run_test('c:kaka', array( 'comments', 'kaka', array(
52 'columns' => array( 'comment_data', 'host_name' ),
53 'filter' => array( 'comment_data' => array( '~~' => 'kaka' ) )
58 * Test second parameter or
60 public function test_host_or() {
61 $this->run_test('h:kaka or boll', array( 'hosts', 'boll', array(
62 'columns' => array( 'name' ),
63 'filter' => array( 'name' => array( '~~' => 'boll' ) )
68 * Test second parameter and
70 public function test_host_and() {
71 $this->run_test('h:kaka and h:boll', array( 'hosts', 'boll', array(
72 'columns' => array( 'name' ),
73 'filter' => array( 'name' => array( '~~' => 'boll' ) )
78 * Test second parameter and different
80 public function test_host_service_and() {
81 $this->run_test('h:kaka and s:boll', array( 'services', 'boll', array(
82 'columns' => array( 'description', 'host_name' ),
83 'filter' => array( 'description' => array( '~~' => 'boll' ) )
90 public function test_host_wildcard() {
91 $this->run_test('h:kaka%boll', array( 'hosts', 'kaka%boll', array(
92 'columns' => array( 'name' ),
93 'filter' => array( 'name' => array( '~~' => 'kaka.*boll' ) )
96 public function test_host_or_wildcard() {
97 $this->run_test('h:kaka%boll or cykel%styre', array( 'hosts', 'cykel%styre', array(
98 'columns' => array( 'name' ),
99 'filter' => array( 'name' => array( '~~' => 'cykel.*styre' ) )
104 * Simple query, without h:/s:
106 public function test_simple() {
107 $this->run_test('hopp', array( 'hosts', 'hopp', array(
108 'columns' => array( 'name' ),
109 'filter' => array( 'name' => array( '~~' => 'hopp' ) )
112 public function test_simple_wildcard() {
113 $this->run_test('hopp%tjopp', array( 'hosts', 'hopp%tjopp', array(
114 'columns' => array( 'name' ),
115 'filter' => array( 'name' => array( '~~' => 'hopp.*tjopp' ) )
119 protected function run_test( $query, $expect ) {
120 $result = $this->controller
->global_search_build_filter( $query );
122 if( $expect === false && $result === false ) {
125 list( $type, $name, $settings, $options ) = $result;
127 $this->assertEquals( array( $type, $name, $options ), $expect, "SearchFilter query '$query' doesn't match expected result." );