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