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

(-)a/C4/XSLT.pm (+48 lines)
Lines 410-415 sub engine { Link Here
410
    return $engine;
410
    return $engine;
411
}
411
}
412
412
413
=head2 CustomXSLTExportList
414
415
 Returns list of file for custom xslt conversion
416
417
=cut
418
419
sub CustomXSLTExportList {
420
    my $opac = shift; # opac (1) vs intranet (0)
421
    return [] if $opac && C4::Context->preference('OpacExportOptions') !~ /custom/;
422
423
    my @tabFiles;
424
425
    my $dir = C4::Context->config( $opac ? 'opachtdocs' : 'intrahtdocs') .
426
                      '/' . C4::Context->preference( $opac ? "opacthemes" : "template") .
427
                      '/' . C4::Languages::getlanguage() .
428
                      '/xslt/biblioexport';
429
    my @files = glob qq("$dir/*.xsl");
430
    foreach my $file (@files) {
431
        if ( -f "$file" ) {
432
            (my $text = $file) =~ s/.*\///g;
433
434
            ## Get title of the option
435
            my $dom;
436
            eval { $dom = XML::LibXML->load_xml( location => $file ); };
437
            next unless $dom;
438
439
            my $node = $dom->documentElement();
440
            my $title = $node->{"title"};
441
            ($title = $text) =~ s/\.xsl// unless defined $title;
442
443
            # Get output format
444
            # There should only be one xsl:output node, so taking the first one only is OK
445
            $node = @{$node->findnodes("xsl:output")}[0];
446
            my $outputformat= "";
447
            $outputformat = $node->{"method"} if $node;
448
            $outputformat = "txt" if ($outputformat eq "" || $outputformat eq "text");
449
450
            my %row = (
451
                value       => $text,
452
                filename    => $title,
453
                format      => $outputformat,
454
            );
455
456
            push @tabFiles, \%row;
457
        }
458
    }
459
    return \@tabFiles;
460
}
413
1;
461
1;
414
462
415
__END__
463
__END__
(-)a/t/db_dependent/XSLT.t (-31 / +14 lines)
Lines 1-37 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;
1
use Modern::Perl;
19
20
use Test::More tests => 2;
2
use Test::More tests => 2;
21
use Test::Warn;
22
use t::lib::TestBuilder;
23
use t::lib::Mocks;
24
25
use Koha::ItemTypes;
26
3
27
BEGIN {
4
use t::lib::Mocks;
28
    use_ok('C4::XSLT');
5
use C4::XSLT;
29
}
6
use Koha::Database;
30
7
31
my $schema  = Koha::Database->new->schema;
8
our $schema = Koha::Database->new->schema;
32
my $builder = t::lib::TestBuilder->new;
33
9
10
# Here we go
34
$schema->storage->txn_begin;
11
$schema->storage->txn_begin;
12
subtest 'CustomXSLTExportList: Check export options' => sub {
13
    plan tests => 2;
14
    t::lib::Mocks::mock_preference('OpacExportOptions', 'custom');
15
        my $list = C4::XSLT::CustomXSLTExportList(1);
16
    is( @$list>0, 1, 'We expect at least one result: simple export' );
17
    t::lib::Mocks::mock_preference('OpacExportOptions', 'dc');
18
    $list = C4::XSLT::CustomXSLTExportList(1);
19
    is( @$list, 0, 'We expect an empty list now' );
20
};
35
21
36
subtest 'buildKohaItemsNamespace status tests' => sub {
22
subtest 'buildKohaItemsNamespace status tests' => sub {
37
    plan tests => 13;
23
    plan tests => 13;
Lines 111-118 subtest 'buildKohaItemsNamespace status tests' => sub { Link Here
111
    });
97
    });
112
    $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
98
    $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
113
    like($xml,qr{<status>Pending hold</status>},"Pending status takes precedence over all");
99
    like($xml,qr{<status>Pending hold</status>},"Pending status takes precedence over all");
114
115
116
};
100
};
117
subtest  'CustomXSLTExportList: Caching' => sub {
101
subtest  'CustomXSLTExportList: Caching' => sub {
118
    plan tests => 1;
102
    plan tests => 1;
119
- 

Return to bug 17385