another useful debugging tool
authorMark Wells <mark@freeside.biz>
Wed, 1 Jul 2015 23:52:16 +0000 (16:52 -0700)
committerMark Wells <mark@freeside.biz>
Wed, 1 Jul 2015 23:52:16 +0000 (16:52 -0700)
bin/fetch_pages [new file with mode: 0755]

diff --git a/bin/fetch_pages b/bin/fetch_pages
new file mode 100755 (executable)
index 0000000..5aeca56
--- /dev/null
@@ -0,0 +1,80 @@
+#!/usr/bin/perl
+
+use strict;
+use WWW::Mechanize;
+use Getopt::Std;
+use File::chdir;
+use URI;
+use File::Slurp qw(write_file);
+
+my %opt;
+getopts('d:h:u:p:', \%opt);
+die usage() unless ($opt{d} and $opt{u} and $opt{p});
+my $host = $opt{h} || 'http://localhost/freeside';
+
+my $mech = WWW::Mechanize->new( autocheck => 0 );
+$mech->get("$host/index.html");
+$mech->submit_form(
+  with_fields => {
+    credential_0 => $opt{u},
+    credential_1 => $opt{p}
+  }
+);
+
+my @tests = <>;
+
+mkdir($opt{d}) unless -d $opt{d};
+push @CWD, $opt{d};
+
+while (my $path = shift @tests) {
+  if ($path =~ /^#(.*)/) {
+    print "$1 - skipped\n";
+    next;
+  }
+  my $uri = URI->new("$host/$path");
+  print $uri->path;
+  my $response = $mech->get($uri);
+  print " - " . $response->code . "\n";
+  if ($response->is_success) {
+    local $CWD;
+    my @dirs = $uri->path_segments;
+    my $file = pop @dirs;
+    foreach my $dir (@dirs) {
+      mkdir $dir unless -d $dir;
+      push @CWD, $dir;
+    }
+    write_file($file, {binmode => ':utf8'}, $response->decoded_content);
+  }
+}
+
+sub usage {
+  "Usage: fetch_pages -d directory -u username -p password [ -h hostname ]\n\n";
+}
+
+=head1 NAME
+
+fetch_pages - a testing tool for UI changes
+
+=head1 USAGE
+
+fetch_pages -d before_change -u myuser -p mypass list_of_tests
+git checkout newbranch
+make install; apache2ctl restart
+fetch_pages -d after_change -u myuser -p mypass list_of_tests
+diff -ur before_change/ after_change/ |diffstat
+
+=head1 ARGUMENTS
+
+-d: the directory to put the files in. Required.
+
+-u: the username to use with the Freeside web interface. Required.
+
+-p: the password. Required.
+
+-h: the URL prefix for the Freeside server. Defaults to
+"http://localhost/freeside".
+
+The list of tests can be in a file specified after all arguments, or passed
+to stdin.
+
+=cut