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

(-)a/C4/XSLT.pm (+48 lines)
Lines 409-414 sub engine { Link Here
409
    return $engine;
409
    return $engine;
410
}
410
}
411
411
412
=head2 CustomXSLTExportList
413
414
 Returns list of file for custom xslt conversion
415
416
=cut
417
418
sub CustomXSLTExportList {
419
    my $opac = shift; # opac (1) vs intranet (0)
420
    return [] if $opac && C4::Context->preference('OpacExportOptions') !~ /custom/;
421
422
    my @tabFiles;
423
424
    my $dir = C4::Context->config( $opac ? 'opachtdocs' : 'intrahtdocs') .
425
                      '/' . C4::Context->preference( $opac ? "opacthemes" : "template") .
426
                      '/' . C4::Languages::getlanguage() .
427
                      '/xslt/biblioexport';
428
    my @files = glob qq("$dir/*.xsl");
429
    foreach my $file (@files) {
430
        if ( -f "$file" ) {
431
            (my $text = $file) =~ s/.*\///g;
432
433
            ## Get title of the option
434
            my $dom;
435
            eval { $dom = XML::LibXML->load_xml( location => $file ); };
436
            next unless $dom;
437
438
            my $node = $dom->documentElement();
439
            my $title = $node->{"title"};
440
            ($title = $text) =~ s/\.xsl// unless defined $title;
441
442
            # Get output format
443
            # There should only be one xsl:output node, so taking the first one only is OK
444
            $node = @{$node->findnodes("xsl:output")}[0];
445
            my $outputformat= "";
446
            $outputformat = $node->{"method"} if $node;
447
            $outputformat = "txt" if ($outputformat eq "" || $outputformat eq "text");
448
449
            my %row = (
450
                value       => $text,
451
                filename    => $title,
452
                format      => $outputformat,
453
            );
454
455
            push @tabFiles, \%row;
456
        }
457
    }
458
    return \@tabFiles;
459
}
412
1;
460
1;
413
461
414
__END__
462
__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( buildKohaItemsNamespace ));
15
    use_ok('C4::XSLT', qw( 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 'buildKohaItemsNamespace status tests' => sub {
32
subtest 'buildKohaItemsNamespace status tests' => sub {
40
    plan tests => 17;
33
    plan tests => 17;
41
- 

Return to bug 17385