import rt 3.8.7
[freeside.git] / rt / t / web / basic.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5 use Encode;
6
7 use RT::Test tests => 24;
8 $RT::Test::SKIP_REQUEST_WORK_AROUND = 1;
9
10 my ($baseurl, $agent) = RT::Test->started_ok;
11
12 my $url = $agent->rt_base_url;
13 diag $url if $ENV{TEST_VERBOSE};
14
15 # get the top page
16 {
17     $agent->get($url);
18     is ($agent->{'status'}, 200, "Loaded a page");
19 }
20
21 # test a login
22 {
23     ok($agent->{form}->find_input('user'));
24     ok($agent->{form}->find_input('pass'));
25
26     ok($agent->{'content'} =~ /username:/i);
27     $agent->field( 'user' => 'root' );
28     $agent->field( 'pass' => 'password' );
29
30     # the field isn't named, so we have to click link 0
31     $agent->click(0);
32     is( $agent->{'status'}, 200, "Fetched the page ok");
33     ok( $agent->{'content'} =~ /Logout/i, "Found a logout link");
34 }
35
36 {
37     $agent->get($url."Ticket/Create.html?Queue=1");
38     is ($agent->{'status'}, 200, "Loaded Create.html");
39     $agent->form_number(3);
40     my $string = Encode::decode_utf8("I18N Web Testing æøå");
41     $agent->field('Subject' => "Ticket with utf8 body");
42     $agent->field('Content' => $string);
43     ok($agent->submit, "Created new ticket with $string as Content");
44     $agent->content_like( qr{$string} , "Found the content");
45     ok($agent->{redirected_uri}, "Did redirection");
46
47     {
48         my $ticket = RT::Test->last_ticket;
49         my $content = $ticket->Transactions->First->Content;
50         like(
51             $content, qr{$string},
52             'content is there, API check'
53         );
54     }
55 }
56
57 {
58     $agent->get($url."Ticket/Create.html?Queue=1");
59     is ($agent->{'status'}, 200, "Loaded Create.html");
60     $agent->form_number(3);
61
62     my $string = Encode::decode_utf8("I18N Web Testing æøå");
63     $agent->field('Subject' => $string);
64     $agent->field('Content' => "Ticket with utf8 subject");
65     ok($agent->submit, "Created new ticket with $string as Content");
66     $agent->content_like( qr{$string} , "Found the content");
67     ok($agent->{redirected_uri}, "Did redirection");
68
69     {
70         my $ticket = RT::Test->last_ticket;
71         is(
72             $ticket->Subject, $string,
73             'subject is correct, API check'
74         );
75     }
76 }
77
78 # Update time worked in hours
79 {
80     $agent->follow_link( text_regex => qr/Basics/ );
81     $agent->submit_form( form_number => 3,
82         fields => { TimeWorked => 5, 'TimeWorked-TimeUnits' => "hours" }
83     );
84
85     like ($agent->{'content'}, qr/to '300'/, "5 hours is 300 minutes");
86 }
87
88 # {{{ test an image
89
90 TODO: {
91     todo_skip("Need to handle mason trying to compile images",1);
92 $agent->get( $url."NoAuth/images/test.png" );
93 my $file = RT::Test::get_relocatable_file(
94   File::Spec->catfile(
95     qw(.. .. share html NoAuth images test.png)
96   )
97 );
98 is(
99     length($agent->content),
100     -s $file,
101     "got a file of the correct size ($file)",
102 );
103 }
104 # }}}
105
106 # {{{ Query Builder tests
107 #
108 # XXX: hey-ho, we have these tests in t/web/query-builder
109 # TODO: move everything about QB there
110
111 my $response = $agent->get($url."Search/Build.html");
112 ok( $response->is_success, "Fetched " . $url."Search/Build.html" );
113
114 # Parsing TicketSQL
115 #
116 # Adding items
117
118 # set the first value
119 ok($agent->form_name('BuildQuery'));
120 $agent->field("AttachmentField", "Subject");
121 $agent->field("AttachmentOp", "LIKE");
122 $agent->field("ValueOfAttachment", "aaa");
123 $agent->submit("AddClause");
124
125 # set the next value
126 ok($agent->form_name('BuildQuery'));
127 $agent->field("AttachmentField", "Subject");
128 $agent->field("AttachmentOp", "LIKE");
129 $agent->field("ValueOfAttachment", "bbb");
130 $agent->submit("AddClause");
131
132 ok($agent->form_name('BuildQuery'));
133
134 # get the query
135 my $query = $agent->current_form->find_input("Query")->value;
136 # strip whitespace from ends
137 $query =~ s/^\s*//g;
138 $query =~ s/\s*$//g;
139
140 # collapse other whitespace
141 $query =~ s/\s+/ /g;
142
143 is ($query, "Subject LIKE 'aaa' AND Subject LIKE 'bbb'");
144
145
146 1;