3 # Copyright 2022 Rijksmuseum
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use Test::More tests => 1;
27 use Koha::XSLT::HTTPS;
29 subtest 'load' => sub {
33 my $lwp_object = Test::MockObject->new;
34 my $response = Test::MockObject->new;
35 $response->mock( 'is_success', sub { return 0 } );
36 $lwp_object->mock( 'get', sub { return $response; } );
37 my $lwp_mod = Test::MockModule->new( 'LWP::UserAgent' );
38 $lwp_mod->mock( 'new', sub { return $lwp_object } );
41 throws_ok { Koha::XSLT::HTTPS->load; } 'Koha::Exceptions::XSLT::MissingFilename', 'No filename';
42 throws_ok { Koha::XSLT::HTTPS->load(q{}); } 'Koha::Exceptions::XSLT::MissingFilename', 'Empty filename';
43 my $result = Koha::XSLT::HTTPS->load('filename.xsl');
44 is( ref($result), 'HASH', 'Should return hash' );
45 is( exists $result->{location}, 1, 'Hash key location found' );
46 is( $result->{location}, 'filename.xsl', 'Value for location key' );
48 # Mock returns no success
49 throws_ok { Koha::XSLT::HTTPS->load('https://myfavoritexsltsite.com/test1.xsl'); }
50 'Koha::Exceptions::XSLT::FetchFailed', 'Fetch failed';
53 $response->mock( 'is_success', sub { return 1 } );
54 $response->mock( 'decoded_content', sub { return 'supposed_xslt_code' } );
55 $result = Koha::XSLT::HTTPS->load('https://myfavoritexsltsite.com/test2.xsl');
56 is( ref($result), 'HASH', 'Should return hash' );
57 is( exists $result->{string}, 1, 'Hash key string found' );
58 is( $result->{string}, 'supposed_xslt_code', 'Value for string key' );