Catalyst-View-Template-PHP

 view release on metacpan or  search on metacpan

t/04-post.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 $entrypoint = "http://localhost/foo";

{
    my $response = request('http://localhost/vars.php');
    ok( $response, 'response no params ok' );
    my $content = eval { $response->content };
    ok( $content =~ /_GET = array *\(\s*\)/, '$_GET is empty' );
    ok( $content =~ /_POST = array *\(\s*\)/, '$_POST is empty' );
    ok( $content =~ /_REQUEST = array *\(\s*\)/, '$_REQUEST is empty' );
    ok( $content =~ /_SERVER = array/ &&
	$content !~ /_SERVER = array *\(\s*\)/, '$_SERVER not empty' );
    ok( $content =~ /_ENV = array/ &&
	$content !~ /_ENV = array *\(\s*\)/, '$_ENV not empty' );
    ok( $content =~ /_COOKIE = array *\(\s*\)/, '$_COOKIE is empty' );

$DB::single=1;
    $response = request POST 'http://localhost/vars.php', [
	abc => 123,
	def => 456
    ];
$DB::single = 1;
    ok( $response, 'response simple post ok' );
    $content = eval { $response->content };
    ok( $content =~ /_GET = array *\(\s*\)/, '$_GET is empty' );
    ok( $content !~ /_POST = array *\(\s*\)/, '$_POST not empty' );
    ok( $content =~ /_POST.*abc.*=.*123.*_REQUEST/s, '$_POST["abc"] ok');
    ok( $content =~ /_POST.*def.*=.*456.*_REQUEST/s, '$_POST["def"] ok');
    ok( $content !~ /_REQUEST = array *\(\s*\)/, '$_REQUEST not empty' );
    ok( $content =~ /_REQUEST.*abc.*=.*123.*_SERVER/s &&
	$content =~ /_REQUEST.*def.*=.*456.*_SERVER/s, '$_REQUEST mimics $_POST' );
    ok( $content =~ /_SERVER = array/ &&
	$content !~ /_SERVER = array *\(\s*\)/, '$_SERVER not empty' );
    ok( $content =~ /_ENV = array/ &&
	$content !~ /_ENV = array *\(\s*\)/, '$_ENV not empty' );
    ok( $content =~ /_COOKIE = array *\(\s*\)/, '$_COOKIE is empty' );



    # When PHP receives a duplicate param name, it ignores all values
    # except the last value.



( run in 0.370 second using v1.01-cache-2.11-cpan-39bf76dae61 )