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