fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / search_simple.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => 30;
5 my ( $baseurl, $m ) = RT::Test->started_ok;
6
7 RT::Test->create_tickets(
8     { Queue   => 'General' },
9     { Subject => 'ticket foo' },
10     { Subject => 'ticket bar' },
11 );
12
13 ok( $m->login, 'logged in' );
14
15 $m->get_ok('/Search/Simple.html');
16 $m->content_lacks( 'Show Results', 'no page menu' );
17 $m->get_ok('/Search/Simple.html?q=ticket foo');
18 $m->content_contains( 'Show Results',   "has page menu" );
19 $m->title_is( 'Found 1 ticket', 'title' );
20 $m->content_contains( 'ticket foo', 'has ticket foo' );
21
22 # Test searches on custom fields
23 my $cf1 = RT::Test->load_or_create_custom_field(
24                       Name  => 'Location',
25                       Queue => 'General',
26                       Type  => 'FreeformSingle', );
27 isa_ok( $cf1, 'RT::CustomField' );
28
29 my $cf2 = RT::Test->load_or_create_custom_field(
30                       Name  => 'Server-name',
31                       Queue => 'General',
32                       Type  => 'FreeformSingle', );
33 isa_ok( $cf2, 'RT::CustomField' );
34
35 my $t = RT::Ticket->new(RT->SystemUser);
36
37 {
38   my ($id,undef,$msg) = $t->Create(
39             Queue => 'General',
40             Subject => 'Test searching CFs');
41   ok( $id, "Created ticket - $msg" );
42 }
43
44 {
45   my ($status, $msg) = $t->AddCustomFieldValue(
46                            Field => $cf1->id,
47                            Value => 'Downtown');
48   ok( $status, "Added CF value - $msg" );
49 }
50
51 {
52   my ($status, $msg) = $t->AddCustomFieldValue(
53                            Field => $cf2->id,
54                            Value => 'Proxy');
55   ok( $status, "Added CF value - $msg" );
56 }
57
58 # Regular search
59 my $search = 'cf.Location:Downtown';
60 $m->get_ok("/Search/Simple.html?q=$search");
61 $m->title_is( 'Found 1 ticket', 'Found 1 ticket' );
62 $m->text_contains( 'Test searching CFs', "Found test CF ticket with $search" );
63
64 # Case insensitive
65 $search = "cf.Location:downtown";
66 $m->get_ok("/Search/Simple.html?q=$search");
67 $m->title_is( 'Found 1 ticket', 'Found 1 ticket' );
68 $m->text_contains( 'Test searching CFs', "Found test CF ticket with $search" );
69
70 # With dash in CF name
71 $search = "cf.Server-name:Proxy";
72 $m->get_ok("/Search/Simple.html?q=$search");
73 $m->title_is( 'Found 1 ticket', 'Found 1 ticket' );
74 $m->text_contains( 'Test searching CFs', "Found test CF ticket with $search" );
75
76 # TODO more simple search tests