The last few days I've been hacking together some more tests and indeed
have now read our entire suite of tests. While I was doing this I noticed
that we seem to have several ways of doing things so it might be worth
deciding on the best.
Firstly the clean up of node.db between tests. We currently have 3 if not
4 ways of doing this.
foreach my $del_node ( $wiki->list_all_nodes ) {
print "# Deleting node $del_node\n";
$wiki->delete_node( $del_node ) or die "Can't delete $del_node";
}
which doesnt clear indexes.
Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
which also doesnt clean indexes
unlink "t/node.db";
unlink <t/indexes/*>;
Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
which is the most useful.
then in one test that becomes a sub
sub refresh_db {
unlink "t/node.db";
unlink <t/indexes/*>;
Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
}
and then used several times.
Repeatitive code pains me. Therefore I feel we should make refresh_db a
sub in OpenGuides::Test and then use that. I have a patch for that and
will also probably go through and clean up all the tests.
Secondly, We have 3 ways to do node generation. All of which are fine but
we should probably pick one and run with it. This would take more time to
change in the test suite. Also there maybe reasons in a test why one way
is used above another.
The first way is
OpenGuides::Test->write_data(
node => "Wombats",
guide => $guide,
username => "bob",
edit_type => "Minor tidying",
return_output => 1,
);
which IHMO should be the prefered method.
the second method seem to be along ther lines of
my $q = CGI->new;
$q->param( -name => "content", -value => "foo" );
$q->param( -name => "categories", -value => "" );
$q->param( -name => "locales", -value => "" );
$q->param( -name => "phone", -value => "" );
$q->param( -name => "fax", -value => "" );
$q->param( -name => "website", -value => "" );
$q->param( -name => "hours_text", -value => "" );
$q->param( -name => "address", -value => "" );
$q->param( -name => "postcode", -value => "" );
$q->param( -name => "map_link", -value => "" );
$q->param( -name => "os_x", -value => "" );
$q->param( -name => "os_y", -value => "" );
$q->param( -name => "username", -value => "bob" );
$q->param( -name => "comment", -value => "foo" );
$q->param( -name => "edit_type", -value => "Minor
tidying" );
$ENV{REMOTE_ADDR} = "127.0.0.1";
my $output = $guide->commit_node(
return_output => 1,
id => "Wombats",
cgi_obj => $q,
);
the third method is
$wiki->write_node( "British Museum", "Huge museum, lots of
artifacts.",
undef,
{ category => ["Museums", "Major Attractions"]
, locale => ["Holborn", "Bloomsbury"] } );
Another thing we need to look at is config generation.
we should probably just be using
my $config = OpenGuides::Test->make_basic_config;
then changing anything we want with lines like.
$config->script_name( "wiki.cgi" );
$config->script_url( "http://example.com/" );
instead of
my $config = OpenGuides::Config->new(
vars => {
dbtype => "sqlite",
dbname => "t/node.db",
indexing_directory => "t/indexes",
script_name => "wiki.cgi",
script_url => "http://example.com/",
site_name => "Test Site",
template_path => "./templates",
home_name => "Home",
use_plucene => 1
}
);
its possibly worth extending the basic config in Openguides::Test.
Finally a couple of the test files have useful subroutines in them whch
should probably be put into Openguides::Test.
So thoughts, questions or indeed comments?
--
bob walker
buses should be purple and bendy
Show replies by date
On Mon 17 Aug 2009, Bob Walker <bob(a)randomness.org.uk> wrote:
The last few days I've been hacking together some
more tests and indeed
have now read our entire suite of tests. While I was doing this I noticed
that we seem to have several ways of doing things so it might be worth
deciding on the best. [...]
Finally a couple of the test files have useful subroutines in them whch
should probably be put into Openguides::Test.
So thoughts, questions or indeed comments?
Good work! I think the inconsistencies you've identified are
basically artefacts of the test suite having grown organically as and
when needed... we didn't have OpenGuides::Test to start with, and I'm
sure I remember thinking that at some point the older tests should be
refactored to remove all this repeated code.
I agree that as much as possible should be moved into utility subs in
OpenGuides::Test.
Kake