import of rt 3.0.9
[freeside.git] / rt / lib / t / 03web.pl
1 #!/usr/bin/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
71
72 use File::Find;
73 find ( \&wanted , 'html/');
74
75 sub wanted {
76         -f  && /\.html$/ && $_ !~ /Logout.html$/  && test_get($File::Find::name);
77 }       
78
79 sub test_get {
80         my $file = shift;
81
82
83         $file =~ s#^html/##; 
84         ok ($agent->get("$url/$file", "GET $url/$file"));
85         is ($agent->{'status'}, 200, "Loaded $file");
86         ok( $agent->{'content'} =~ /Logout/i, "Found a logout link on $file ");
87         ok( $agent->{'content'} !~ /Not logged in/i, "Still logged in for  $file");
88         ok( $agent->{'content'} !~ /System error/i, "Didn't get a Mason compilation error on $file");
89         
90 }
91
92 # }}}
93
94 1;