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

(-)a/C4/XSLT.pm (+48 lines)
Lines 475-480 sub engine { Link Here
475
    return $engine;
475
    return $engine;
476
}
476
}
477
477
478
=head2 CustomXSLTExportList
479
480
 Returns list of file for custom xslt conversion
481
482
=cut
483
484
sub CustomXSLTExportList {
485
    my $opac = shift; # opac (1) vs intranet (0)
486
    return [] if $opac && C4::Context->preference('OpacExportOptions') !~ /custom/;
487
488
    my @tabFiles;
489
490
    my $dir = C4::Context->config( $opac ? 'opachtdocs' : 'intrahtdocs') .
491
                      '/' . C4::Context->preference( $opac ? "opacthemes" : "template") .
492
                      '/' . C4::Languages::getlanguage() .
493
                      '/xslt/biblioexport';
494
    my @files = glob qq("$dir/*.xsl");
495
    foreach my $file (@files) {
496
        if ( -f "$file" ) {
497
            (my $text = $file) =~ s/.*\///g;
498
499
            ## Get title of the option
500
            my $dom;
501
            eval { $dom = XML::LibXML->load_xml( location => $file ); };
502
            next unless $dom;
503
504
            my $node = $dom->documentElement();
505
            my $title = $node->{"title"};
506
            ($title = $text) =~ s/\.xsl// unless defined $title;
507
508
            # Get output format
509
            # There should only be one xsl:output node, so taking the first one only is OK
510
            $node = @{$node->findnodes("xsl:output")}[0];
511
            my $outputformat= "";
512
            $outputformat = $node->{"method"} if $node;
513
            $outputformat = "txt" if ($outputformat eq "" || $outputformat eq "text");
514
515
            my %row = (
516
                value       => $text,
517
                filename    => $title,
518
                format      => $outputformat,
519
            );
520
521
            push @tabFiles, \%row;
522
        }
523
    }
524
    return \@tabFiles;
525
}
478
1;
526
1;
479
527
480
__END__
528
__END__
(-)a/t/db_dependent/XSLT.t (-20 / +12 lines)
Lines 1-20 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
2
20
use MARC::Record;
3
use MARC::Record;
Lines 26-40 use t::lib::Mocks; Link Here
26
use Koha::Database;
9
use Koha::Database;
27
use Koha::Libraries;
10
use Koha::Libraries;
28
use Koha::ItemTypes;
11
use Koha::ItemTypes;
12
use C4::XSLT;
29
13
30
BEGIN {
14
BEGIN {
31
    use_ok('C4::XSLT', qw( transformMARCXML4XSLT getAuthorisedValues4MARCSubfields buildKohaItemsNamespace ));
15
    use_ok('C4::XSLT', qw( transformMARCXML4XSLT getAuthorisedValues4MARCSubfields buildKohaItemsNamespace ));
32
}
16
}
33
17
34
my $schema  = Koha::Database->new->schema;
18
our $schema = Koha::Database->new->schema;
35
my $builder = t::lib::TestBuilder->new;
36
19
20
# Here we go
37
$schema->storage->txn_begin;
21
$schema->storage->txn_begin;
22
subtest 'CustomXSLTExportList: Check export options' => sub {
23
    plan tests => 2;
24
    t::lib::Mocks::mock_preference('OpacExportOptions', 'custom');
25
        my $list = C4::XSLT::CustomXSLTExportList(1);
26
    is( @$list>0, 1, 'We expect at least one result: simple export' );
27
    t::lib::Mocks::mock_preference('OpacExportOptions', 'dc');
28
    $list = C4::XSLT::CustomXSLTExportList(1);
29
    is( @$list, 0, 'We expect an empty list now' );
30
};
38
31
39
subtest 'transformMARCXML4XSLT tests' => sub {
32
subtest 'transformMARCXML4XSLT tests' => sub {
40
    plan tests => 1;
33
    plan tests => 1;
41
- 

Return to bug 17385