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