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

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