From b7cbe055a38ad9c923a9c4c9839bb47e1e8434f2 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
Signed-off-by: David Nind --- t/db_dependent/XSLT.t | 54 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index 5f79b35b13..ddeda737be 100755 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -20,10 +20,10 @@ use Modern::Perl; use File::Temp; use File::Path qw/make_path/; use MARC::Record; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Warn; use t::lib::TestBuilder; -use t::lib::Mocks; +use t::lib::Mocks qw( mock_preference ); use Koha::Database; use Koha::Libraries; @@ -35,9 +35,10 @@ BEGIN { my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; +our $cache = Koha::Caches->get_instance; subtest 'Tests moved from t' => sub { - plan tests => 8; + plan tests => 11; $schema->storage->txn_begin; my $dir = File::Temp->newdir(); @@ -74,9 +75,41 @@ subtest 'Tests moved from t' => sub { 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'); + 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; + + t::lib::Mocks::mock_preference( 'OpacExportOptions', 'custom'); + 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"); $schema->storage->txn_rollback; }; @@ -201,6 +234,17 @@ subtest 'buildKohaItemsNamespace status tests' => sub { $schema->storage->txn_rollback; }; +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' ); + $cache->clear_from_cache('CustomXSLTExportListOPAC'); + t::lib::Mocks::mock_preference('OpacExportOptions', 'dc'); + $list = C4::XSLT::CustomXSLTExportList(1); + is( @$list, 0, 'We expect an empty list now' ); +}; + subtest 'buildKohaItemsNamespace() including/omitting items tests' => sub { plan tests => 23; -- 2.34.1