View | Details | Raw Unified | Return to bug 33967
Collapse All | Expand All

(-)a/t/Koha/Middleware/SetEnv.t (-1 / +85 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
#
4
# Copyright 2023 Prosentient Systems
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# Koha is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
use strict;
22
use warnings;
23
use Test::More tests => 2;
24
use Test::Warn;
25
26
use t::lib::Mocks;
27
use_ok("Koha::Middleware::SetEnv");
28
use Plack::Builder;
29
use Plack::Util;
30
31
subtest 'Test $env integrity' => sub {
32
    plan tests => 2;
33
34
    my $app = sub {
35
        my $resp = [
36
            200,
37
            [
38
                'Content-Type',
39
                'text/plain',
40
                'Content-Length',
41
                12
42
            ],
43
            ['Koha is cool']
44
        ];
45
        return $resp;
46
    };
47
    my $env               = {};
48
    my $correct_hash_addr = "$env";
49
    my @ref_to_test       = ();
50
51
    $app = builder {
52
        enable sub {
53
            my $app = shift;
54
            sub {
55
                my $env = shift;
56
                push( @ref_to_test, "$env" );
57
58
                # do preprocessing
59
                my $res = $app->($env);
60
61
                # do postprocessing
62
                return $res;
63
            };
64
        };
65
        enable "+Koha::Middleware::SetEnv";
66
        enable sub {
67
            my $app = shift;
68
            sub {
69
                my $env = shift;
70
                push( @ref_to_test, "$env" );
71
72
                # do preprocessing
73
                my $res = $app->($env);
74
75
                # do postprocessing
76
                return $res;
77
            };
78
        };
79
        $app;
80
    };
81
82
    my $res = Plack::Util::run_app( $app, $env );
83
    is( $correct_hash_addr, $ref_to_test[0], "First hash ref address correct before middleware applied" );
84
    is( $correct_hash_addr, $ref_to_test[1], "Second hash ref address correct after middleware applied" );
85
};

Return to bug 33967