#!/usr/bin/perl -w use strict; use Data::Dumper qw( Dumper ); use WWW::Mechanize; use File::Basename; use URI; my $srcMech = WWW::Mechanize::TWiki->new( agent => basename($0) . ' [src]', autocheck => 1 ) or die $!; $srcMech->cgibin( "http://localhost/~twiki/cgi-bin/twiki" ); my $destMech = WWW::Mechanize::TWiki->new( agent => basename($0) . ' [dest]', autocheck => 1 ) or die $!; $destMech->cgibin( "http://localhost/~twiki/cgi-bin/twiki" ); my $iWeb = 'TWiki'; my $iTopic = 'QuietSave'; ################################################################################ { # grab html my $htmlGoldenExpected = $srcMech->view( "$iWeb/$iTopic", { skin => 'text' } )->content(); # grab raw tml text my $tmlTextSource = $srcMech->view( "$iWeb/$iTopic", { skin => 'text', raw => 1 } )->content(); # create new topic in UnitCases $destMech->edit( "TestCases/TestCaseAuto" . $iTopic ); my $description = "Description: generated from $iWeb.$iTopic"; my $testCaseTemplate = <<__TEMPLATE__; ---+!! %TOPIC% Description: $description expected $htmlGoldenExpected source $tmlTextSource __TEMPLATE__ $destMech->field( text => $testCaseTemplate ); $destMech->click_button( value => 'Save' ); } ################################################################################ exit 0; ################################################################################ ################################################################################ package WWW::Mechanize::TWiki; use strict; use warnings FATAL => 'all'; our $VERSION = '0.02'; use base qw( WWW::Mechanize ); sub new { my $class = shift; my %args = @_; my $self = $class->SUPER::new( %args ); return $self; } sub cgibin { my $self = shift; my $cgibin = shift; my $args = @_; $self->{cgibin} = $cgibin; return $self; } # maps function calls into twiki urls sub AUTOLOAD { our ($AUTOLOAD); no strict 'refs'; my $action = $AUTOLOAD; $action =~s/.*:://; *$AUTOLOAD = sub { my ($self, $topic, $args) = @_; (my $u1 = URI->new( "$self->{cgibin}/$action/$topic" ))->query_form( $args ); return $self->get( $u1 ); }; goto &$AUTOLOAD; } ############################################################################### package TWiki::Topic; use strict; use warnings FATAL => 'all'; our $VERSION = '0.01'; #use base qw(); sub new { my $class = shift; my $self = { @_, # defaults here... }; return bless ($self, $class); } ################################################################################