fix A/R report
[freeside.git] / bin / fetch_pages
1 #!/usr/bin/perl
2
3 use strict;
4 use WWW::Mechanize;
5 use Getopt::Std;
6 use File::chdir;
7 use URI;
8 use File::Slurp qw(write_file);
9
10 my %opt;
11 getopts('d:h:u:p:', \%opt);
12 die usage() unless ($opt{d} and $opt{u} and $opt{p});
13 my $host = $opt{h} || 'http://localhost/freeside';
14
15 my $mech = WWW::Mechanize->new( autocheck => 0 );
16 $mech->get("$host/index.html");
17 $mech->submit_form(
18   with_fields => {
19     credential_0 => $opt{u},
20     credential_1 => $opt{p}
21   }
22 );
23
24 my @tests = <>;
25
26 mkdir($opt{d}) unless -d $opt{d};
27 push @CWD, $opt{d};
28
29 while (my $path = shift @tests) {
30   if ($path =~ /^#(.*)/) {
31     print "$1 - skipped\n";
32     next;
33   }
34   my $uri = URI->new("$host/$path");
35   print $uri->path;
36   my $response = $mech->get($uri);
37   print " - " . $response->code . "\n";
38   if ($response->is_success) {
39     local $CWD;
40     my @dirs = $uri->path_segments;
41     my $file = pop @dirs;
42     foreach my $dir (@dirs) {
43       mkdir $dir unless -d $dir;
44       push @CWD, $dir;
45     }
46     write_file($file, {binmode => ':utf8'}, $response->decoded_content);
47   }
48 }
49
50 sub usage {
51   "Usage: fetch_pages -d directory -u username -p password [ -h hostname ]\n\n";
52 }
53
54 =head1 NAME
55
56 fetch_pages - a testing tool for UI changes
57
58 =head1 USAGE
59
60 fetch_pages -d before_change -u myuser -p mypass list_of_tests
61 git checkout newbranch
62 make install; apache2ctl restart
63 fetch_pages -d after_change -u myuser -p mypass list_of_tests
64 diff -ur before_change/ after_change/ |diffstat
65
66 =head1 ARGUMENTS
67
68 -d: the directory to put the files in. Required.
69
70 -u: the username to use with the Freeside web interface. Required.
71
72 -p: the password. Required.
73
74 -h: the URL prefix for the Freeside server. Defaults to
75 "http://localhost/freeside".
76
77 The list of tests can be in a file specified after all arguments, or passed
78 to stdin.
79
80 =cut