The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
use strict;
use FindBin;
use Test::More;
use Plack::Test;

use HTML::Mason::PSGIHandler;

my $h = HTML::Mason::PSGIHandler->new(
    comp_root => $FindBin::Bin,
);

my @apps = (
  sub { $h->handle_psgi(@_) },
  $h->as_psgi,
  HTML::Mason::PSGIHandler->new_psgi(comp_root => $FindBin::Bin),
);

for my $app (@apps) {
    test_psgi app => $app, client => sub {
        my $cb = shift;
        my $res = $cb->(
            HTTP::Request->new(GET => "http://localhost/hello.mhtml?foo=bar")
        );
        is $res->code, 200, 'got 200 response';
        like $res->content, qr/Hello World Foo/;
        like $res->content, qr/foo,bar/;

        $res = $cb->(
            HTTP::Request->new(GET => "http://localhost/hello.mhtml?403=1")
        );
        is $res->code, 403, 'got 403 response';

    }
}

done_testing;