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

NAME

Egg::Helper::O::Test - It assists in the construction of the test environment for Egg.

SYNOPSIS

  use Test::More tests=> 3;
  use Egg::Helper;
  
  my $test= Egg::Helper->run('O::Test');
  
  # The test project environment is constructed.
  $test->prepare;
  
  # The object of the test project is acquired. 
  my $egg= $test->egg_virtual;
  
  # The environment variable for a virtual request is setup.
  $egg->setup_env('http://domain.name/hoge?param1=a1&param2=a2');
  
  # The use of the component of a virtual project is enabled.
  $egg->prepare_component;
  
  ok( $egg->request->params->{param1} eq 'a1' );
  
  # The output contents of a virtual project are acquired.
  ok( my $catch= $t->response_catch2($egg) );
  
  ok( $$catch );

DESCRIPTION

The construction of a virtual project and other assistances are done so that this module may conveniently test the module related to Egg.

METHODS

The object of this module is received via Egg::Helper.

  my $test= Egg::Helper->run('O::Test');

preapre

The environment of a virtual project is temporarily constructed in the directory.

It is necessary to be called always first.

Please see the document of Egg::Helper::O::Test::Prepar in detail.

egg_virtual

The object of a virtual project is returned.

cleanup (BOOLEAN)

The CLEANUP flag of File::Temp::tempdir is specified.

response_catch ([EGG_OBJECT] or [VR_URL], [DATA])

The output contents of a virtual project are returned by the SCALAR reference.

When URL is passed, setup_env is done. Moreover, when [DATA] is passed, it is treated as POST request.

$e->start_engine is done and the output contents are acquired. Therefore, please note uselessness even if [EGG_OBJECT] that did $e->prepare_componet is passed.

Please use 'response_catch2' if you want the result the same as the expectation.

response_catch2 ([EGG_OBJECT])

The output contents of a virtual project are returned by the SCALAR reference.

Processing that omits $e->prepare_component because of $e->start_engine is done. It is necessary to do [EGG_OBJECT]->prepare_component beforehand.

Moreover, if it wants the result of a specific request, it is necessary to do setup_env beforehand.

catch_stdout ([CODE_REFERENCE])

The result of the output of [CODE_REFERENCE] to STDOUT is returned by the SCALAR reference.

attach_request ([REQUEST_METHOD], [VR_URL], [DATA])

The object of a virtual project of the request processing ending is returned. It is ,in a word, an object of the $e->prepare_component processing.

When [REQUEST_METHOD] is POST, the value of [DATA] becomes an option to pass to HTTP::Request::Common.

  my $egg= $test->attach_request( POST=> 'http://domain.name/test', {
    Content_Type=> 'form-data',
    Content=> [
      param1 => 'test',
      upload1=> ["/path/to/file1"],
      upload2=> ["/path/to/file2"],
      ],
    });

The option to pass to setup_env with the key named ENV can be defined in [DATA].

setup_env ([VR_URL], [DATA]);

The environment variable based on passed URL is setup.

HASH passed with [DATA] is developed with the environment variable. All keys are converted into the capital letter.

exec_trigger

'Trigger.cgi' that exists in bin of a virtual project is moved.

path_to ([PATH])

Passing that builds in the project route of a virtual project is returned.

  my $path= $test->path_to('test/test.txt');
  
  ok( $path eq $test->project_root ."/test/test.txt" );

project_name ([PROJECT_NAME])

The virtual project name is returned.

The project name can be specified by specifying [PROJECT_NAME].

However, a correct project name cannot be acquired in case of not being after 'prepare' or 'create_project_root' is called.

project_root

Passing the route of a virtual project is returned.

However, it is not possible to acquire it in case of not being after 'prepare' or 'create_project_root' is called.

create_project_root ([PROJECT_NAME])

If the project name is undefined, 'project_root' is decided after 'project_name' is defined, and temp_dir is acquired, and the passing is returned.

If [PROJECT_NAME] unspecifies it, 'EggVirtual' becomes default.

The directory of 'project_root' has not been made in this processing yet. Moreover, if 'project_root' already exists, the exception is generated.

temp_dir

The work passing is temporarily returned.

Passing specification can be set beforehand by environment variable 'EGG_TEST_TEMP'. Default becomes passing generated with File::Temp::tempdir.

file_view ([PATH])

The content is returned reading the file of [PATH].

Please note the evaluation with path_to about [PATH].

  print $test->file_view('lib/MYPROJECT.pm');

SEE ALSO

File::Temp, Egg::Helper::O::Test::Prepare, Egg::Release,

AUTHOR

Masatoshi Mizuno, <mizuno@bomcity.com>

COPYRIGHT AND LICENSE

Copyright (C) 2007 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.