|
From: <jgr...@us...> - 2003-08-22 04:56:54
|
Update of /cvsroot/popfile/engine/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv10250/tests
Modified Files:
TestHTML.tst
Added Files:
TestHTML.script
Log Message:
Improved HTML test runner with scripting mechanism to make it easier to specify URLs to hit and how to match the responses
--- NEW FILE: TestHTML.script ---
# ---------------------------------------------------------------------------------------------
#
# Test script for the HTML interface, loaded by TestHTML.tst
#
# Copyright (c) 2003 John Graham-Cumming
#
# This file is part of POPFile
#
# POPFile is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# POPFile is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with POPFile; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ---------------------------------------------------------------------------------------------
# To simplify testing the POPFile HTML UI this file contains a script
# that is read by TestHTML.tst and executed. The script consists of instructions
# for specific URLs that are to be hit and instructions for how to match the
# result that comes back
#
# The commands are as follows
#
# URL <url> Set the URL that is to be fetched
# GET Gets the last set URL
# POST/ENDPOST Contains a block of data to be POSTed
# MATCH <data> Match the return from last URL fetch against the data
# MATCH/ENDMATCH Encloses a block of test to find in the return from the last URL fetch
#
# Expect that the following are available to you within the MATCH/ENDMATCH block
#
# $port The port on which the HTML interface is running
# $url URL object for the last URL specified
# $content String containing the return from the last URL fetch
# $sk The current HTML UI session key
# $version Same as $h->version()
# Test the simplest functionality of the HTML interface
# Look for elements that should appear at the TOP and BOTTOM
# of every page
URL http://127.0.0.1:$port
GET
# Common TOP parts
MATCH <title>POPFile Control Center</title>
MATCH <html lang="en">
MATCH <meta http-equiv="Pragma" content="no-cache">
MATCH <meta http-equiv="Expires" content="0">
MATCH <meta http-equiv="Cache-Control" content="no-cache">
MATCH <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
MATCH <link rel="stylesheet" type="text/css" href="skins/SimplyBlue.css" title="SimplyBlue">
MATCH <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
MATCH <link rel="icon" href="popfile.ico" type="image/ico">
# Common MIDDLE parts (i.e. the tabs)
MATCH <a class="menuLink" href="/history?session=$sk&setfilter=">
MATCH History</a>
MATCH <a class="menuLink" href="/buckets?session=$sk">
MATCH Buckets</a>
MATCH <a class="menuLink" href="/magnets?session=$sk&start_magnet=0">
MATCH Magnets</a>
MATCH <a class="menuLink" href="/configuration?session=$sk">
MATCH Configuration</a>
MATCH <a class="menuLink" href="/security?session=$sk">
MATCH Security</a>
MATCH <a class="menuLink" href="/advanced?session=$sk">
MATCH Advanced</a>
# Common BOTTOM parts
MATCH <a class="bottomLink" href="manual/en/manual.html">
MATCH <br>$version<br>
# Verify that each of the pages highlights the correct item on
# the tab bar and hence the simplest level of page serving is working
# correctly
URL http://127.0.0.1:$port/history
GET
MATCH
<td class="menuSelected" align="center">
<a class="menuLink" href="/history?session=$sk&setfilter=">
ENDMATCH
URL http://127.0.0.1:$port/buckets
GET
MATCH
<td class="menuSelected" align="center">
<a class="menuLink" href="/buckets?session=$sk">
ENDMATCH
URL http://127.0.0.1:$port/magnets
GET
MATCH
<td class="menuSelected" align="center">
<a class="menuLink" href="/magnets?session=$sk&start_magnet=0">
ENDMATCH
URL http://127.0.0.1:$port/configuration
GET
MATCH
<td class="menuSelected" align="center">
<a class="menuLink" href="/configuration?session=$sk">
ENDMATCH
URL http://127.0.0.1:$port/security
GET
MATCH
<td class="menuSelected" align="center">
<a class="menuLink" href="/security?session=$sk">
ENDMATCH
URL http://127.0.0.1:$port/advanced
GET
MATCH
<td class="menuSelected" align="center">
<a class="menuLink" href="/advanced?session=$sk">
ENDMATCH
Index: TestHTML.tst
===================================================================
RCS file: /cvsroot/popfile/engine/tests/TestHTML.tst,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** TestHTML.tst 20 Aug 2003 17:31:11 -0000 1.5
--- TestHTML.tst 20 Aug 2003 20:14:20 -0000 1.6
***************
*** 77,81 ****
$b->initialize();
! my $h = new UI::HTML;
$h->configuration( $c );
--- 77,81 ----
$b->initialize();
! our $h = new UI::HTML;
$h->configuration( $c );
***************
*** 85,90 ****
$h->initialize();
$h->version( 'testsuite' );
! my $sk = $h->{session_key__};
test_assert_equal( $h->url_encode_( ']' ), '%5d' );
--- 85,91 ----
$h->initialize();
$h->version( 'testsuite' );
+ our $version = $h->version();
! our $sk = $h->{session_key__};
test_assert_equal( $h->url_encode_( ']' ), '%5d' );
***************
*** 93,97 ****
test_assert_equal( $h->url_encode_( '[foo]' ), '%5bfoo%5d' );
! my $port = 9000 + int(rand(1000));
pipe my $dreader, my $dwriter;
pipe my $ureader, my $uwriter;
--- 94,98 ----
test_assert_equal( $h->url_encode_( '[foo]' ), '%5bfoo%5d' );
! our $port = 9000 + int(rand(1000));
pipe my $dreader, my $dwriter;
pipe my $ureader, my $uwriter;
***************
*** 135,212 ****
use LWP::Simple;
use URI::URL;
! # Test the simplest functionality of the HTML interface
!
! my $url = url( "http://127.0.0.1:$port" );
! my $content = get($url);
!
! # Look for elements that should appear at the TOP and BOTTOM
! # of every page
!
! # Common TOP parts
!
! test_assert_regexp( $content, "<title>POPFile Control Center</title>" );
! test_assert_regexp( $content, "<html lang=\"en\">" );
! test_assert_regexp( $content, "<meta http-equiv=\"Pragma\" content=\"no-cache\">" );
! test_assert_regexp( $content, "<meta http-equiv=\"Expires\" content=\"0\">" );
! test_assert_regexp( $content, "<meta http-equiv=\"Cache-Control\" content=\"no-cache\">" );
! test_assert_regexp( $content, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">" );
! test_assert_regexp( $content, "<link rel=\"stylesheet\" type=\"text/css\" href=\"skins/SimplyBlue.css\" title=\"SimplyBlue\">" );
! test_assert_regexp( $content, "<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"favicon.ico\">" );
! test_assert_regexp( $content, "<link rel=\"icon\" href=\"popfile.ico\" type=\"image/ico\">" );
!
! # Common MIDDLE parts (i.e. the tabs)
!
! test_assert_regexp( $content, "<a class=\"menuLink\" href=\"/history.session=$sk&setfilter=\">" );
! test_assert_regexp( $content, "History</a>" );
! test_assert_regexp( $content, "<a class=\"menuLink\" href=\"/buckets.session=$sk\">" );
! test_assert_regexp( $content, "Buckets</a>" );
! test_assert_regexp( $content, "<a class=\"menuLink\" href=\"/magnets.session=$sk&start_magnet=0\">" );
! test_assert_regexp( $content, "Magnets</a>" );
! test_assert_regexp( $content, "<a class=\"menuLink\" href=\"/configuration.session=$sk\">" );
! test_assert_regexp( $content, "Configuration</a>" );
! test_assert_regexp( $content, "<a class=\"menuLink\" href=\"/security.session=$sk\">" );
! test_assert_regexp( $content, "Security</a>" );
! test_assert_regexp( $content, "<a class=\"menuLink\" href=\"/advanced.session=$sk\">" );
! test_assert_regexp( $content, "Advanced</a>" );
!
! # Common BOTTOM parts
!
! test_assert_regexp( $content, "<a class=\"bottomLink\" href=\"manual/en/manual.html\">" );
! test_assert_regexp( $content, "<br>" . $h->version() . "<br>" );
! # Verify that each of the pages highlights the correct item on
! # the tab bar and hence the simplest level of page serving is working
! # correctly
! $url = url( "http://127.0.0.1:$port/history" );
! $content = get($url);
! test_assert_regexp( $content, "<td class=\"menuSelected\" align=\"center\">\n<a class=\"menuLink\" href=\"/history.session=$sk&setfilter=\">" );
! $url = url( "http://127.0.0.1:$port/buckets" );
! $content = get($url);
! test_assert_regexp( $content, "<td class=\"menuSelected\" align=\"center\">\n<a class=\"menuLink\" href=\"/buckets.session=$sk\">" );
! $url = url( "http://127.0.0.1:$port/magnets" );
! $content = get($url);
! test_assert_regexp( $content, "<td class=\"menuSelected\" align=\"center\">\n<a class=\"menuLink\" href=\"/magnets.session=$sk&start_magnet=0\">" );
! $url = url( "http://127.0.0.1:$port/configuration" );
! $content = get($url);
! test_assert_regexp( $content, "<td class=\"menuSelected\" align=\"center\">\n<a class=\"menuLink\" href=\"/configuration.session=$sk\">" );
! $url = url( "http://127.0.0.1:$port/security" );
! $content = get($url);
! test_assert_regexp( $content, "<td class=\"menuSelected\" align=\"center\">\n<a class=\"menuLink\" href=\"/security.session=$sk\">" );
! $url = url( "http://127.0.0.1:$port/advanced" );
! $content = get($url);
! test_assert_regexp( $content, "<td class=\"menuSelected\" align=\"center\">\n<a class=\"menuLink\" href=\"/advanced.session=$sk\">" );
# TODO Validate every page in the interface against the W3C HTML 4.01
--- 136,193 ----
use LWP::Simple;
use URI::URL;
+ use String::Interpolate 'interpolate';
! our $url;
! our $content;
! open SCRIPT, "<TestHTML.script";
! while ( my $line = <SCRIPT> ) {
! $line =~ s/^[\t ]+//g;
! $line =~ s/[\r\n\t ]+$//g;
! $line = interpolate( $line );
! if ( $line =~ /^#/ ) {
! next;
! }
! if ( $line =~ /^URL (.+)/ ) {
! $url = url( $1 );
! next;
! }
! if ( $line =~ /^GET$/ ) {
! $content = get($url);
! next;
! }
! if ( $line =~ /^MATCH (.+)$/ ) {
! test_assert_regexp( $content, "\Q$1\E" );
! next;
! }
! if ( $line =~ /^MATCH$/ ) {
! my $block;
! while ( $line = <SCRIPT> ) {
! $line =~ s/^[\t ]+//g;
! $line =~ s/[\r\n\t ]+$//g;
! $line = interpolate( $line );
! if ( $line =~ /^ENDMATCH$/ ) {
! last;
! }
! $block .= "\n" unless ( $block eq '' );
! $block .= $line;
! }
! test_assert_regexp( $content, "\Q$block\E" );
! next;
! }
! }
! close SCRIPT;
# TODO Validate every page in the interface against the W3C HTML 4.01
|