@@ -, +, @@ folder --- C4/XSLT.pm | 48 +++++++++++++++++++++++++++++++++++++++++++ t/db_dependent/XSLT.t | 31 +++++++++++----------------- 2 files changed, 60 insertions(+), 19 deletions(-) --- a/C4/XSLT.pm +++ a/C4/XSLT.pm @@ -475,6 +475,54 @@ sub engine { return $engine; } +=head2 CustomXSLTExportList + + Returns list of file for custom xslt conversion + +=cut + +sub CustomXSLTExportList { + my $opac = shift; # opac (1) vs intranet (0) + return [] if $opac && C4::Context->preference('OpacExportOptions') !~ /custom/; + + my @tabFiles; + + my $dir = C4::Context->config( $opac ? 'opachtdocs' : 'intrahtdocs') . + '/' . C4::Context->preference( $opac ? "opacthemes" : "template") . + '/' . C4::Languages::getlanguage() . + '/xslt/biblioexport'; + my @files = glob qq("$dir/*.xsl"); + foreach my $file (@files) { + if ( -f "$file" ) { + (my $text = $file) =~ s/.*\///g; + + ## Get title of the option + my $dom; + eval { $dom = XML::LibXML->load_xml( location => $file ); }; + next unless $dom; + + my $node = $dom->documentElement(); + my $title = $node->{"title"}; + ($title = $text) =~ s/\.xsl// unless defined $title; + + # Get output format + # There should only be one xsl:output node, so taking the first one only is OK + $node = @{$node->findnodes("xsl:output")}[0]; + my $outputformat= ""; + $outputformat = $node->{"method"} if $node; + $outputformat = "txt" if ($outputformat eq "" || $outputformat eq "text"); + + my %row = ( + value => $text, + filename => $title, + format => $outputformat, + ); + + push @tabFiles, \%row; + } + } + return \@tabFiles; +} 1; __END__ --- a/t/db_dependent/XSLT.t +++ a/t/db_dependent/XSLT.t @@ -1,20 +1,3 @@ -#!/usr/bin/perl - -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - use Modern::Perl; use MARC::Record; @@ -26,15 +9,25 @@ use t::lib::Mocks; use Koha::Database; use Koha::Libraries; use Koha::ItemTypes; +use C4::XSLT; BEGIN { use_ok('C4::XSLT', qw( transformMARCXML4XSLT getAuthorisedValues4MARCSubfields buildKohaItemsNamespace )); } -my $schema = Koha::Database->new->schema; -my $builder = t::lib::TestBuilder->new; +our $schema = Koha::Database->new->schema; +# Here we go $schema->storage->txn_begin; +subtest 'CustomXSLTExportList: Check export options' => sub { + plan tests => 2; + t::lib::Mocks::mock_preference('OpacExportOptions', 'custom'); + my $list = C4::XSLT::CustomXSLTExportList(1); + is( @$list>0, 1, 'We expect at least one result: simple export' ); + t::lib::Mocks::mock_preference('OpacExportOptions', 'dc'); + $list = C4::XSLT::CustomXSLTExportList(1); + is( @$list, 0, 'We expect an empty list now' ); +}; subtest 'transformMARCXML4XSLT tests' => sub { plan tests => 1; --