Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# |
4 |
# Copyright 2020 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 |
|
32 |
|
33 |
|
34 |
subtest 'Test $env integrity' => sub { |
35 |
plan tests => 2; |
36 |
|
37 |
my $app = sub { |
38 |
my $resp = [ |
39 |
200, |
40 |
[ |
41 |
'Content-Type', |
42 |
'text/plain', |
43 |
'Content-Length', |
44 |
12 |
45 |
], |
46 |
[ |
47 |
'Koha is cool' |
48 |
] |
49 |
]; |
50 |
return $resp; |
51 |
}; |
52 |
my $env = {}; |
53 |
my $correct_hash_addr = "$env"; |
54 |
my @ref_to_test = (); |
55 |
|
56 |
$app = builder { |
57 |
enable sub { |
58 |
my $app = shift; |
59 |
sub { |
60 |
my $env = shift; |
61 |
push(@ref_to_test,"$env"); |
62 |
# do preprocessing |
63 |
my $res = $app->($env); |
64 |
# do postprocessing |
65 |
return $res; |
66 |
}; |
67 |
}; |
68 |
enable "+Koha::Middleware::SetEnv"; |
69 |
enable sub { |
70 |
my $app = shift; |
71 |
sub { |
72 |
my $env = shift; |
73 |
push(@ref_to_test,"$env"); |
74 |
# do preprocessing |
75 |
my $res = $app->($env); |
76 |
# do postprocessing |
77 |
return $res; |
78 |
}; |
79 |
}; |
80 |
$app; |
81 |
}; |
82 |
|
83 |
my $res = Plack::Util::run_app($app, $env); |
84 |
is($correct_hash_addr,$ref_to_test[0],"First hash ref address correct before middleware applied"); |
85 |
is($correct_hash_addr,$ref_to_test[1],"Second hash ref address correct after middleware applied"); |
86 |
}; |