Catalyst-View-Template-PHP
view release on metacpan or search on metacpan
t/12-postprocess.t view on Meta::CPAN
use FindBin;
use lib "$FindBin::Bin/lib";
use strict;
use warnings;
use Test::More;
use Catalyst::Test 'TestApp';
use Data::Dumper;
use HTTP::Request::Common; # reqd for POST requests
eval "use PHP 0.13";
if ($@) {
plan skip_all => "PHP 0.13 needed for testing";
}
BEGIN {
no warnings 'redefine';
*Catalyst::Test::local_request = sub {
my ($class, $req) = @_;
my $app = ref($class) eq "CODE" ? $class : $class->_finalized_psgi_app;
my $ret;
require Plack::Test;
Plack::Test::test_psgi(
app => sub { $app->( %{ $_[0] } ) },
client => sub { $ret = shift->{request} } );
return $ret;
};
}
{
my ($response, $content);
%TestApp::Controller::Root::stash_globals = ();
%TestApp::View::PHPTest::phptest_globals = ();
$response = request 'http://localhost/globals.php';
ok( $response, 'response from globals.php ok' );
$content = eval { $response->content };
ok( $content, 'content from globals.php available' );
ok( $content =~ /g$_ not set/, "g$_ not set" ) for 1..5;
%TestApp::Controller::Root::stash_globals = (
g1 => 123,
g2 => 456
);
$TestApp::View::PHPTest::postprocessor = sub {
my $output = shift;
$output =~ s/5/7/g;
$output;
};
$response = request 'http://localhost/globals.php';
ok( $response, 'response with stash_globals ok' );
$content = eval { $response->content };
ok( $content, 'response has content' );
ok( $content =~ /g1=123/, 'g1 set in stash' );
ok( $content =~ /g2=476/, 'g2 set in stash, output postprocessed' );
ok( $content =~ /g7 not set/, 'g5 not set, output postprocesed' );
%TestApp::Controller::Root::stash_globals = (
g3 => "foo",
g4 => [ 1, 3, 5 ]
);
( run in 0.806 second using v1.01-cache-2.11-cpan-39bf76dae61 )