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

(-)a/t/XSLT.t (-68 lines)
Lines 1-68 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
use Test::More tests => 1;
20
21
use File::Temp;
22
use File::Path qw/make_path/;
23
24
use t::lib::Mocks;
25
26
use C4::XSLT;
27
28
my $dir = File::Temp->newdir();
29
my @themes = ('prog', 'test');
30
my @langs = ('en', 'es-ES');
31
32
subtest 'Tests moved from t' => sub {
33
    plan tests => 8;
34
35
    # create temporary files to be tested later
36
    foreach my $theme (@themes) {
37
        foreach my $lang (@langs) {
38
            make_path("$dir/$theme/$lang/xslt");
39
            open my $fh, '>', "$dir/$theme/$lang/xslt/my_file.xslt";
40
            print $fh "Theme $theme, language $lang";
41
            close $fh;
42
        }
43
    }
44
45
    sub find_and_slurp {
46
        my ($dir, $theme, $lang) = @_;
47
48
        my $filename = C4::XSLT::_get_best_default_xslt_filename($dir, $theme, $lang, 'my_file.xslt');
49
        open my $fh, '<', $filename;
50
        my $str = <$fh>;
51
        close $fh;
52
        return $str;
53
    }
54
55
    # These tests verify that we're finding the right XSLT file when present,
56
    # and falling back to the right XSLT file when an exact match is not present.
57
    is(find_and_slurp($dir, 'test', 'en'   ), 'Theme test, language en',    'Found test/en');
58
    is(find_and_slurp($dir, 'test', 'es-ES'), 'Theme test, language es-ES', 'Found test/es-ES');
59
    is(find_and_slurp($dir, 'prog', 'en',  ), 'Theme prog, language en',    'Found test/en');
60
    is(find_and_slurp($dir, 'prog', 'es-ES'), 'Theme prog, language es-ES', 'Found test/es-ES');
61
    is(find_and_slurp($dir, 'test', 'fr-FR'), 'Theme test, language en',    'Fell back to test/en for test/fr-FR');
62
    is(find_and_slurp($dir, 'nope', 'es-ES'), 'Theme prog, language es-ES', 'Fell back to prog/es-ES for nope/es-ES');
63
    is(find_and_slurp($dir, 'nope', 'fr-FR'), 'Theme prog, language en',    'Fell back to prog/en for nope/fr-FR');
64
65
    my $matching_string = q{<syspref name="singleBranchMode">0</syspref>};
66
    my $sysprefs_xml = C4::XSLT::get_xslt_sysprefs();
67
    ok( $sysprefs_xml =~ m/$matching_string/, 'singleBranchMode has a value of 0');
68
};
(-)a/t/db_dependent/XSLT.t (-6 / +49 lines)
Lines 17-24 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use File::Temp;
21
use File::Path qw/make_path/;
20
use MARC::Record;
22
use MARC::Record;
21
use Test::More tests => 3;
23
use Test::More tests => 4;
22
use Test::Warn;
24
use Test::Warn;
23
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
24
use t::lib::Mocks;
26
use t::lib::Mocks;
Lines 34-43 BEGIN { Link Here
34
my $schema  = Koha::Database->new->schema;
36
my $schema  = Koha::Database->new->schema;
35
my $builder = t::lib::TestBuilder->new;
37
my $builder = t::lib::TestBuilder->new;
36
38
37
$schema->storage->txn_begin;
39
subtest 'Tests moved from t' => sub {
40
    plan tests => 8;
41
    $schema->storage->txn_begin;
42
43
    my $dir = File::Temp->newdir();
44
    my @themes = ('prog', 'test');
45
    my @langs = ('en', 'es-ES');
46
47
    # create temporary files to be tested later
48
    foreach my $theme (@themes) {
49
        foreach my $lang (@langs) {
50
            make_path("$dir/$theme/$lang/xslt");
51
            open my $fh, '>', "$dir/$theme/$lang/xslt/my_file.xslt";
52
            print $fh "Theme $theme, language $lang";
53
            close $fh;
54
        }
55
    }
56
57
    sub find_and_slurp {
58
        my ($dir, $theme, $lang) = @_;
59
60
        my $filename = C4::XSLT::_get_best_default_xslt_filename($dir, $theme, $lang, 'my_file.xslt');
61
        open my $fh, '<', $filename;
62
        my $str = <$fh>;
63
        close $fh;
64
        return $str;
65
    }
66
67
    # These tests verify that we're finding the right XSLT file when present,
68
    # and falling back to the right XSLT file when an exact match is not present.
69
    is(find_and_slurp($dir, 'test', 'en'   ), 'Theme test, language en',    'Found test/en');
70
    is(find_and_slurp($dir, 'test', 'es-ES'), 'Theme test, language es-ES', 'Found test/es-ES');
71
    is(find_and_slurp($dir, 'prog', 'en',  ), 'Theme prog, language en',    'Found test/en');
72
    is(find_and_slurp($dir, 'prog', 'es-ES'), 'Theme prog, language es-ES', 'Found test/es-ES');
73
    is(find_and_slurp($dir, 'test', 'fr-FR'), 'Theme test, language en',    'Fell back to test/en for test/fr-FR');
74
    is(find_and_slurp($dir, 'nope', 'es-ES'), 'Theme prog, language es-ES', 'Fell back to prog/es-ES for nope/es-ES');
75
    is(find_and_slurp($dir, 'nope', 'fr-FR'), 'Theme prog, language en',    'Fell back to prog/en for nope/fr-FR');
76
77
    my $matching_string = q{<syspref name="singleBranchMode">0</syspref>};
78
    my $sysprefs_xml = C4::XSLT::get_xslt_sysprefs();
79
    ok( $sysprefs_xml =~ m/$matching_string/, 'singleBranchMode has a value of 0');
80
81
    $schema->storage->txn_rollback;
82
};
38
83
39
subtest 'buildKohaItemsNamespace status tests' => sub {
84
subtest 'buildKohaItemsNamespace status tests' => sub {
40
    plan tests => 18;
85
    plan tests => 18;
86
    $schema->storage->txn_begin;
41
87
42
    t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2');
88
    t::lib::Mocks::mock_preference('Reference_NFL_Statuses', '1|2');
43
    t::lib::Mocks::mock_preference( 'OPACResultsLibrary', 'holdingbranch' );
89
    t::lib::Mocks::mock_preference( 'OPACResultsLibrary', 'holdingbranch' );
Lines 152-163 subtest 'buildKohaItemsNamespace status tests' => sub { Link Here
152
    like($xml,qr{<substatus>Recall waiting</substatus>},"Waiting status takes precedence over In transit (recalls)");
198
    like($xml,qr{<substatus>Recall waiting</substatus>},"Waiting status takes precedence over In transit (recalls)");
153
    t::lib::Mocks::mock_preference('UseRecalls', 0);
199
    t::lib::Mocks::mock_preference('UseRecalls', 0);
154
200
201
    $schema->storage->txn_rollback;
155
};
202
};
156
203
157
$schema->storage->txn_rollback;
158
159
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub {
204
subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub {
160
161
    plan tests => 23;
205
    plan tests => 23;
162
206
163
    $schema->storage->txn_begin;
207
    $schema->storage->txn_begin;
164
- 

Return to bug 33733