#!/usr/bin/perl -w ################################ # Test various variables and subroutines in MarlboroCollegeSchedule.cgi # $Id: test.pl,v 1.4 2002/04/12 09:01:20 msie Exp $ ######################## use Test::Simple tests => 9; #-------------------------------------------------------- # 1. -- Does it compile ? my $compiles = eval " require 'MarlboroClassSchedule.cgi'"; ok($compiles, "MarlboroClassSchedule.cgi compiles" ); package MarlboroClassSchedule; # An alias for the Test::Simple::ok() subroutine. # I need this because I'm now working inside another package namespace. sub OK { my ($test, $name) = @_; return main::ok($test, $name); } #-------------------------------------------------------- # 2. -- Does the last modified date look like it's a time? our $lastmodified; # This avoids warning that lastmodified is mentioned 1nce. OK( $lastmodified =~ /\d{4}$/ , "modification date ends in dddd"); #-------------------------------------------------------- # 3. -- Can we store some data and read it from the file system ? $blockdata = { one => 1, two => 2 }; writeData(); $blockdata = {}; readData(); OK( $blockdata->{one} == 1 , "can read and write to datafile" ); # -- live tests -- my $defaultURL = "http://bob.marlboro.edu/~msie/2002/ipl/perl/lectures/apr12/RegistrarSchedule/deploy/MarlboroClassSchedule.cgi"; print "Url for live tests? [$defaultURL] "; chomp(my $url = <>); $url = $url || $defaultURL; #-------------------------------------------------------- # 4. -- Can we fetch the webpage ? # (See lwp-cookbook from libwww-perl) use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new( GET => $url ); $req->header("Accept" => "text/html"); my $result = $ua->request($req); my $status = $result->status_line; OK( $result->is_success, "fetching web page, status is $status "); #-------------------------------------------------------- # 5. -- Does the webpage have an "Edit 11:30" link? my $pagelink = 'Edit'; OK( $result->content =~ /$pagelink/, "has edit=mon1130 link "); #-------------------------------------------------------- # 6. -- Can we fetch the edit 11:30 page? $req = HTTP::Request->new( GET => $url."?edit=mon1130" ); $req->header("Accept" => "text/html"); $result = $ua->request($req); $status = $result->status_line; OK( $result->is_success, "fetching edit page, status is $status "); #-------------------------------------------------------- # 7. -- And does it have the text form on it? $pagelink = '