import of rt 3.0.4
[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
9 my $cookie_jar = HTTP::Cookies->new;
10 my $agent = WWW::Mechanize->new();
11
12 # give the agent a place to stash the cookies
13
14 $agent->cookie_jar($cookie_jar);
15
16
17 # get the top page
18 my $url = "http://localhost/";
19 $agent->get($url);
20
21 is ($agent->{'status'}, 200, "Loaded a page");
22
23
24 # {{{ test a login
25
26 # follow the link marked "Login"
27
28 ok($agent->{form}->find_input('user'));
29
30 ok($agent->{form}->find_input('pass'));
31 ok ($agent->{'content'} =~ /username:/i);
32 $agent->field( 'user' => 'root' );
33 $agent->field( 'pass' => 'password' );
34 # the field isn't named, so we have to click link 0
35 $agent->click(0);
36 is($agent->{'status'}, 200, "Fetched the page ok");
37 ok( $agent->{'content'} =~ /Logout/i, "Found a logout link");
38
39
40 use File::Find;
41 find ( \&wanted , 'html/');
42
43 sub wanted {
44         -f  && /\.html$/ && $_ !~ /Logout.html$/  && test_get($File::Find::name);
45 }       
46
47 sub test_get {
48         my $file = shift;
49
50
51         $file =~ s#^html/##; 
52         ok ($agent->get("$url/$file", "GET $url/$file"));
53         is ($agent->{'status'}, 200, "Loaded $file");
54         ok( $agent->{'content'} =~ /Logout/i, "Found a logout link on $file ");
55         ok( $agent->{'content'} !~ /Not logged in/i, "Still logged in for  $file");
56         ok( $agent->{'content'} !~ /System error/i, "Didn't get a Mason compilation error on $file");
57         
58 }
59
60 # }}}
61
62 1;