Browse Source

Bug 24052: Rename XSLT_Handler

Should be XSLT::Base now.
Removes old XSLT_Handler stub too (from bug 23290).
Result of a git grep | sed statement.

Test plan:
Run qa tools (so modules compile).
Run t/db_dependent/Breeding.t
Run t/db_dependent/Koha/XSLT/Base.t (This test fails when only this patch
has been applied; see subsequent patch.)
Enable XSLT use on results and details display. Check search results and
detail view on OPAC and staff.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
20.05.x
Marcel de Rooy 1 year ago
committed by Martin Renvoize
parent
commit
2bf171acaf
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 4
      C4/Breeding.pm
  2. 4
      C4/Record.pm
  3. 4
      C4/XSLT.pm
  4. 2
      Koha/OAI/Server/Record.pm
  5. 4
      Koha/OAI/Server/Repository.pm
  6. 12
      Koha/XSLT_Handler.pm
  7. 4
      opac/unapi
  8. 6
      t/db_dependent/Breeding.t
  9. 22
      t/db_dependent/Koha/XSLT/Base.t

4
C4/Breeding.pm

@ -30,7 +30,7 @@ use C4::ImportBatch;
use C4::AuthoritiesMarc; #GuessAuthTypeCode, FindDuplicateAuthority
use C4::Languages;
use Koha::Database;
use Koha::XSLT_Handler;
use Koha::XSLT::Base;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@ -163,7 +163,7 @@ sub Z3950Search {
_translate_query( $server, $squery )));
$s++;
}
my $xslh = Koha::XSLT_Handler->new;
my $xslh = Koha::XSLT::Base->new;
my $nremaining = $s;
while ( $nremaining-- ) {

4
C4/Record.pm

@ -34,7 +34,7 @@ use Template;
use Text::CSV::Encoded; #marc2csv
use Koha::Items;
use Koha::SimpleMARC qw(read_field);
use Koha::XSLT_Handler;
use Koha::XSLT::Base;
use Koha::CsvProfiles;
use Koha::AuthorisedValues;
use Carp;
@ -291,7 +291,7 @@ sub marc2dcxml {
carp "\t". $warn;
};
} elsif ( $record =~ /^MARC::Record/ ) { # if OK makes xslt transformation
my $xslt_engine = Koha::XSLT_Handler->new;
my $xslt_engine = Koha::XSLT::Base->new;
if ( $format =~ /^(dc|oaidc|srwdc|rdfdc)$/i ) {
$output = $xslt_engine->transform( $marcxml, $xsl );
} else {

4
C4/XSLT.pm

@ -31,7 +31,7 @@ use C4::Circulation;
use C4::Reserves;
use Koha::AuthorisedValues;
use Koha::ItemTypes;
use Koha::XSLT_Handler;
use Koha::XSLT::Base;
use Koha::Libraries;
use Encode;
@ -49,7 +49,7 @@ BEGIN {
@EXPORT = qw(
&XSLTParse4Display
);
$engine=Koha::XSLT_Handler->new( { do_not_return_source => 1 } );
$engine=Koha::XSLT::Base->new( { do_not_return_source => 1 } );
}
=head1 NAME

2
Koha/OAI/Server/Record.pm

@ -47,7 +47,7 @@ sub new {
my $args = {
OPACBaseURL => "'" . C4::Context->preference('OPACBaseURL') . "'"
};
# call Koha::XSLT_Handler now
# call Koha::XSLT::Base now
$record_dom = $repository->{xslt_engine}->transform({
xml => $marcxml,
file => $repository->stylesheet($format),

4
Koha/OAI/Server/Repository.pm

@ -36,7 +36,7 @@ use YAML::Syck qw( LoadFile );
use CGI qw/:standard -oldstyle_urls/;
use C4::Context;
use C4::Biblio;
use Koha::XSLT_Handler;
use Koha::XSLT::Base;
=head1 NAME
@ -104,7 +104,7 @@ sub new {
$self->{ koha_identifier } = C4::Context->preference("OAI-PMH:archiveID");
$self->{ koha_max_count } = C4::Context->preference("OAI-PMH:MaxCount");
$self->{ koha_metadata_format } = ['oai_dc', 'marc21', 'marcxml'];
$self->{ xslt_engine } = Koha::XSLT_Handler->new;
$self->{ xslt_engine } = Koha::XSLT::Base->new;
# Load configuration file if defined in OAI-PMH:ConfFile syspref
if ( my $file = C4::Context->preference("OAI-PMH:ConfFile") ) {

12
Koha/XSLT_Handler.pm

@ -1,12 +0,0 @@
package Koha::XSLT_Handler;
# This is just a stub; will be removed later on
use Modern::Perl;
use base qw(Koha::XSLT::Base);
use constant XSLTH_ERR_1 => 'XSLTH_ERR_NO_FILE';
use constant XSLTH_ERR_2 => 'XSLTH_ERR_FILE_NOT_FOUND';
use constant XSLTH_ERR_3 => 'XSLTH_ERR_LOADING';
use constant XSLTH_ERR_4 => 'XSLTH_ERR_PARSING_CODE';
use constant XSLTH_ERR_5 => 'XSLTH_ERR_PARSING_DATA';
use constant XSLTH_ERR_6 => 'XSLTH_ERR_TRANSFORMING';
use constant XSLTH_ERR_7 => 'XSLTH_NO_STRING_PASSED';
1;

4
opac/unapi

@ -39,7 +39,7 @@ an XML format such as OAI DC, RSS2, MARCXML, or MODS.
use CGI qw ( -utf8 );
use C4::Context;
use C4::Biblio;
use Koha::XSLT_Handler;
use Koha::XSLT::Base;
my $cgi = CGI->new();
binmode(STDOUT, ":encoding(UTF-8)"); #output as utf8
@ -141,7 +141,7 @@ if (not defined $format) {
print $cgi->header( -status => '406 invalid format requested' );
exit 0;
}
my $xslt_engine = Koha::XSLT_Handler->new;
my $xslt_engine = Koha::XSLT::Base->new;
$content = $xslt_engine->transform({
xml => $marcxml,
file => $xslt_file,

6
t/db_dependent/Breeding.t

@ -34,7 +34,7 @@ use t::lib::Mocks qw( mock_preference );
use C4::Context;
use C4::Breeding;
use Koha::Database;
use Koha::XSLT_Handler;
use Koha::XSLT::Base;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
@ -208,7 +208,7 @@ sub test_do_xslt {
);
my $file= $FindBin::Bin.'/XSLT_Handler/test01.xsl';
my $server= { add_xslt => $file };
my $engine=Koha::XSLT_Handler->new;
my $engine=Koha::XSLT::Base->new;
#ready for the main test
my @res = C4::Breeding::_do_xslt_proc( $biblio, $server, $engine );
@ -219,7 +219,7 @@ sub test_do_xslt {
#forcing an error on the xslt side
$server->{add_xslt} = 'notafile.xsl';
@res = C4::Breeding::_do_xslt_proc( $biblio, $server, $engine );
is( $res[1], Koha::XSLT_Handler::XSLTH_ERR_2, 'Error code found' );
is( $res[1], Koha::XSLT::Base::XSLTH_ERR_2, 'Error code found' );
#We still expect the original record back
is( ref $res[0], 'MARC::Record', 'Still got back MARC record' );
is ( $res[0]->subfield('245','a'), 'Just a title',

22
t/db_dependent/XSLT_Handler.t → t/db_dependent/Koha/XSLT/Base.t

@ -24,16 +24,16 @@ use File::Slurp;
use Test::More tests => 35;
use Test::Warn;
use Koha::XSLT_Handler;
use Koha::XSLT::Base;
my $engine=Koha::XSLT_Handler->new;
is( ref $engine, 'Koha::XSLT_Handler', 'Testing creation of handler object' );
my $engine=Koha::XSLT::Base->new;
is( ref $engine, 'Koha::XSLT::Base', 'Testing creation of handler object' );
$engine->transform('');
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_1, 'Engine returns error on no file' );
is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_1, 'Engine returns error on no file' );
$engine->transform( '', 'thisfileshouldnotexist.%$#@' );
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_2, 'Engine returns error on bad file' );
is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_2, 'Engine returns error on bad file' );
is( $engine->refresh( 'asdjhaskjh'), 0, 'Test on invalid refresh' );
#check first test xsl
@ -48,28 +48,28 @@ my $output;
# Undefined text tests
$output = $engine->transform( undef, $xsltfile_1 );
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_7, 'Engine returns error on undefined text' );
is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_7, 'Engine returns error on undefined text' );
# Empty string tests
$output = $engine->transform( '', $xsltfile_1 );
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_5, 'Engine returns error on empty string' );
is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_5, 'Engine returns error on empty string' );
# Non-XML tests
$engine->print_warns(1);
warning_like { $output = $engine->transform( 'abcdef', $xsltfile_1 ) }
qr{parser error : Start tag expected, '<' not found},
"Non-XML warning correctly displayed";
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_5, 'Engine returns error on non-xml' );
is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_5, 'Engine returns error on non-xml' );
# Malformed XML tests
warning_like { $output = $engine->transform( '<a></b>', $xsltfile_1 ) }
qr{parser error : Opening and ending tag mismatch: a line 1 and b},
"Malformed XML warning correctly displayed";
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_5, 'Engine returns error on malformed xml' );
is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_5, 'Engine returns error on malformed xml' );
#Test not returning source on failure when asked for
#Include passing do_not_return via constructor on second engine
my $secondengine=Koha::XSLT_Handler->new( {
my $secondengine=Koha::XSLT::Base->new( {
do_not_return_source => 'very_true',
some_unknown_attrib => 'just_for_fun',
});
@ -142,7 +142,7 @@ $xsltfile_2= $path.$xsltfile_2;
$engine->print_warns(0);
$output = $engine->transform( $xml_2, $xsltfile_2 );
is( $engine->err, Koha::XSLT_Handler::XSLTH_ERR_4, 'Engine returned error for parsing bad xsl' );
is( $engine->err, Koha::XSLT::Base::XSLTH_ERR_4, 'Engine returned error for parsing bad xsl' );
#The third test xsl is okay again; main use is clearing two items from cache
my $xsltfile_3 = 'test03.xsl';
Loading…
Cancel
Save