#! /usr/bin/perl -w use strict; use Data::Dumper qw( Dumper ); use Test::More; BEGIN { unshift @INC, './lib'; } use WWW::Mechanize; use WWW::Mechanize::TWiki; use TWiki::Topic; my $tt = TWiki::Topic->new() or die $!; #my $mech = WWW::Mechanize->new( agent => 'TWikiTester', autocheck => 1 ) or die $!; my $mech = WWW::Mechanize::TWiki->new( agent => 'TWikiTester', autocheck => 1 ) or die $!; my $config = { web => 'Test', }; my $baseUrl = "http://localhost/~wbniv/twiki/bin/view"; my $baseWebUrl = "$baseUrl/$config->{web}"; my $webHome = "$baseWebUrl/WebHome"; if ( 0 ) { ################################################################################ # create new Test web # assert( webExists( '_default' ) ); # assert( not webExists( $config->{web} ) ); print $mech->go( url => "$baseUrl/TWiki/ManagingWebs" ); $mech->get( "$baseUrl/TWiki/ManagingWebs" ); $mech->submit_form( form_name => 'admin', fields => { baseweb => '_default', newweb => $config->{web}, webbgcolor => '#FF0099', # hot pink (noticeable!) sitemapwhat => 'TWiki Automated Unit and Regression Tests', sitemapuseto => '...internal testing', nosearchall => [ radio => '' ], # HTML smell: should have values of "yes" and "no" ? }, ); # assert( webExists( $config->{web} ) ); # assert( wikiCompare( $config->{web}, '_default' ) == 0 ); # * hmm, what to do about WebPreferences (because of parameters above) # * create with duplicates/defaults for _default (so they're identical) # * skip WebPreferences (or compare it differently?) } ################################################################################ # create new topic (TestNewTopic) my $topic = 'TestNewTopic'; # assert( not topicExists( $config->{web}, $topic ); print $mech->go( url => "$baseWebUrl/$topic" ); $mech->get( "$baseWebUrl/$topic" ); $mech->follow_link( text => 'Create' ); $mech->field( text => "\n" ); $mech->click_button( value => 'Save' ); # assert( topicExists( $config->{web}, $topic ) ); # assert( topicCompare( "$config->{web}.$topic", "" ) == 0 ); #-------------------------------------------------------------------------------- # for my $i ( 1..1 ) { print "$i\n"; $mech->follow_link( text => 'Edit' ); $mech->form_name( 'main' ); my $topicText = $mech->value( 'text' ); $topicText .= "\n\nsome more testing\n\n-- %MAINWEB%.TWikiTester\n"; $mech->field( text => $topicText ); $mech->click_button( value => 'Save' ); } # $mech->get( "$baseWebUrl/$topic?skin=plain" ); # like( $mech->content(), "...", "Got expected content" ); ################################################################################ for my $i ( 1..2 ) { $mech->follow_link( text => 'Attach' ); $mech->submit_form( form_name => 'main', fields => { filepath => q[/Users/wbniv/twiki/test/icon.png], filecomment => q[test logo attachment], createlink => 'on', # hidefile => undef, }, ); } ################################################################################ $mech->follow_link( text => 'More topic actions' ); $mech->follow_link( text => 'Delete topic...', n => 1 ); ( my $gmtime = gmtime() ) =~ s/ /_/g; # because spaces get eaten in topic names (and numbers run together) my $trashTopicTitle = $mech->field( 'newtopic' ) . '_' . $gmtime; $mech->field( newtopic => $trashTopicTitle ); $mech->click_button( value => 'Delete' ); $mech->get( "$webHome?skin=plain" ); print $mech->uri(), "\n"; print $mech->content(), "\n"; print "\n";