CGI-Application-Plugin-MessageStack-0.34/ 0000755 0001750 0000147 00000000000 10504260761 020517 5 ustar jason webdev 0000000 0000000 CGI-Application-Plugin-MessageStack-0.34/t/ 0000755 0001750 0000147 00000000000 10504260761 020762 5 ustar jason webdev 0000000 0000000 CGI-Application-Plugin-MessageStack-0.34/t/TestAppTT.pm 0000644 0001750 0000147 00000003352 10504260761 023153 0 ustar jason webdev 0000000 0000000 package TestAppTT; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; use CGI::Application::Plugin::TT 0.09; ## TEST PLAN ## # * cgiapp w/ html-template # * first request: # - establish session # - check output for ! message # * second request: # - pass in session # - push an info message # * third request: # - pass in session # - check output for message # - check message for proper classification # FILES: 02-check_output.t, TestAppOutput.pm, output.TMPL sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third cleanup ) ] ); $self->tmpl_path( './t' ); $self->tt_include_path( './t' ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; return $self->tt_process( 'output.tt' ); } sub second { my $self = shift; my $session = $self->session; $self->push_message( -message => 'this is a test', -classification => 'ERROR', ); return "message pushed"; } sub third { my $self = shift; my $session = $self->session; return $self->tt_process( 'output.tt' ); } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1; CGI-Application-Plugin-MessageStack-0.34/t/08-capms_config_ac.t 0000644 0001750 0000147 00000004037 10504260761 024473 0 ustar jason webdev 0000000 0000000 use Test::More; # The cgiapp adds 1 more test to the mix... ## TEST PLAN ## #* capms_config w/ Automatic Clearing # * cgiapp w/ various configuration runmodes # * first request # - establish session # - call capms_config with -automatic_clearing # - push in some messages # * second request # - pass in session # - check output for message # * third request # - pass in session # - call messages() and compare #FILES: 08-capms_config_ac.t, TestAppConfigAC.pm, output.TMPL use lib './t'; use strict; BEGIN { eval "use CGI::Application::Plugin::Session"; plan skip_all => "CGI::Application::Plugin::Session required for this test" if $@; } plan tests => 7; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppConfigAC; my $testapp = TestAppConfigAC->new(QUERY=>CGI->new()); my $output = $testapp->run(); my $test_name; # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppConfigAC->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected outputs"; # testing for an array of data here... like( $output, qr/this is a test/, $test_name ); like( $output, qr/this is another test/, $test_name ); like( $output, qr/got your stuff updated/, $test_name ); like( $output, qr/another info/, $test_name ); like( $output, qr/some bad stuff/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppConfigAC->new( QUERY => $query ); $output = $testapp->run; $test_name = "good automatic clearing"; like( $output, qr/succeeded/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppConfigAC->new( QUERY => $query ); $output = $testapp->run; undef $testapp; # check & make sure that file doesn't exist... my $file = 't/cgisess_' . $session_id; $test_name = 'session flat file was deleted'; CGI-Application-Plugin-MessageStack-0.34/t/TestAppClear.pm 0000644 0001750 0000147 00000011760 10504260761 023654 0 ustar jason webdev 0000000 0000000 package TestAppClear; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; use Test::More; ## TEST PLAN ## #* messages # * first request: # - establish session # - push in a few messages # * second request: # - pass in session # - call messages() and compare data structure # * third request: # - pass in session # - call messages() with scope and compare data structure # * fourth request: # - pass in session # - call messages() with classification and compare data structure # * fifth request: # - pass in session # - call messages() with both scope & classification and compare data structure #FILES: 04-messages.t, TestMessages.pm sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third fourth fifth cleanup ) ] ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; $session->clear( [ '__CAP_MessageStack_Stack' ] ); # muhahahahaha $self->push_message( -message => 'this is a test', ); $self->push_message( -message => 'this is another test', -classification => 'INFO', ); $self->push_message( -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR', ); $self->push_message( -scope => 'start', -message => 'there was a problem', -classification => 'ERROR', ); $self->push_message( -scope => 'fourth', -message => 'got your stuff updated', -classification => 'INFO', ); $self->push_message( -scope => 'fourth', -message => 'another info', -classification => 'INFO', ); $self->push_message( -scope => 'fourth', -message => 'some bad stuff', -classification => 'ERROR', ); return "all set"; } sub second { my $self = shift; my $session = $self->session; $self->clear_messages(); my $messages = $self->messages(); my $expectation = [ ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub third { my $self = shift; my $session = $self->session; $self->clear_messages( -scope => 'fourth' ); my $messages = $self->messages(); my $expectation = [ { -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR' }, { -scope => 'start', -message => 'there was a problem', -classification => 'ERROR' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub fourth { my $self = shift; my $session = $self->session; $self->clear_messages( -classification => 'ERROR' ); my $messages = $self->messages(); my $expectation = [ { -message => 'this is a test' }, { -message => 'this is another test', -classification => 'INFO' }, { -scope => 'fourth', -message => 'got your stuff updated', -classification => 'INFO' }, { -scope => 'fourth', -message => 'another info', -classification => 'INFO' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub fifth { my $self = shift; my $session = $self->session; $self->clear_messages( -scope => 'fourth', -classification => 'ERROR' ); my $messages = $self->messages(); my $expectation = [ { -message => 'this is a test' }, { -message => 'this is another test', -classification => 'INFO' }, { -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR' }, { -scope => 'start', -message => 'there was a problem', -classification => 'ERROR' }, { -scope => 'fourth', -message => 'got your stuff updated', -classification => 'INFO' }, { -scope => 'fourth', -message => 'another info', -classification => 'INFO' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1; CGI-Application-Plugin-MessageStack-0.34/t/02-check_output.t 0000644 0001750 0000147 00000005115 10504260761 024065 0 ustar jason webdev 0000000 0000000 use Test::More; # the cgiapp adds one more to the test # above ## TEST PLAN ## # * cgiapp w/ html-template # * first request: # - establish/check for session # - check output for ! message # * second request: # - pass in session # - push an info message # * third request: # - pass in session # - check output for message # - check message for proper classification # * fourth request: # - pass in session # - call messages() and compare # - check output for 'succeeded' # FILES: 02-check_output.t, TestAppOutput.pm, output.TMPL use lib './t'; use strict; BEGIN { eval "use CGI::Application::Plugin::Session"; plan skip_all => "CGI::Application::Plugin::Session required for this test" if $@; } plan tests => 10; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppOutput; my $testapp = TestAppOutput->new(QUERY=>CGI->new()); my $output = $testapp->run(); # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request my $test_name = 'session cookie was setup'; like( $output, qr/Set-Cookie: CGISESSID=\w+/, $test_name ); $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $test_name = "got the session id ($session_id)"; ok( $session_id, $test_name ); $test_name = "message isn't in output"; unlike( $output, qr/this is a test/, $test_name ); $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppOutput->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output"; like( $output, qr/message pushed/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppOutput->new( QUERY => $query ); $output = $testapp->run; $test_name = "message is in the output"; like( $output, qr/this is a test/, $test_name ); $test_name = "classification was in place"; like( $output, qr/div class="ERROR"/, $test_name ); $query->param( -name => 'rm', -value => 'fourth' ); $testapp = TestAppOutput->new( QUERY => $query ); $output = $testapp->run; $test_name = "messages weren't automatically cleared"; like( $output, qr/succeeded/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppOutput->new( QUERY => $query ); $output = $testapp->run; $test_name = 'got the expected output from the cleanup runmode'; like( $output, qr/session deleted/, $test_name ); undef $testapp; # check & make sure that file doesn't exist... my $file = 't/cgisess_' . $session_id; $test_name = 'session flat file was deleted'; ok( ! -e $file, $test_name ); CGI-Application-Plugin-MessageStack-0.34/t/TestAppOutput.pm 0000644 0001750 0000147 00000004236 10504260761 024126 0 ustar jason webdev 0000000 0000000 package TestAppOutput; use base 'CGI::Application'; use Test::More; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; ## TEST PLAN ## # * cgiapp w/ html-template # * first request: # - establish session # - check output for ! message # * second request: # - pass in session # - push an info message # * third request: # - pass in session # - check output for message # - check message for proper classification # FILES: 02-check_output.t, TestAppOutput.pm, output.TMPL sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third fourth cleanup ) ] ); $self->tmpl_path( './t' ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub second { my $self = shift; my $session = $self->session; $self->push_message( -message => 'this is a test', -classification => 'ERROR', ); return "message pushed"; } sub third { my $self = shift; my $session = $self->session; my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub fourth { my $self = shift; my $session = $self->session; my $messages = $self->messages(); my $expectation = [ { -message => 'this is a test', -classification => 'ERROR' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1; CGI-Application-Plugin-MessageStack-0.34/t/07-template_toolkit.t 0000644 0001750 0000147 00000004304 10504260761 024754 0 ustar jason webdev 0000000 0000000 use Test::More; ## TEST PLAN ## # same as 02-check_output.t, but using a Template # * cgiapp w/ html-template # * first request: # - establish/check for session # - check output for ! message # * second request: # - pass in session # - push an info message # * third request: # - pass in session # - check output for message # - check message for proper classification # FILES: 07-template_toolkit.t, TestAppTT.pm, output.tt use lib './t'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; BEGIN { eval "use TestAppTT"; plan skip_all => "CGI::Application::Plugin::TT 0.09 required for testing TT integration" if $@; } use CGI; plan tests => 8; my $testapp = TestAppTT->new(QUERY=>CGI->new()); my $output = $testapp->run(); # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request my $test_name = 'session cookie was setup'; like( $output, qr/Set-Cookie: CGISESSID=\w+/, $test_name ); $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $test_name = "got the session id ($session_id)"; ok( $session_id, $test_name ); $test_name = "message isn't in output"; unlike( $output, qr/this is a test/, $test_name ); $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppTT->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output"; like( $output, qr/message pushed/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppTT->new( QUERY => $query ); $output = $testapp->run; $test_name = "message is in the output"; like( $output, qr/this is a test/, $test_name ); $test_name = "classification was in place"; like( $output, qr/div class="ERROR"/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppTT->new( QUERY => $query ); $output = $testapp->run; $test_name = 'got the expected output from the cleanup runmode'; like( $output, qr/session deleted/, $test_name ); undef $testapp; # check & make sure that file doesn't exist... my $file = 't/cgisess_' . $session_id; $test_name = 'session flat file was deleted'; ok( ! -e $file, $test_name ); CGI-Application-Plugin-MessageStack-0.34/t/10-capms_config_no_session.t 0000644 0001750 0000147 00000002311 10504260761 026251 0 ustar jason webdev 0000000 0000000 use Test::More tests => 5; ## TEST PLAN ## # * capms_config w/ dont_use_session # * cgiapp w/ dont_use_session config # * first request # - push in some messages # - check for no messages # - load_tmpl and check for output # * second request # - load_tmpl and check for no messages in output # FILES: 10-capms_config_no_session.t, TestAppConfigNoSession.pm, output.TMPL use lib './t'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppConfigNoSession; my $cgiapp; my $output; eval { $cgiapp = TestAppConfigNoSession->new(QUERY=>CGI->new()); $output = $cgiapp->run(); }; my $test_name = "didn't die() w/ no session"; ok( !$@, $test_name ); $test_name = "output has message in it"; like( $output, qr/this is a test/, $test_name ); $test_name = "output has classification in it"; like( $output, qr/ERROR/, $test_name ); my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $cgiapp = TestAppConfigNoSession->new(QUERY=>$query); $output = $cgiapp->run(); $test_name = "output doesn't have message in it"; unlike( $output, qr/this is a test/, $test_name ); $test_name = "output doesn't have classification in it"; unlike( $output, qr/"ERROR"/, $test_name ); CGI-Application-Plugin-MessageStack-0.34/t/01-nosession.t 0000644 0001750 0000147 00000000652 10504260761 023410 0 ustar jason webdev 0000000 0000000 use Test::More tests => 2; use lib './t'; use strict; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppNoSession; eval { my $t1_obj = TestAppNoSession->new(QUERY=>CGI->new()); my $t1_output = $t1_obj->run(); }; my $err = $@; my $test_name = "testing for die() since we did't use a session"; ok( $err, $test_name ); $test_name = 'testing for right error message'; ok( $err =~ /No session object!/, $test_name ); CGI-Application-Plugin-MessageStack-0.34/t/TestAppConfigAC.pm 0000644 0001750 0000147 00000006146 10504260761 024241 0 ustar jason webdev 0000000 0000000 package TestAppConfigAC; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::MessageStack; use Test::More; ## TEST PLAN ## #* capms_config w/ Automatic Clearing # * cgiapp w/ various configuration runmodes # * first request # - establish session # - call capms_config with -automatic_clearing # - push in some messages # * second request # - pass in session # - check output for message # * third request # - pass in session # - call messages() and compare #FILES: 08-capms_config_ac.t, TestAppConfigAC.pm, output.TMPL sub setup { my $self = shift; $self->mode_param( 'rm' ); $self->run_modes( [ qw( start second third cleanup ) ] ); $self->tmpl_path( './t' ); } sub cgiapp_init { my $self = shift; $self->session_config({ CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory=>'t/'} ], SEND_COOKIE => 1, COOKIE_PARAMS => { -path => '/', -domain => 'mydomain.com', -expires => '+3M', }, }); } sub start { my $self = shift; my $session = $self->session; $self->push_message( -message => 'this is a test', ); $self->push_message( -message => 'this is another test', -classification => 'INFO', ); $self->push_message( -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR', ); $self->push_message( -scope => 'start', -message => 'there was a problem', -classification => 'ERROR', ); $self->push_message( -scope => 'second', -message => 'got your stuff updated', -classification => 'INFO', ); $self->push_message( -scope => 'second', -message => 'another info', -classification => 'INFO', ); $self->push_message( -scope => 'second', -message => 'some bad stuff', -classification => 'ERROR', ); $self->capms_config( -automatic_clearing => 1 ); return "all set"; } sub second { my $self = shift; my $session = $self->session(); my $template = $self->load_tmpl( 'output.TMPL', 'die_on_bad_params' => 0 ); $template->output; } sub third { my $self = shift; my $session = $self->session; my $messages = $self->messages(); my $expectation = [ { -scope => 'invalid', -message => 'bad password!', -classification => 'ERROR' }, { -scope => 'start', -message => 'there was a problem', -classification => 'ERROR' }, ]; my $message = 'failed'; if ( is_deeply( $expectation, $messages, undef ) ) { $message = 'succeeded'; } return $message; } sub cleanup { my $self = shift; $self->session->delete; return "session deleted"; } 1; CGI-Application-Plugin-MessageStack-0.34/t/06-pop_message.t 0000644 0001750 0000147 00000005242 10504260761 023677 0 ustar jason webdev 0000000 0000000 use Test::More; # five tests below and then one from the TestAppPop cgiapp ## TEST PLAN ## #* pop_message # * first request: # - establish session # - clear private session var # - push in a few messages # * second request: # - pass in session # - call pop_message() and compare # * recall first request # * third request: # - pass in session # - call pop_message() with scope and compare # * recall first request # * fourth request: # - pass in session # - call pop_message() with classification and compare # * recall first request # * fifth request: # - pass in session # - call pop_message() with scope & classification and compare # * sixth request: # - pass in session # - compare the remaining messages() #FILES: 06-pop_message.t, TestAppPop.pm use lib './t'; use strict; BEGIN { eval "use CGI::Application::Plugin::Session"; plan skip_all => "CGI::Application::Plugin::Session required for this test" if $@; } plan tests => 6; $ENV{CGI_APP_RETURN_ONLY} = 1; use CGI; use TestAppPop; my $testapp = TestAppPop->new(QUERY=>CGI->new()); my $output = $testapp->run(); # $output should have the session setup w/ a cookie # Get the ID # to establish the session in a second request $output =~ /Set-Cookie: CGISESSID=(\w+);/; my $session_id = $1; $ENV{HTTP_COOKIE} = "CGISESSID=$session_id"; my $query = new CGI; $query->param( -name => 'rm', -value => 'second' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; my $test_name = "got the expected output (pop'd the last msg)"; like( $output, qr/succeeded/, $test_name ); $query->param( -name => 'rm', -value => 'third' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (pop'd the scoped msg)"; like( $output, qr/succeeded/, $test_name ); $query->param( -name => 'rm', -value => 'fourth' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (pop'd the classified message)"; like( $output, qr/succeeded/, $test_name ); $query->param( -name => 'rm', -value => 'fifth' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; $test_name = "got the expected output (pop'd both the scope & classification message)"; like( $output, qr/succeeded/, $test_name ); $query->param( -name => 'rm', -value => 'sixth' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; $test_name = "the remaining data structure is as expected"; like( $output, qr/succeeded/, $test_name ); # let's clean up $query->param( -name => 'rm', -value => 'cleanup' ); $testapp = TestAppPop->new( QUERY => $query ); $output = $testapp->run; undef $testapp; CGI-Application-Plugin-MessageStack-0.34/t/output.tt 0000644 0001750 0000147 00000000501 10504260761 022667 0 ustar jason webdev 0000000 0000000
hello world
[% FOREACH CAP_Messages %]