NAME
Labyrinth::Test::Harness - Test Harness for Labyrinth Plugin modules
SYNOPSIS
my $harness = Labyrinth::Test::Harness->new( %options );
my $res = $harness->prep('file1.sql','file2.sql');
$res = $harness->labyrinth(@plugins);
$res = $harness->action('Base::Admin');
$harness->refresh( \@plugins );
$harness->refresh(
\@plugins,
{ test1 => 1 },
{ test2 => 2 } );
$harness->cleanup;
$harness->clear();
my $vars = $harness->vars;
my $params = $harness->params;
my $settings = $harness->settings;
$harness->set_vars( name => 'Test', test => 1 );
$harness->set_params( name => 'Test', test => 1 );
$harness->set_settings( name => 'Test', test => 1 );
my $error = $harness->error;
my $config = $harness->config;
my $directory = $harness->directory;
$harness->copy_files($source,$target);
DESCRIPTION
Contains all the harness code around Labyrinth, to enable plugin testing.
METHODS
The Constructor
- new( %options )
-
Harness object constructor.
Defines a default config file and directory, unless otherwise provided.
Options available are:
keep => 1 # default is 0 config => $config directory => $directory env => \%environment
When a harness object goes out of scope, the DESTROY method is called, unless 'keep' is a true value, the cleanup method will be automatically called.
'config' and 'directory' preset the respective file and directory names, although these can also be set by the respective methods calls prior to calling the prep method.
'env' can contain settings for internal environment variables that are used within Labyrinth. The environment variables that can be overridden, together with their current defaults, are:
SERVER_PROTOCOL => 'http', SERVER_PORT => 80, HTTP_HOST => 'example.com', REQUEST_URI => '/', PATH_INFO => undef
Public Methods
- keep( $value )
-
If set to a true value, don't cleanup when object oes out of scope.
- config( $value )
-
Set the name of the file to use as the configuration file. Default is 't/_DBDIR/test-config.ini'.
- directory( $value )
-
Set the name of the working directory. Default is 't/_DBDIR'.
- prep( %options )
-
Prepares the environment. Copies files from the current vhost directory, creates a database, and runs the necessary SQL to create the required tables and add the appropriate data. Saves the configuration settings to the designated config file.
The options allow for overides and additional test information to be provided. Example option are:
sql => [ 'file1', 'file2' ], files => { 'file3.jpg' => 'html/images/file3.jpg' }, config => { SECTION => { key => 'value' } }
SQL files listed in 'sql' are loaded and run prior to testing. After the initial copyin of the vhost files, the list in 'files' are copied. Note that files should be listed as source => target (beneath the $directory) as a key/value pair.
In the 'config' list, the additional sections and parameters can be provided, which override the default configurations if necessary. Default sections are PROJECT, INTERNAL, HTTP and CMS. DATABASE is also provide, but cannot be overriden.
- labyrinth( @plugins )
-
Loads an instance of Labyrinth. Will also pre-load the list of given plugins.
- action( $action )
-
Runs the named plugin action.
- refresh( \@plugins, $vars_hash, $params_hash )
-
Refreshes the current instance by reloading the Labyrinth instances, together with the name plugins, and adding the variables and parameters to the current internal hashes.
Essentially a short cut to calling labyrinth(), set_vars() and set_params() separately.
- login( $id )
-
Given a user id, will automatically log that user into the system. This then loads the appropriate permissions for that user.
- cleanup
-
Clean up the instance, removes the current directory and deletes the test database.
Internal Variables
- clear
-
Clear the internal variables and parameters hashes.
- params
-
returns the current parameters hash.
- set_params( %hash )
-
Adds the given parameters to the current paraments hash.
- vars
-
returns the current variables hash.
- set_vars( %hash )
-
Adds the given variables to the current variables hash.
- settings
-
returns the current settings hash.
- set_settings( %hash )
-
Adds the given variables to the current settings hash.
- error
-
Returns the last error recorded.
Internal Methods
- copy_files( $source, $target )
-
Copies files between the source and target directories.
- copy_file( $source, $target )
-
Copies a single file from source to target.
- create_config( $db_config )
-
Creates a configuration file.
- create_mysql_databases( @files )
-
Creates the test database. The @files array, lists the SQL files containing SQL statements to run on the test database.
- dosql
-
Runs an SQL command.
SEE ALSO
http://labyrinth.missbarbell.co.uk
AUTHOR
Barbie, <barbie@missbarbell.co.uk> for Miss Barbell Productions, http://www.missbarbell.co.uk/
COPYRIGHT & LICENSE
Copyright (C) 2014-2015 Barbie for Miss Barbell Productions
All Rights Reserved.
This module is free software; you can redistribute it and/or
modify it under the Artistic License 2.0.