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