From cd9f17b8d4653375725b5972c025737ff55803c5 Mon Sep 17 00:00:00 2001 From: Alexis Ripetti Date: Tue, 3 Nov 2020 16:48:54 -0500 Subject: [PATCH] Bug 17385: Add tests for CustomXSLTExportList Tests are now in one patch. One test does not pass and I am not able to fix it. The test who fails :
$ prove -l t/db_dependent/XSLT.t
t/db_dependent/XSLT.t .. 1/3
    #   Failed test 'This list comes from the cache and that is fine'
    #   at t/db_dependent/XSLT.t line 122.
    #          got: '1'
    #     expected: '2'
    # Looks like you failed 1 test of 1.

 #   Failed test 'CustomXSLTExportList: Caching'
 #   at t/db_dependent/XSLT.t line 124.
 # Looks like you failed 1 test of 3.
t/db_dependent/XSLT.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/3 subtests

Test Summary Report
-------------------
t/db_dependent/XSLT.t (Wstat: 256 Tests: 3 Failed: 1)
  Failed test:  2
  Non-zero exit status: 1
Files=1, Tests=3,  3 wallclock secs ( 0.03 usr  0.00 sys +  1.74 cusr  0.14 csys =  1.91 CPU)
Result: FAIL
This one works fine :
$ prove -l t/XSLT.t
t/XSLT.t .. ok
All tests successful.
Files=1, Tests=12,  4 wallclock secs ( 0.02 usr  0.00 sys +  2.55 cusr  0.17 csys =  2.74 CPU)
Result: PASS
--- t/XSLT.t | 39 +++++++++++++++++++++++++++++++++++---- t/db_dependent/XSLT.t | 19 +++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/t/XSLT.t b/t/XSLT.t index e20a7b80e1..d80397e6ed 100755 --- a/t/XSLT.t +++ b/t/XSLT.t @@ -21,13 +21,13 @@ use Test::More; use File::Temp; use File::Path qw/make_path/; -use t::lib::Mocks; +use t::lib::Mocks qw( mock_preference ); use Module::Load::Conditional qw/check_install/; BEGIN { if ( check_install( module => 'Test::DBIx::Class' ) ) { - plan tests => 9; + plan tests => 12; } else { plan skip_all => "Need Test::DBIx::Class" } @@ -73,6 +73,37 @@ is(find_and_slurp($dir, 'test', 'fr-FR'), 'Theme test, language en', 'Fell ba is(find_and_slurp($dir, 'nope', 'es-ES'), 'Theme prog, language es-ES', 'Fell back to prog/es-ES for nope/es-ES'); is(find_and_slurp($dir, 'nope', 'fr-FR'), 'Theme prog, language en', 'Fell back to prog/en for nope/fr-FR'); -my $matching_string = q{0}; +my $matching_string = q{[0|1]}; my $sysprefs_xml = C4::XSLT::get_xslt_sysprefs(); -ok( $sysprefs_xml =~ m/$matching_string/, 'singleBranchMode has a value of 0'); \ No newline at end of file +ok( $sysprefs_xml =~ m/$matching_string/, 'singleBranchMode has no value'); + +t::lib::Mocks::mock_config('opachtdocs', "$dir"); +make_path("$dir/bootstrap/en/xslt/biblioexport"); + +# Make XSL with title +open my $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_01.xsl"; +print $fh qq| + +|; +close $fh; + +# Make XSL without title +open $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_02.xsl"; +print $fh qq| + +|; +close $fh; + +open $fh, '>', "$dir/bootstrap/en/xslt/biblioexport/export_03.xsl"; +print $fh qq||; +close $fh; + +my @custom_xslts = @{C4::XSLT::CustomXSLTExportList(1)}; +ok((scalar @custom_xslts) == 2, "CustomXSLTExportList finds custom XSLTs"); +ok($custom_xslts[0]->{filename} eq "Export 01", "Title is specified in root node"); +ok($custom_xslts[1]->{filename} eq "export_02", "Title is filename if not specified"); diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index ed9f39adf9..3d0dfa4c66 100755 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -1,3 +1,20 @@ +#!/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; @@ -16,6 +33,8 @@ BEGIN { } our $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; +our $cache = Koha::Caches->get_instance; # Here we go $schema->storage->txn_begin; -- 2.25.1