NAME
Egg::Helper::VirtualTest - The virtual test environment for Egg project.
SYNOPSIS
use Egg::Helper::VirtualTest;
my $vr= Egg::Helper::VirtualTest->new;
$vr->prepare(
controller => { egg_includes => [qw/ AnyPlugin /] },
create_files => \@files,
config => {
hoo => '.....',
hoge => '...',
},
);
my $e= $vr->egg_context;
my $mech= $vr->mech_get('/request_uri');
print $mech->content;
DESCRIPTION
An executable virtual environment is constructed for the test of the Egg project.
A virtual environment can control the composition by HASH passed to the prepare method.
Moreover, the result to a virtual request and the operation of the script are verifiable it according to WWW::Mechanize::CGI.
METHODS
new ( [OPTION_HASH] )
Constructor.
It comes to be able to access given OPTION_HASH by the option method.
Suitable following initialize is done, and the object is returned.
project_name
If project_name of OPTION_HASH is undefined, 'VirtualTest' is set.
start_dir
Current directory of execution.
project_root
If temp_dir of OPTION_HASH is undefined, the work directory is acquired temporarily and set from File::Temp.
project_already
When project_root already exists when 'already_ok' of OPTION_HASH is undefined, the exception is generated.
prepare
It passes it to the prepare method if there is prepare in OPTION_HASH.
prepare ( [PREPAR_HASH] )
A virtual project is constructed according to PREPAR_HASH.
When PREPAR_HASH is omitted, all virtual projects are constructed with Defolt.
The item evaluated with PREPAR_HASH is as follows.
controller => [CONTROLLER_HASH]
Setting concerning controller.
The content evaluates the following items with HASH without fail.
egg => [PLUGIN_OR_FLAG_ARRAY]
The plugin and the flag that makes it load are specified with ARRAY.
Default is [qw/Dispatch::Standard Debugging Log/]
controller => { egg => [qw/ Dispatch::Fast Debugging Log /] },
egg_includes => [PLUGIN_OR_FLAG_ARRAY]
List of plugin and flag added to value of egg.
controller => { egg_includes => [qw/ AnyPlugin /] },
egg_debug => [BOOL]
'-Debug' is added to the list of the plugin and the flag.
controller => { egg_debug => 1 },
default_mode => [DEFAULT_MODEL]
Name of default_mode defined in default_mode.
controller => { default_mode => 'default' },
egg_dispatch_map => [DISPATCH_MAP_TEXT]
The setting of dispatch_map is set as it is in the text.
my $dispatch_map= <<'END_MODE'; _default => sub {}, hoo => sub { my($self, $e)= @_; $e->template('document/hoo.tt'); }, hoge => sub {}, END_MODE controller => { dispatch_map => $dispatch_map },
egg_mode_param => [PARAM_NAME]
Name of mode_param defined in mode_param.
controller => { mode_param => 'mode' },
first_code = [CODE_TEXT]
Script code that wants to be included in controller's first half.
my $first_code= <<'END_CODE'; use MyApp::Tools; END_CODE controller => { first_code => $first_code },
last_code => [CODE_TEXT]
Script code that wants to be included in controller's latter half.
my $last_code = <<'END_CODE'; sub last_code { my($self, $e)= @_; ......... ..... .. } END_CODE controller => { last_code => $last_code },
version => [VERSION_NUMBER]
Version of controller who generates it.
controller => { version => '1.00' },
config => [CONFIG_HASH]
title => [TITLE_TEXT]
Default is $vr->project_name.
root => [PROJECT_ROOT_PATH]
Default is $vr->project_root.
template_path => [PATH_ARRAY]
Default is ["$vr->project_root/root", "$vr->project_root/comp"]
VIEW => [VIEW_CONFIG_ARRAY]
Default is a setting of Template (HTML::Template).
default_view_mason => [BOOL]
Mason is set to VIEW if this value is effective when the setting of VIEW is undefined.
... etc.
Additionally, please refer to the document of Egg for details for the configuration.
create_files => [FILE_DATA_ARRAY]
A new file is generated according to FILE_DATA_ARRAY.
Each item of ARRAY is HASH passed to Egg::Helper->save_file.
* Because generation does project_root to the starting point, filename can be specified by relativity PATH. create_files => [ { filename => "etc/hoge.txt", value => "<\$e.project_name> \n OK \n", }, { filename => "bin/hoge.pl", filetype => "script", value => "print 'OK';", }, ],
create_dirs => [DIR_LIST_ARRAY]
An empty directory is made according to DIR_LIST_ARRAY.
create_dirs => [qw{ tmp/myapp cache/content/myapp }],
disable_warn
$SIG{__WARN__}= sub {}.
disable_stdout
STDOUT is output temporary.
disable_stderr
STDERR is output temporary.
disable_allstd
All 'disable_warn' and 'disable_stdout' and 'disable_stderr' is done at a time.
egg_context
The object of a virtual project is returned.
my $e= $vr->egg_context;
egg_pcomp_context
The object of a virtual project of the '_prepare_model' and '_prepare_view' and '_prepare' execution is returned.
my $e= $vr->egg_pcomp_context;
egg_handler
‰¼‘zƒvƒ�ƒWƒFƒNƒg‚Ì handler ƒ�ƒ\ƒbƒh‚ðƒR�[ƒ‹‚µ‚Ü‚·�B
$vr->egg_handler;
helper_run ( [MODE], [ANY_NAME], [OPTION] )
The helper script is operated on a virtual project.
MODE is not omissible.
$vr->helper_run('Plugin:Helper', 'NewName', { ... options });
mech_ok
If the include of WWW::Mechanize::CGI succeeds, true is returned.
mechanize ( [OPTION_HASH] )
The object of WWW::Mechanize::CGI is returned.
OPTION_HASH is an option to pass to WWW::Mechanize::CGI.
mech_get ( [VR_REQUEST_URI], [OPTION] )
Virtual GET is requested to VR_REQUEST_URI.
OPTION is an option to pass to 'mechanize' method.
When the return value is received with ARRAY, the object of the project after CGI is executed can be received.
my($mech, $e)= $vr->mech_get('/get_request');
print $mech->content;
if ($e->param('check_param')) { print "OK" }
mech_post ( [VR_REQUEST_URI], [QUERY_DATA_HASH], [OPTION] )
Virtual POST is requested to VR_REQUEST_URI.
QUERY_DATA_HASH is a parameter passed to CGI.
OPTION is an option to pass to 'mechanize' method.
my $mech= $vr->mech_post('/post_request', { foo => 'test', hoge=> 'OK' });
print $mech->content;
* When upload is tested, it is L as for QUERY_DATA_HASH. <HTTP::Request::Common> Please give it by the form that passes.
my $proot= $vr->project_root;
my($mech, $e)= $vr->mech_post('/post_request', {
Content_Type => 'form-data',
Content => [
upload1 => ["$proot/data/upload.txt" ],
upload2 => ["$proot/data/upload.html"],
param1 => 'test',
],
});
my $upload= $e->request->upload('upload1');
if ($upload->filename) { print "OK" }
* It is necessary to load the 'Upload' plugin into the test of upload.
SEE ALSO
File::Temp, WWW::Mechanize::CGI, HTTP::Request::Common, Egg::Helper, Egg::Release,
AUTHOR
Masatoshi Mizuno <lushe@cpan.org>
COPYRIGHT
Copyright (C) 2007 by Bee Flag, Corp. <http://egg.bomcity.com/>, All Rights Reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 392:
Non-ASCII character seen before =encoding in '‰¼‘zƒvƒ�ƒWƒFƒNƒg‚Ì'. Assuming CP1252