r36144 - in /branches/upstream/libsocialtext-wikitest-perl: ./ current/ current/lib/ current/lib/Socialtext/ current/lib/Socialtext/WikiFixture/ current/lib/Socialtext/WikiObject/ current/t/ current/t/lib/ current/t/lib/Test/ current/t/lib/Test/WWW/
myon at users.alioth.debian.org
myon at users.alioth.debian.org
Fri May 22 12:30:59 UTC 2009
Author: myon
Date: Fri May 22 12:30:55 2009
New Revision: 36144
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=36144
Log:
[svn-inject] Installing original source of libsocialtext-wikitest-perl
Added:
branches/upstream/libsocialtext-wikitest-perl/
branches/upstream/libsocialtext-wikitest-perl/current/
branches/upstream/libsocialtext-wikitest-perl/current/Changes
branches/upstream/libsocialtext-wikitest-perl/current/MANIFEST
branches/upstream/libsocialtext-wikitest-perl/current/META.yml
branches/upstream/libsocialtext-wikitest-perl/current/Makefile.PL
branches/upstream/libsocialtext-wikitest-perl/current/lib/
branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/
branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/
branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture.pm
branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/Null.pm
branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/Selenese.pm
branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/TestUtils.pm
branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiObject/
branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiObject/TestPlan.pm
branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiTest.pm
branches/upstream/libsocialtext-wikitest-perl/current/t/
branches/upstream/libsocialtext-wikitest-perl/current/t/fixture-selenese.t
branches/upstream/libsocialtext-wikitest-perl/current/t/fixture.t
branches/upstream/libsocialtext-wikitest-perl/current/t/lib/
branches/upstream/libsocialtext-wikitest-perl/current/t/lib/Test/
branches/upstream/libsocialtext-wikitest-perl/current/t/lib/Test/WWW/
branches/upstream/libsocialtext-wikitest-perl/current/t/lib/Test/WWW/Selenium.pm
branches/upstream/libsocialtext-wikitest-perl/current/t/testplan.t
Added: branches/upstream/libsocialtext-wikitest-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/Changes?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/Changes (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/Changes Fri May 22 12:30:55 2009
@@ -1,0 +1,36 @@
+0.06 - Thu Jun 21 15:47:13 PDT 2007
+ - Fix a bug that prevented testing whether a value was "0"
+ - Handle multi-byte characters better - Thanks Takatoshi Kitano
+
+0.05 - Mon Apr 9 11:00:01 PDT 2007
+ - move Socialtext specific code out of this module
+ - move the fixture test utility code into a package
+ - s/Mock::Rester/Socialtext::Resting::Mock/
+
+0.04 - March 21, 2007
+ - Added a failing test if a testplan dies
+ - updated Socialtext ids based on UI changes
+ - Made Socialtext watchlist code more robust
+ - Change the selenium browser with $ENV{selenium_browser}
+ - Added print_page for debugging
+ - Modified socialtext st_login to redirect to the workspace
+
+0.03 - Mon Mar 12 21:20:05 PDT 2007
+ - Null now prints out commands
+ - Add util/run-wiki-tests example script
+ - test plans that die shouldn't stop all testing
+ - fixed st-admin when called with no verify option
+
+0.02 - Fri Dec 29 15:09:10 PST 2006
+ - added a bunch more Socialtext fixture commands
+ - use click_and_wait more
+ - option description for click_and_wait
+ - enhanced qr// support for most fields
+ - Added mock rester support for local testing from file
+ - Add variable support to selenium commands
+ - Added st-admin fixture command
+ - Added st-force-confirmation command
+
+0.01 - Wed Dec 20 11:43:02 PST 2006
+ - first release
+ - extra awesome
Added: branches/upstream/libsocialtext-wikitest-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/MANIFEST?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/MANIFEST (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/MANIFEST Fri May 22 12:30:55 2009
@@ -1,0 +1,14 @@
+lib/Socialtext/WikiFixture.pm
+lib/Socialtext/WikiFixture/Selenese.pm
+lib/Socialtext/WikiFixture/Null.pm
+lib/Socialtext/WikiFixture/TestUtils.pm
+lib/Socialtext/WikiObject/TestPlan.pm
+lib/Socialtext/WikiTest.pm
+t/fixture.t
+t/fixture-selenese.t
+t/testplan.t
+t/lib/Test/WWW/Selenium.pm
+Makefile.PL
+MANIFEST
+Changes
+META.yml Module meta-data (added by MakeMaker)
Added: branches/upstream/libsocialtext-wikitest-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/META.yml?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/META.yml (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/META.yml Fri May 22 12:30:55 2009
@@ -1,0 +1,15 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
+name: Socialtext-WikiTest
+version: 0.06
+version_from: lib/Socialtext/WikiTest.pm
+installdirs: site
+requires:
+ mocked: 0
+ Socialtext::Resting: 0
+ Socialtext::Resting::Utils: 0.04
+ Test::Exception: 0
+ Test::More: 0
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17
Added: branches/upstream/libsocialtext-wikitest-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/Makefile.PL?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/Makefile.PL (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/Makefile.PL Fri May 22 12:30:55 2009
@@ -1,0 +1,20 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'Socialtext::WikiTest',
+ AUTHOR => 'Luke Closs <cpan at 5thplane.com>',
+ VERSION_FROM => 'lib/Socialtext/WikiTest.pm',
+ PL_FILES => {},
+ PREREQ_PM => {
+ 'Socialtext::Resting' => 0,
+ 'Socialtext::Resting::Utils' => 0.04,
+ 'Test::More' => 0,
+ 'Test::Exception' => 0,
+ 'mocked' => 0,
+ },
+ EXE_FILES => [],
+ dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ clean => { FILES => 'Socialtext-WikiTest-*' },
+);
Added: branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture.pm?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture.pm (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture.pm Fri May 22 12:30:55 2009
@@ -1,0 +1,143 @@
+package Socialtext::WikiFixture;
+use strict;
+use warnings;
+use Test::WWW::Selenium;
+
+=head1 NAME
+
+Socialtext::WikiFixture - Base class for tests specified on a wiki page
+
+=cut
+
+our $VERSION = '0.05';
+
+=head1 SYNOPSIS
+
+ use base 'Socialtext::WikiFixture';
+
+=head1 DESCRIPTION
+
+Socialtext::WikiFixture is a base class that fetches and parses wiki pages
+using the Socialtext::Resting REST API. It then tries to execute the
+commands in the wiki tables. The code for executing the tables should
+be implemented in subclasses.
+
+This package assumes that tests will be defined in top level tables on
+the specified wiki page.
+
+=head1 FUNCTIONS
+
+=head2 new( %opts )
+
+Create a new fixture object. You probably mean to call this on a subclass.
+
+=cut
+
+sub new {
+ my ($class, %args) = @_;
+ my $self = \%args;
+ bless $self, $class;
+
+ $self->init;
+
+ return $self;
+}
+
+=head2 init()
+
+Optional initialization hook for subclasses. Called from new().
+
+=cut
+
+sub init {}
+
+=head2 run_test_table( $table_ref )
+
+Run the commands contained in the supplied table. The table will
+be an array ref of array refs.
+
+=cut
+
+sub run_test_table {
+ my $self = shift;
+ my $table = shift;
+
+ for my $row (@$table) {
+ $row->[0] =~ s/^\s*//;
+ next unless $row->[0];
+ next if $row->[0] =~ /^\*?command\*?$/i; # header
+ $self->handle_command(@$row);
+ }
+
+ $self->end_hook;
+}
+
+=head2 end_hook()
+
+Optional hook for subclasses that will be called after the tests in the
+table have been run.
+
+=cut
+
+sub end_hook {}
+
+=head2 handle_command( @row )
+
+Run the command. Subclasses will implement this.
+
+=cut
+
+sub handle_command { die 'Subclass must implement' }
+
+=head1 AUTHOR
+
+Luke Closs, C<< <luke.closs at socialtext.com> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-socialtext-editpage at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Socialtext-WikiTest>.
+I will be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc Socialtext::WikiFixture
+
+You can also look for information at:
+
+=over 4
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/Socialtext-WikiTest>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/Socialtext-WikiTest>
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Socialtext-WikiTest>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/Socialtext-WikiTest>
+
+=back
+
+=head1 ACKNOWLEDGEMENTS
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2006 Luke Closs, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1;
Added: branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/Null.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/Null.pm?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/Null.pm (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/Null.pm Fri May 22 12:30:55 2009
@@ -1,0 +1,31 @@
+package Socialtext::WikiFixture::Null;
+use strict;
+use warnings;
+use base 'Socialtext::WikiFixture';
+use base 'Exporter';
+
+our @EXPORT_OK = qw/get_num_calls/;
+
+my $CALLS;
+
+=head2 get_num_calls
+
+Return the number of calls made to handle_command, and reset the counter.
+
+=cut
+
+sub get_num_calls {
+ my $num = $CALLS;
+ $CALLS = 0;
+ return $num;
+}
+
+sub handle_command {
+ my $self = shift;
+ my $command = shift;
+ print "Null: $command\n" unless $self->{silent};
+ $CALLS++;
+ die if $command eq 'die';
+}
+
+1;
Added: branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/Selenese.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/Selenese.pm?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/Selenese.pm (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/Selenese.pm Fri May 22 12:30:55 2009
@@ -1,0 +1,322 @@
+package Socialtext::WikiFixture::Selenese;
+use strict;
+use warnings;
+use base 'Socialtext::WikiFixture';
+use Encode;
+use Test::More;
+
+=head1 NAME
+
+Socialtext::WikiFixture::Selenese - Executes wiki tables using Selenium RC
+
+=cut
+
+our $VERSION = '0.02';
+
+=head1 DESCRIPTION
+
+This class executes wiki tables using Selenium Remote Control. Test tables
+contain 3 columns:
+
+ | *Command* | *Option1* | *Option2* |
+
+This module will attempt to convert selenese into proper calls to
+Test::WWW::Selenium, otherwise the calls will be passed straight to
+Test::WWW::Selenium.
+
+=head1 FUNCTIONS
+
+=head2 new( %opts )
+
+Create a new fixture object. Options:
+
+=over 4
+
+=item host
+
+Mandatory - specifies the Selenium server to connect to
+
+=item port
+
+Optional - specifies the port of the Selenium server (default: 4444)
+
+=item browser_url
+
+Mandatory - Passed to WWW::Selenium constructor, specifies where the
+browser should connect to.
+
+=back
+
+=head2 init()
+
+Called by the constructor. Creates a Test::WWW::Selenium object which
+asks the Selenium Server to launch a browser.
+
+=cut
+
+sub init {
+ my ($self) = @_;
+
+ unless ($self->{selenium}) {
+ die "Selenium host is mandatory!" unless $self->{host};
+ die "Selenium browser_url is mandatory!" unless $self->{browser_url};
+
+ $self->{selenium} = Test::WWW::Selenium->new(
+ host => $self->{host},
+ port => $self->{port} || 4444,
+ browser_url => $self->{browser_url},
+ browser => $ENV{selenium_browser} || '*firefox',
+ );
+ $self->{_started_selenium}++;
+ }
+ $self->{selenium_timeout} ||= 10000;
+
+ $self->setup_table_variables;
+}
+
+=head2 setup_table_variables
+
+Called by init() during object creation. Use it to set variables
+usable by commands in the wiki test tables.
+
+=cut
+
+sub setup_table_variables {
+ my $self = shift;
+ $self->{start_time} = time;
+}
+
+=head2 end_hook()
+
+Called by the test plan after testing has finished. Kills the browser.
+
+=cut
+
+sub end_hook {
+ my $self = shift;
+ if ($self->{_started_selenium}) {
+ $self->{selenium}->stop;
+ $self->{selenium} = undef;
+ }
+}
+
+=head3 handle_command()
+
+Called by the test plan to execute each command.
+
+=cut
+
+sub handle_command {
+ my $self = shift;
+ my $sel = $self->{selenium};
+ my $command = $self->_munge_command(shift);
+ my ($opt1, $opt2) = $self->_munge_options(@_);
+
+ # Convenience method
+ if ($command eq 'text_like' and !$opt2) {
+ $opt2 = $opt1;
+ $opt1 = '//body';
+ }
+
+ if ($command =~ /_(?:un)?like$/) {
+ if ($opt2) {
+ $opt2 = $self->quote_as_regex($opt2);
+ }
+ else {
+ $opt1 = $self->quote_as_regex($opt1);
+ }
+ }
+
+ # Try to guess _ok methods
+ $command .= '_ok' if { map { $_ => 1 } qw(open type) }->{$command};
+ $self->$command($opt1, $opt2);
+}
+
+sub _munge_command {
+ my $self = shift;
+ my $command = shift;
+
+ $command =~ s/-/_/g;
+ $command =~ s/^\*(.+)\*$/$1/;
+
+ # Turn Camelcase into perl style (eg: clickAndWait -> click_and_wait)
+ while ($command =~ /[A-Z]/) {
+ $command =~ s/([a-z]*)([A-Z])/($1 ? $1 . '_' : '') . lc($2)/e;
+ }
+
+ # Map selenese (eg: verify_title => title_like)
+ if ($command =~ /^verify_(\w+)$/) {
+ $command = lc($1) . '_like';
+ }
+
+ return $command;
+}
+
+sub _munge_options {
+ my $self = shift;
+
+ my @opts;
+ for (@_) {
+ my $var = defined $_ ? $_ : '';
+ $var =~ s/%%(\w+)%%/exists $self->{$1} ? $self->{$1} : 'undef' /eg;
+ $var =~ s/\\n/\n/g;
+ push @opts, $var;
+ }
+ return @opts;
+}
+
+
+=head2 quote_as_regex( $option )
+
+Will convert an option to a regex. If qr// is around the option text,
+the regex will not be escaped. Be careful with your regexes.
+
+=cut
+
+sub quote_as_regex {
+ my $self = shift;
+ my $var = shift || '';
+
+ Encode::_utf8_on($var) unless Encode::is_utf8($var);
+ if ($var =~ qr{^qr/(.+?)/$}) {
+ return qr/$1/s;
+ }
+ return qr/\Q$var\E/;
+}
+
+=head2 click_and_wait()
+
+Clicks and waits.
+
+=cut
+
+sub click_and_wait {
+ my ($self, $opt1, $opt2) = @_;
+ my $sel = $self->{selenium};
+
+ my @args;
+ push @args, $opt2 if $opt2;
+ $sel->click_ok($opt1, @args);
+ $sel->wait_for_page_to_load_ok($self->{selenium_timeout}, @args);
+}
+
+=head2 text_present_like()
+
+Search entire body for given text
+
+=cut
+
+sub text_present_like {
+ my ($self, $opt1) = @_;
+ $self->{selenium}->text_like('//body', $opt1);
+}
+
+=head2 comment( $comment )
+
+Prints $comment to test output.
+
+=cut
+
+sub comment {
+ my ($self, $comment) = @_;
+ diag '';
+ diag "comment: $comment";
+}
+
+=head2 set( $name, $value )
+
+Stores a variable for later use.
+
+=cut
+
+sub set {
+ my ($self, $name, $value) = @_;
+ unless (defined $name and defined $value) {
+ diag "Both name and value must be defined for set!";
+ return;
+ }
+ $self->{$name} = $value;
+ diag "Set '$name' to '$value'";
+}
+
+=head2 print_page()
+
+Prints the text of the current page loaded into the browser.
+
+=cut
+
+sub print_page {
+ my ($self) = @_;
+
+ print $self->get_text('//body');
+}
+
+=head2 AUTOLOAD
+
+Any functions not specified are passed to Test::WWW::Selenium
+
+=cut
+
+our $AUTOLOAD;
+sub AUTOLOAD {
+ my $name = $AUTOLOAD;
+ $name =~ s/.+:://;
+ return if $name eq 'DESTROY';
+
+# warn "No method $name found - passing to selenium\n";
+ my $self = shift;
+ $self->{selenium}->$name(@_);
+}
+
+=head1 AUTHOR
+
+Luke Closs, C<< <luke.closs at socialtext.com> >>
+
+=head1 BUGS
+
+Please report any bugs or feature requests to
+C<bug-socialtext-editpage at rt.cpan.org>, or through the web interface at
+L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Socialtext-WikiTest>.
+I will be notified, and then you'll automatically be notified of progress on
+your bug as I make changes.
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc Socialtext::WikiFixture::Selenese
+
+You can also look for information at:
+
+=over 4
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/Socialtext-WikiTest>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/Socialtext-WikiTest>
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Socialtext-WikiTest>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/Socialtext-WikiTest>
+
+=back
+
+=head1 ACKNOWLEDGEMENTS
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2006 Luke Closs, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1;
Added: branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/TestUtils.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/TestUtils.pm?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/TestUtils.pm (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiFixture/TestUtils.pm Fri May 22 12:30:55 2009
@@ -1,0 +1,49 @@
+package Socialtext::WikiFixture::TestUtils;
+use strict;
+use warnings;
+use Test::More;
+use Socialtext::Resting::Mock;
+use mocked 'Test::WWW::Selenium', qw/$SEL/;
+
+use base 'Exporter';
+our @EXPORT_OK = qw/fixture_ok/;
+
+my $rester = Socialtext::Resting::Mock->new;
+
+sub fixture_ok {
+ my %args = @_;
+
+ ok 1, $args{name};
+
+ $rester->put_page('Test Plan', $args{plan});
+ my $plan = Socialtext::WikiObject::TestPlan->new(
+ rester => $rester,
+ page => 'Test Plan',
+ default_fixture => $args{default_fixture},
+ fixture_args => {
+ host => 'selenium-server',
+ username => 'testuser',
+ password => 'password',
+ browser_url => 'http://server',
+ workspace => 'foo',
+ %{ $args{fixture_args} || {} },
+ },
+ );
+
+ if ($args{sel_setup}) {
+ for my $s (@{$args{sel_setup}}) {
+ $SEL->set_return_value(@$s);
+ }
+ }
+
+ $plan->run_tests;
+
+ for my $t (@{$args{tests}}) {
+ $SEL->method_args_ok(@$t);
+ }
+
+ $SEL->method_args_ok('stop', undef);
+ $SEL->empty_ok($args{extra_calls_ok});
+}
+
+1;
Added: branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiObject/TestPlan.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiObject/TestPlan.pm?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiObject/TestPlan.pm (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiObject/TestPlan.pm Fri May 22 12:30:55 2009
@@ -1,0 +1,131 @@
+package Socialtext::WikiObject::TestPlan;
+use strict;
+use warnings;
+use base 'Socialtext::WikiObject';
+use Test::More;
+
+=head1 NAME
+
+Socialtext::WikiObject::TestPlan - Load wiki pages as Test plan objects
+
+=cut
+
+our $VERSION = '0.03';
+
+=head1 SYNOPSIS
+
+ use base 'Socialtext::WikiObject::TestPlan';
+ my $test_plan = Socialtext::WikiObject::TestPlan->new(
+ rester => $rester,
+ page => $plan_page,
+ server => $test_server,
+ workspace => $test_workspace,
+ );
+ $test_plan->run_tests;
+
+=head1 DESCRIPTION
+
+Socialtext::WikiObject::TestPlan fetches Wiki pages using the Socialtext
+REST API, and parses the page into a testplan object. This class can be
+subclassed to support different types of test plans.
+
+Test Plans look for a list item at the top level of the page looking like
+this:
+
+ * Fixture: Foo
+
+This tells the TestPlan object to create a Socialtext::WikiFixture::Foo
+object and use it to run the tests. A default fixture can also be specified
+in the constructor.
+
+The wiki tests are specified as tables in the top level of the page.
+
+Test Plans can also contain links to other test plans. If no fixture is
+found, the test plan will look for wiki links in any top level list items:
+
+ * [This Test Plan]
+ * [That Test Plan]
+
+These pages will be loaded as TestPlan objects, and their tests will be
+run as well.
+
+=head1 FUNCTIONS
+
+=head2 new( %opts )
+
+Create a new test plan. Options:
+
+=over 4
+
+=item rester
+
+Mandatory - specifies the Socialtext::Resting object that will be used
+to load the test plan. The rester should already have a workspace conifgured.
+
+=item page
+
+Mandatory - the page containing the test plan.
+
+=item fixture_args
+
+A hashref containing arguments to pass through to the fixture constructor.
+
+=back
+
+=head2 run_tests()
+
+Execute the tests.
+
+=cut
+
+sub run_tests {
+ my $self = shift;
+
+ unless ($self->{table}) {
+ $self->_recurse_testplans;
+ return;
+ }
+
+ my $fixture_class = $self->_fixture || $self->{default_fixture};
+ return unless $self->{table} and $fixture_class;
+
+ unless ($fixture_class =~ /::/) {
+ $fixture_class = "Socialtext::WikiFixture::$fixture_class";
+ }
+
+ eval "require $fixture_class";
+ die "Can't load fixture $fixture_class $@\n" if $@;
+
+ my $fix = $fixture_class->new( %{ $self->{fixture_args} } );
+ $fix->run_test_table($self->{table});
+}
+
+# Find the fixture in the page
+sub _fixture {
+ my $self = shift;
+ for (@{ $self->{items} || [] }) {
+ next unless /^fixture:\s*(\S+)/i;
+ return $1;
+ }
+ return undef;
+}
+
+sub _recurse_testplans {
+ my $self = shift;
+
+ for my $i (@{ $self->{items} }) {
+ next unless $i =~ /^\[([^\]]+)\]/;
+ my $page = $1;
+ warn "# Loading test plan $page...\n";
+ my $plan = Socialtext::WikiObject::TestPlan->new(
+ page => $page,
+ rester => $self->{rester},
+ default_fixture => $self->{default_fixture},
+ fixture_args => $self->{fixture_args},
+ );
+ eval { $plan->run_tests };
+ ok 0, "Error during test plan $page: $@" if $@;
+ }
+}
+
+1;
Added: branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiTest.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiTest.pm?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiTest.pm (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/lib/Socialtext/WikiTest.pm Fri May 22 12:30:55 2009
@@ -1,0 +1,26 @@
+package Socialtext::WikiTest;
+use strict;
+use warnings;
+
+=head1 NAME
+
+Socialtext::WikiTest - Execute tests defined on wiki pages
+
+=cut
+
+our $VERSION = '0.06';
+
+=head1 AUTHOR
+
+Luke Closs, C<< <luke.closs at socialtext.com> >>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2006,2007 Luke Closs, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1;
Added: branches/upstream/libsocialtext-wikitest-perl/current/t/fixture-selenese.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/t/fixture-selenese.t?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/t/fixture-selenese.t (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/t/fixture-selenese.t Fri May 22 12:30:55 2009
@@ -1,0 +1,157 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More qw/no_plan/;
+use Test::Exception;
+use Socialtext::WikiFixture::TestUtils qw/fixture_ok/;
+
+BEGIN {
+ use lib 'lib';
+ use_ok 'Socialtext::WikiObject::TestPlan';
+}
+
+sel_fixture_ok (
+ name => 'Simple Selenese',
+ plan => <<EOT,
+* Fixture: Selenese
+| *Command* | *Option 1* | *Option 2* |
+| open | / |
+| verifyTitle | monkey |
+| verifyTextPresent | water |
+| verifyText | //body | pen? |
+| verifyText | //body | qr/pen?/ |
+| confirmation_like | pen? |
+| confirmation_like | qr/pen?/ |
+| clickAndWait | foo | |
+EOT
+ tests => [
+ [ open_ok => '/' ],
+ [ title_like => qr/\Qmonkey\E/ ],
+ [ text_like => ['//body', qr/\Qwater\E/] ],
+ [ text_like => ['//body', qr/\Qpen?\E/] ],
+ [ text_like => ['//body', qr/pen?/] ],
+ [ confirmation_like => qr/\Qpen?\E/ ],
+ [ confirmation_like => qr/pen?/ ],
+ [ click_ok => 'foo' ],
+ [ wait_for_page_to_load_ok => 10000 ],
+ ],
+);
+
+sel_fixture_ok (
+ name => 'Specific timeout',
+ plan => <<EOT,
+* Fixture: Selenese
+| clickAndWait | foo | |
+EOT
+ tests => [
+ [ click_ok => 'foo' ],
+ [ wait_for_page_to_load_ok => 9 ],
+ ],
+ fixture_args => {
+ selenium_timeout => 9,
+ },
+);
+
+Pass_in_selenium: {
+ my $selenium = 'fake';
+ my $f = Socialtext::WikiFixture::Selenese->new(selenium => $selenium);
+ is $f->{selenium}, $selenium, "didn't create a new selenium";
+ $f->end_hook;
+ is $f->{selenium}, $selenium, "didn't undef selenium";
+}
+
+Variable_interpolation: {
+ my $f = Socialtext::WikiFixture::Selenese->new(selenium => 'fake');
+ my @opts = $f->_munge_options('%%foo%%');
+ is_deeply \@opts, ['undef'];
+ $f->{foo} = 'bar';
+ @opts = $f->_munge_options('%%foo%%');
+ is_deeply \@opts, ['bar'];
+}
+
+Missing_mandatory_args: {
+ throws_ok { Socialtext::WikiFixture::Selenese->new }
+ qr/Selenium host/;
+ throws_ok { Socialtext::WikiFixture::Selenese->new(host => 'foo') }
+ qr/Selenium browser_url/;
+}
+
+Optional_selenium_port: {
+ my $f = Socialtext::WikiFixture::Selenese->new(
+ host => 'foo',
+ browser_url => 'bar',
+ port => 1234,
+ );
+ is $f->{selenium}{args}{host}, 'foo';
+ is $f->{selenium}{args}{browser_url}, 'bar';
+ is $f->{selenium}{args}{port}, 1234;
+}
+
+Selenese_command_mapping: {
+ sel_fixture_ok (
+ name => 'text_like with 1 arg',
+ plan => <<EOT,
+| verifyText | foo | |
+EOT
+ tests => [
+ [ text_like => ['//body', qr/foo/] ],
+ ],
+ );
+}
+
+Camel_cased_commands: {
+ my %commands = (
+ SuperDuper => 'super_duper',
+ Super => 'super',
+ );
+ my $f = Socialtext::WikiFixture::Selenese->new(selenium => 'fake');
+ for my $long (keys %commands) {
+ is $f->_munge_command($long), $commands{$long}, $long;
+ }
+}
+
+Quote_as_regex: {
+ my $f = Socialtext::WikiFixture::Selenese->new(selenium => 'fake');
+ is $f->quote_as_regex(), qr//;
+ is $f->quote_as_regex('foo'), qr/\Qfoo\E/;
+ is $f->quote_as_regex('qr/foo/'), qr/foo/s;
+}
+
+Special_functions: {
+ no warnings qw/redefine once/;
+ my $f = Socialtext::WikiFixture::Selenese->new(selenium => 'fake');
+ my $diag = '';
+ *Socialtext::WikiFixture::Selenese::diag = sub { $diag .= "$_[0]\n" };
+
+ Comment: {
+ $f->comment('foo');
+ is $diag, "\ncomment: foo\n";
+ }
+
+ Set: {
+ $diag = '';
+ $f->set('foo', 'bar');
+ is $diag, "Set 'foo' to 'bar'\n";
+ is $f->{foo}, 'bar';
+ }
+
+ Bad_set: {
+ $diag = '';
+ $f->set('bar');
+ like $diag, qr/Both name and value/;
+ is $f->{bar}, undef;;
+
+ $diag = '';
+ $f->set(undef, 'bar');
+ like $diag, qr/Both name and value/;
+ }
+}
+
+sub sel_fixture_ok {
+ my %args = @_;
+
+ fixture_ok(
+ default_fixture => 'Selenese',
+ %args,
+ );
+}
Added: branches/upstream/libsocialtext-wikitest-perl/current/t/fixture.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/t/fixture.t?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/t/fixture.t (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/t/fixture.t Fri May 22 12:30:55 2009
@@ -1,0 +1,29 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More qw/no_plan/;
+use Socialtext::Resting::Mock;
+use lib 't/lib';
+use Test::WWW::Selenium qw/$SEL/; # mocked
+
+BEGIN {
+ use lib 'lib';
+ use_ok 'Socialtext::WikiObject::TestPlan';
+}
+
+my $rester = Socialtext::Resting::Mock->new;
+
+Base_fixture: {
+ $rester->put_page('Test Plan', <<EOT);
+* Fixture: Socialtext::WikiFixture
+| foo |
+EOT
+ my $plan = Socialtext::WikiObject::TestPlan->new(
+ rester => $rester,
+ page => 'Test Plan',
+ );
+
+ eval { $plan->run_tests };
+ ok $@;
+}
+
Added: branches/upstream/libsocialtext-wikitest-perl/current/t/lib/Test/WWW/Selenium.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/t/lib/Test/WWW/Selenium.pm?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/t/lib/Test/WWW/Selenium.pm (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/t/lib/Test/WWW/Selenium.pm Fri May 22 12:30:55 2009
@@ -1,0 +1,69 @@
+package Test::WWW::Selenium;
+use strict;
+use warnings;
+use base 'Exporter';
+use Test::More;
+
+our @EXPORT_OK = '$SEL';
+
+our $SEL; # singleton
+
+sub new {
+ my ($class, %opts) = @_;
+ if ($SEL) {
+ $SEL->{args} = \%opts;
+ return $SEL;
+ }
+ $SEL = { args => \%opts };
+ bless $SEL, $class;
+ return $SEL;
+}
+
+sub set_return_value {
+ my ($self, $name, $return) = @_;
+ push @{$self->{return}{$name}}, $return;
+}
+
+sub method_args_ok {
+ my ($self, $name, $expected) = @_;
+ my $actual = shift @{$self->{$name}};
+ is_deeply $actual, $expected;
+}
+
+sub empty_ok {
+ my $self = shift;
+ my $ignore_extra = shift;
+ for my $k (keys %$self) {
+ next if $k eq 'return' or $k eq 'args';
+ next if ref($self->{$k}) eq 'ARRAY' and @{$self->{$k}} == 0;
+ if ($ignore_extra) {
+ delete $self->{$k};
+ }
+ else {
+ ok 0, "extra call to $k - " . ref($self->{$k});
+ }
+ }
+ $self->{return} = {};
+}
+
+our $AUTOLOAD;
+sub AUTOLOAD {
+ my $name = $AUTOLOAD;
+ $name =~ s/.+:://;
+ return if $name eq 'DESTROY';
+
+ my ($self, $opt1, $opt2) = @_;
+ if ($opt2) {
+ push @{$self->{$name}}, [$opt1, $opt2];
+ }
+ else {
+ push @{$self->{$name}}, $opt1;
+ }
+
+ if ($self->{return}{$name}) {
+ return shift @{$self->{return}{$name}};
+ }
+ return;
+}
+
+1;
Added: branches/upstream/libsocialtext-wikitest-perl/current/t/testplan.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libsocialtext-wikitest-perl/current/t/testplan.t?rev=36144&op=file
==============================================================================
--- branches/upstream/libsocialtext-wikitest-perl/current/t/testplan.t (added)
+++ branches/upstream/libsocialtext-wikitest-perl/current/t/testplan.t Fri May 22 12:30:55 2009
@@ -1,0 +1,119 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More qw/no_plan/;
+use lib 't/lib';
+use Socialtext::Resting::Mock;
+
+BEGIN {
+ use lib 'lib';
+ use_ok 'Socialtext::WikiObject::TestPlan';
+ use_ok 'Socialtext::WikiFixture::Null', 'get_num_calls';
+}
+
+Basic_plan: {
+ testplan_ok(
+ num => 2,
+ plan_content => <<EOT,
+* Fixture: Null
+| Foo |
+| bar |
+| |
+EOT
+ );
+}
+
+Recursive_plan: {
+ testplan_ok(
+ num => 2,
+ plan_content => <<EOT,
+* [Plan1]
+* Wah-wah
+* [Plan2]
+EOT
+ pages => {
+ 'Plan1' => "* Fixture: Null\n| foo |\n",
+ 'Plan2' => "* Fixture: Null\n| foo |\n",
+ },
+ );
+}
+
+Recursive_plan_with_default_fixture: {
+ testplan_ok(
+ num => 2,
+ plan_content => <<EOT,
+* [Plan1]
+* Wah-wah
+* [Plan2]
+EOT
+ pages => {
+ 'Plan1' => "* Fixture: Null\n| bar |\n",
+ 'Plan2' => "* Fixture: Null\n| foo |\n",
+ },
+ tp_args => { default_fixture => 'Null' },
+ );
+}
+
+Default_fixture: {
+ testplan_ok(
+ num => 2,
+ plan_content => <<EOT,
+| Foo |
+| bar |
+EOT
+ tp_args => { default_fixture => 'Null' },
+ );
+}
+
+No_fixture: {
+ testplan_ok(
+ num => 0,
+ plan_content => <<EOT,
+| Foo |
+| bar |
+EOT
+ );
+}
+
+Invalid_fixture: {
+ testplan_ok(
+ should_die => 1,
+ plan_content => <<EOT,
+* Fixture: Monkey
+| Foo |
+| bar |
+EOT
+ );
+}
+
+sub testplan_ok {
+ my %args = @_;
+
+ my $rester = Socialtext::Resting::Mock->new;
+ $rester->put_page('Test Plan' => $args{plan_content});
+ for my $p (keys %{ $args{pages} }) {
+ $rester->put_page($p, $args{pages}{$p});
+ }
+ my %tp_args = (
+ rester => $rester,
+ page => 'Test Plan',
+ %{ $args{tp_args} || {} },
+ );
+ my $plan = Socialtext::WikiObject::TestPlan->new(
+ %tp_args,
+ fixture_args => {
+ server => 'http://server',
+ workspace => 'foo',
+ },
+ );
+
+ if ($args{should_die}) {
+ eval { $plan->run_tests };
+ ok $@;
+ }
+ else {
+ $plan->run_tests;
+ is get_num_calls(), $args{num};
+ }
+}
+
More information about the Pkg-perl-cvs-commits
mailing list