import rt 3.6.6
[freeside.git] / rt / lib / t / regression / 02basic_web.t
1 #!/usr/bin/perl
2
3 use strict;
4 use Test::More tests => 19;
5 use WWW::Mechanize;
6 use HTTP::Request::Common;
7 use HTTP::Cookies;
8 use LWP;
9 use Encode;
10
11 my $cookie_jar = HTTP::Cookies->new;
12 my $agent = WWW::Mechanize->new();
13
14 # give the agent a place to stash the cookies
15
16 $agent->cookie_jar($cookie_jar);
17
18 use RT;
19 RT::LoadConfig();
20 # get the top page
21 my $url = $RT::WebURL;
22 diag $url;
23 $agent->get($url);
24
25 is ($agent->{'status'}, 200, "Loaded a page");
26
27
28 # {{{ test a login
29
30 # follow the link marked "Login"
31
32 ok($agent->{form}->find_input('user'));
33
34 ok($agent->{form}->find_input('pass'));
35 ok ($agent->{'content'} =~ /username:/i);
36 $agent->field( 'user' => 'root' );
37 $agent->field( 'pass' => 'password' );
38 # the field isn't named, so we have to click link 0
39 $agent->click(0);
40 is($agent->{'status'}, 200, "Fetched the page ok");
41 ok( $agent->{'content'} =~ /Logout/i, "Found a logout link");
42
43
44
45 $agent->get($url."Ticket/Create.html?Queue=1");
46 is ($agent->{'status'}, 200, "Loaded Create.html");
47 $agent->form_number(3);
48 # Start with a string containing characters in latin1
49 my $string = "I18N Web Testing æøå";
50 Encode::from_to($string, 'iso-8859-1', 'utf8');
51 $agent->field('Subject' => "Ticket with utf8 body");
52 $agent->field('Content' => $string);
53 ok($agent->submit(), "Created new ticket with $string as Content");
54 like( $agent->{'content'}, qr{$string} , "Found the content");
55 ok($agent->{redirected_uri}, "Did redirection");
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 # Start with a string containing characters in latin1
62 my $string = "I18N Web Testing æøå";
63 Encode::from_to($string, 'iso-8859-1', 'utf8');
64 $agent->field('Subject' => $string);
65 $agent->field('Content' => "Ticket with utf8 subject");
66 ok($agent->submit(), "Created new ticket with $string as Subject");
67
68 like( $agent->{'content'}, qr{$string} , "Found the content");
69
70 # Update time worked in hours
71 $agent->follow_link( text_regex => qr/Basics/ );
72 $agent->submit_form( form_number => 3,
73     fields => { TimeWorked => 5, 'TimeWorked-TimeUnits' => "hours" }
74 );
75
76 like ($agent->{'content'}, qr/to '300'/, "5 hours is 300 minutes");
77
78 # }}}
79
80 # {{{ Query Builder tests
81
82 my $response = $agent->get($url."Search/Build.html");
83 ok( $response->is_success, "Fetched " . $url."Search/Build.html" );
84
85 # Parsing TicketSQL
86 #
87 # Adding items
88
89 # set the first value
90 ok($agent->form_name('BuildQuery'));
91 $agent->field("AttachmentField", "Subject");
92 $agent->field("AttachmentOp", "LIKE");
93 $agent->field("ValueOfAttachment", "aaa");
94 $agent->submit("AddClause");
95
96 # set the next value
97 ok($agent->form_name('BuildQuery'));
98 $agent->field("AttachmentField", "Subject");
99 $agent->field("AttachmentOp", "LIKE");
100 $agent->field("ValueOfAttachment", "bbb");
101 $agent->submit("AddClause");
102
103 ok($agent->form_name('BuildQuery'));
104
105 # get the query
106 my $query = $agent->current_form->find_input("Query")->value;
107 # strip whitespace from ends
108 $query =~ s/^\s*//g;
109 $query =~ s/\s*$//g;
110
111 # collapse other whitespace
112 $query =~ s/\s+/ /g;
113
114 is ($query, "Subject LIKE 'aaa' AND Subject LIKE 'bbb'");
115
116 # - new items go one level down
117 # - add items at currently selected level
118 # - if nothing is selected, add at end, one level down
119 #
120 # move left
121 # - error if nothing selected
122 # - same item should be selected after move
123 # - can't move left if you're at the top level
124 #
125 # move right
126 # - error if nothing selected
127 # - same item should be selected after move
128 # - can always move right (no max depth...should there be?)
129 #
130 # move up
131 # - error if nothing selected
132 # - same item should be selected after move
133 # - can't move up if you're first in the list
134 #
135 # move down
136 # - error if nothing selected
137 # - same item should be selected after move
138 # - can't move down if you're last in the list
139 #
140 # toggle
141 # - error if nothing selected
142 # - change all aggregators in the grouping
143 # - don't change any others
144 #
145 # delete
146 # - error if nothing selected
147 # - delete currently selected item
148 # - delete all children of a grouping
149 # - if delete leaves a node with no children, delete that, too
150 # - what should be selected?
151 #
152 # Clear
153 # - clears entire query
154 # - clears it from the session, too
155
156 # }}}
157
158
159 1;