From b417dbb85685fcde653a47229e0ab05532d94b81 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 22 Mar 2019 08:03:16 +0000 Subject: [PATCH] Bug 17385: (QA follow-up) Do not needlessly scan biblioexport folder Performance: We need to return an empty list if OpacExportOptions does not contain Custom. No need to scan the directory for custom files, if we are not using them at all. Note: The test only pertains to OPAC now, since the pref should not control intranet behavior. We have no intranet counterpart. See further next follow-up. Test plan: Run t/db_dependent/XSLT.t Signed-off-by: Marcel de Rooy --- C4/XSLT.pm | 2 + t/db_dependent/XSLT.t | 116 +++++------------------------------------- 2 files changed, 15 insertions(+), 103 deletions(-) diff --git a/C4/XSLT.pm b/C4/XSLT.pm index 330d21a304..faba7cc25c 100644 --- a/C4/XSLT.pm +++ b/C4/XSLT.pm @@ -402,6 +402,8 @@ sub engine { 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') . diff --git a/t/db_dependent/XSLT.t b/t/db_dependent/XSLT.t index cfec5e9f55..5f91cdb44b 100644 --- a/t/db_dependent/XSLT.t +++ b/t/db_dependent/XSLT.t @@ -1,113 +1,23 @@ -#!/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 Test::More tests => 1; -use Test::More tests => 2; -use Test::Warn; -use t::lib::TestBuilder; use t::lib::Mocks; +use C4::XSLT; +use Koha::Database; -use Koha::ItemTypes; - -BEGIN { - use_ok('C4::XSLT'); -} - -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'); -subtest 'buildKohaItemsNamespace status tests' => sub { - plan tests => 12; - my $item = $builder->build_sample_item({}); - - my $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{available},"Item is available when no other status applied"); - - # notforloan - { - - t::lib::Mocks::mock_preference('item-level_itypes', 0); - $item->notforloan(0)->store; - Koha::ItemTypes->find($item->itype)->notforloan(0)->store; - Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(1)->store; - $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{reference},"reference if positive itype notforloan value"); - - t::lib::Mocks::mock_preference('item-level_itypes', 1); - Koha::ItemTypes->find($item->itype)->notforloan(1)->store; - Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(0)->store; - $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{reference},"reference if positive itemtype notforloan value"); - Koha::ItemTypes->find($item->itype)->notforloan(0)->store; - - $item->notforloan(-1)->store; - $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{On order},"On order if negative notforloan value"); - - $item->notforloan(1)->store; - $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{reference},"reference if positive notforloan value"); - } - - $item->onloan('2001-01-01')->store; - $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{Checked out},"Checked out status takes precedence over Not for loan"); - - $item->withdrawn(1)->store; - $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{Withdrawn},"Withdrawn status takes precedence over Checked out"); - - $item->itemlost(1)->store; - $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{Lost},"Lost status takes precedence over Withdrawn"); - - $item->damaged(1)->store; - $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{Damaged},"Damaged status takes precedence over Lost"); - - $builder->build({ source => "Branchtransfer", value => { - itemnumber => $item->itemnumber, - datearrived => undef, - } - }); - $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{In transit},"In-transit status takes precedence over Damaged"); - - my $hold = $builder->build_object({ class => 'Koha::Holds', value => { - biblionumber => $item->biblionumber, - itemnumber => $item->itemnumber, - found => 'W', - priority => 0, - } - }); - $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{Waiting},"Waiting status takes precedence over In transit"); - - $builder->build({ source => "TmpHoldsqueue", value => { - itemnumber => $item->itemnumber - } - }); - $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]); - like($xml,qr{Pending hold},"Pending status takes precedence over all"); - + 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' ); }; - $schema->storage->txn_rollback; -- 2.17.1