The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

CGI::Wiki::TestConfig::Utilities - Utilities for testing CGI::Wiki things.

DESCRIPTION

When 'perl Makefile.PL' is run on a CGI::Wiki distribution, information will be gathered about test databases etc that can be used for running tests. CGI::Wiki::TestConfig::Utilities gives you convenient access to this information, so you can easily write and run tests for your own CGI::Wiki plugins.

SYNOPSIS

  # Reinitialise every configured storage backend.
  use strict;
  use CGI::Wiki;
  use CGI::Wiki::TestConfig::Utilities;

  CGI::Wiki::TestConfig::Utilities->reinitialise_stores;


  # Run all our tests for every possible storage backend.

  use strict;
  use CGI::Wiki;
  use CGI::Wiki::TestConfig::Utilities;
  use Test::More tests =>
                   (8 * $CGI::Wiki::TestConfig::Utilities::num_stores);

  my %stores = CGI::Wiki::TestConfig::Utilities->stores;

  my ($store_name, $store);
  while ( ($store_name, $store) = each %stores ) {
      SKIP: {
        skip "$store_name storage backend not configured for testing", 8
            unless $store;

        # PUT YOUR TESTS HERE
      }
  }


  # Or maybe we want to run tests for every combination of store
  # and search.

  use strict;
  use CGI::Wiki::TestConfig::Utilities;
  use Test::More tests =>
         (1 + 11 * $CGI::Wiki::TestConfig::Utilities::num_combinations);

  use_ok( "CGI::Wiki::Plugin::Location" );

  # Test for each configured pair: $store, $search.
  my @tests = CGI::Wiki::TestConfig::Utilities->combinations;
  foreach my $configref (@tests) {
      my %testconfig = %$configref;
      my ( $store_name, $store, $search_name, $search, $configured ) =
         @testconfig{qw(store_name store search_name search configured)};
      SKIP: {
        skip "Store $store_name and search $search_name"
             . " not configured for testing", 11 unless $configured;

        # PUT YOUR TESTS HERE
      }
  }

METHODS

reinitialise_stores
  # Reinitialise every configured storage backend.
  use strict;
  use CGI::Wiki;
  use CGI::Wiki::TestConfig::Utilities;

  CGI::Wiki::TestConfig::Utilities->reinitialise_stores;

Clears out all of the configured storage backends.

stores
  my %stores = CGI::Wiki::TestConfig::Utilities->stores;

Returns a hash whose keys are the names of all possible storage backends (eg, MySQL, Pg, SQLite) and whose values are either a corresponding CGI::Wiki::Store::* object, if one has been configured, or undef, if no corresponding store has been configured.

You can find out at BEGIN time how many of these to expect; it's stored in $CGI::Wiki::TestConfig::Utilities::num_stores

combinations
  my @combs = CGI::Wiki::TestConfig::Utilities->combinations;

Returns an array of references to hashes, one each for every possible combination of storage and search backends.

The hash entries are as follows:

store_name - eg MySQL, Pg, SQLite
store - a CGI::Wiki::Store::* object corresponding to store_name, if one has been configured, or undef, if no corresponding store has been configured.
search_name - eg DBIxFTSMySQL, SIIMySQL, SII
search - a CGI::Wiki::Search::* object corresponding to search_name, if one has been configured, or undef, if no corresponding search has been configured.
configured - true if this combination has been sufficiently configured to run tests on, false otherwise.

You can find out at BEGIN time how many of these to expect; it's stored in $CGI::Wiki::TestConfig::Utilities::num_combinations

SEE ALSO

CGI::Wiki

AUTHOR

Kake Pugh (kake@earth.li).

COPYRIGHT

     Copyright (C) 2003 Kake Pugh.  All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

CAVEATS

If you have the Search::InvertedIndex backend configured (see CGI::Wiki::Search::SII) then your tests will raise warnings like

  (in cleanup) Search::InvertedIndex::DB::Mysql::lock() -
    testdb is not open. Can't lock.
  at /usr/local/share/perl/5.6.1/Search/InvertedIndex.pm line 1348

or

  (in cleanup) Can't call method "sync" on an undefined value
    at /usr/local/share/perl/5.6.1/Tie/DB_File/SplitHash.pm line 331
    during global destruction.

in unexpected places. I don't know whether this is a bug in me or in Search::InvertedIndex.