import rt 3.8.9
[freeside.git] / rt / lib / t / 03web.pl.in
1 #!@PERL@
2
3 use strict;
4 use WWW::Mechanize;
5 use HTTP::Request::Common;
6 use HTTP::Cookies;
7 use LWP;
8 use Encode;
9
10 my $cookie_jar = HTTP::Cookies->new;
11 my $agent = WWW::Mechanize->new();
12
13 # give the agent a place to stash the cookies
14
15 $agent->cookie_jar($cookie_jar);
16
17
18 # get the top page
19 my $url = "http://localhost".$RT::WebPath."/";
20 $agent->get($url);
21
22 is ($agent->{'status'}, 200, "Loaded a page");
23
24
25 # {{{ test a login
26
27 # follow the link marked "Login"
28
29 ok($agent->{form}->find_input('user'));
30
31 ok($agent->{form}->find_input('pass'));
32 ok ($agent->{'content'} =~ /username:/i);
33 $agent->field( 'user' => 'root' );
34 $agent->field( 'pass' => 'password' );
35 # the field isn't named, so we have to click link 0
36 $agent->click(0);
37 is($agent->{'status'}, 200, "Fetched the page ok");
38 ok( $agent->{'content'} =~ /Logout/i, "Found a logout link");
39
40
41
42 $agent->get($url."Ticket/Create.html?Queue=1");
43 is ($agent->{'status'}, 200, "Loaded Create.html");
44 $agent->form(3);
45 # Start with a string containing characters in latin1
46 my $string = "I18N Web Testing æøå";
47 Encode::from_to($string, 'iso-8859-1', 'utf8');
48 $agent->field('Subject' => "Foo");
49 $agent->field('Content' => $string);
50 ok($agent->submit(), "Created new ticket with $string");
51
52 ok( $agent->{'content'} =~ qr{$string} , "Found the content");
53
54 $agent->get($url."Ticket/Create.html?Queue=1");
55 is ($agent->{'status'}, 200, "Loaded Create.html");
56 $agent->form(3);
57 # Start with a string containing characters in latin1
58 my $string = "I18N Web Testing æøå";
59 Encode::from_to($string, 'iso-8859-1', 'utf8');
60 $agent->field('Subject' => $string);
61 $agent->field('Content' => "BAR");
62 ok($agent->submit(), "Created new ticket with $string");
63
64 ok( $agent->{'content'} =~ qr{$string} , "Found the content");
65
66
67
68 # }}}
69
70 # {{{ Query Builder tests
71
72 my $response = $agent->get($url."Search/Build.html");
73 ok( $response->is_success, "Fetched " . $url."Search/Build.html" );
74
75 # Parsing TicketSQL
76 #
77 # Adding items
78
79 # set the first value
80 ok($agent->form_name('BuildQuery'));
81 $agent->field("AttachmentField", "Subject");
82 $agent->field("AttachmentOp", "LIKE");
83 $agent->field("ValueOfAttachment", "aaa");
84 $agent->submit();
85
86 # set the next value
87 ok($agent->form_name('BuildQuery'));
88 $agent->field("AttachmentField", "Subject");
89 $agent->field("AttachmentOp", "LIKE");
90 $agent->field("ValueOfAttachment", "bbb");
91 $agent->submit();
92
93 ok($agent->form_name('BuildQuery'));
94
95 # get the query
96 my $query = $agent->current_form->find_input("Query")->value;
97 # strip whitespace from ends
98 $query =~ s/^\s*//g;
99 $query =~ s/\s*$//g;
100
101 # collapse other whitespace
102 $query =~ s/\s+/ /g;
103
104 is ($query, "Subject LIKE 'aaa' AND Subject LIKE 'bbb'");
105
106 # - new items go one level down
107 # - add items at currently selected level
108 # - if nothing is selected, add at end, one level down
109 #
110 # move left
111 # - error if nothing selected
112 # - same item should be selected after move
113 # - can't move left if you're at the top level
114 #
115 # move right
116 # - error if nothing selected
117 # - same item should be selected after move
118 # - can always move right (no max depth...should there be?)
119 #
120 # move up
121 # - error if nothing selected
122 # - same item should be selected after move
123 # - can't move up if you're first in the list
124 #
125 # move down
126 # - error if nothing selected
127 # - same item should be selected after move
128 # - can't move down if you're last in the list
129 #
130 # toggle
131 # - error if nothing selected
132 # - change all aggregators in the grouping
133 # - don't change any others
134 #
135 # delete
136 # - error if nothing selected
137 # - delete currently selected item
138 # - delete all children of a grouping
139 # - if delete leaves a node with no children, delete that, too
140 # - what should be selected?
141 #
142 # Clear
143 # - clears entire query
144 # - clears it from the session, too
145
146 # }}}
147
148 use File::Find;
149 find ( \&wanted , 'html/');
150
151 sub wanted {
152         -f  && /\.html$/ && $_ !~ /Logout.html$/  && test_get($File::Find::name);
153 }       
154
155 sub test_get {
156         my $file = shift;
157
158
159         $file =~ s#^html/##; 
160         ok ($agent->get("$url/$file", "GET $url/$file"));
161         is ($agent->{'status'}, 200, "Loaded $file");
162 #        ok( $agent->{'content'} =~ /Logout/i, "Found a logout link on $file ");
163         ok( $agent->{'content'} !~ /Not logged in/i, "Still logged in for  $file");
164         ok( $agent->{'content'} !~ /System error/i, "Didn't get a Mason compilation error on $file");
165         
166 }
167
168 # }}}
169
170 1;