From 21814a6c9c650e979d0d29783b224c4670e91e7c Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 20 Jan 2023 17:12:21 +0100 Subject: [PATCH] Bug 11844: Take into account itemtypes, branches, and cn_source MARC subfields can be linked to "authorised values" that are not real authorised values: itemtypes, branches, and cn_source. Those were not taken into account. This patch fixes that Test plan: 1. Create additional fields for order lines with a MARC subfield that is linked to one of those "fake" authorised values list 2. Follow the same steps as in the main test plan Signed-off-by: Katrin Fischer Signed-off-by: Michaela Sieber Signed-off-by: Martin Renvoize --- Koha/Template/Plugin/ClassSources.pm | 41 +++++++++ .../en/includes/additional-fields-entry.inc | 39 ++++++-- .../Koha/Template/Plugin/ClassSources.t | 90 +++++++++++++++++++ 3 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 Koha/Template/Plugin/ClassSources.pm create mode 100755 t/db_dependent/Koha/Template/Plugin/ClassSources.t diff --git a/Koha/Template/Plugin/ClassSources.pm b/Koha/Template/Plugin/ClassSources.pm new file mode 100644 index 0000000000..7b424f4905 --- /dev/null +++ b/Koha/Template/Plugin/ClassSources.pm @@ -0,0 +1,41 @@ +package Koha::Template::Plugin::ClassSources; + +# 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 base qw( Template::Plugin ); + +use C4::Context; +use Koha::ClassSources; + +sub all { + my ($self, $params) = @_; + + my $selected = $params->{selected}; + + my $default_source = C4::Context->preference("DefaultClassificationSource"); + + my @class_sources = grep { + $_->used + or ( $selected and $_->cn_source eq $selected ) + or ( $default_source and $_->cn_source eq $default_source ) + } Koha::ClassSources->search->as_list; + + return @class_sources; +} + +1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc index 17c7a6f9a2..b16f537090 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc @@ -1,4 +1,7 @@ [% USE AuthorisedValues %] +[% USE Branches %] +[% USE ClassSources %] +[% USE ItemTypes %] [% IF wrap_fieldset != 0 %]
Additional fields @@ -15,11 +18,37 @@ (Authorised values for [% authorised_value_category | html %]) diff --git a/t/db_dependent/Koha/Template/Plugin/ClassSources.t b/t/db_dependent/Koha/Template/Plugin/ClassSources.t new file mode 100755 index 0000000000..d897838b7d --- /dev/null +++ b/t/db_dependent/Koha/Template/Plugin/ClassSources.t @@ -0,0 +1,90 @@ +#!/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 => 2; + +use t::lib::Mocks; + +BEGIN { + use_ok('Koha::Template::Plugin::ClassSources'); +} + +my $schema = Koha::Database->schema; + +subtest 'all' => sub { + plan tests => 4; + + $schema->storage->txn_begin; + $schema->resultset('ClassSource')->delete(); + $schema->resultset('ClassSource')->create({ + cn_source => 'anscr', + description => 'ANSCR (Sound Recordings)', + used => 0, + class_sort_rule => 'generic', + class_split_rule => 'generic', + }); + $schema->resultset('ClassSource')->create({ + cn_source => 'ddc', + description => 'Dewey Decimal Classification', + used => 1, + class_sort_rule => 'dewey', + class_split_rule => 'dewey', + }); + $schema->resultset('ClassSource')->create({ + cn_source => 'z', + description => 'Other/Generic Classification Scheme', + used => 0, + class_sort_rule => 'generic', + class_split_rule => 'generic', + }); + + t::lib::Mocks::mock_preference('DefaultClassificationSource', ''); + + my $plugin = Koha::Template::Plugin::ClassSources->new(); + subtest 'when given no parameters' => sub { + plan tests => 2; + my @class_sources = $plugin->all(); + + is(scalar @class_sources, 1, 'it returns only "used" class sources'); + is($class_sources[0]->used, 1, 'it returns only "used" class sources'); + }; + + subtest 'when given parameter "selected"' => sub { + plan tests => 1; + my @class_sources = $plugin->all({ selected => 'anscr' }); + + ok(scalar @class_sources == 2, 'it returns "used" class sources and the selected one'); + }; + + subtest 'when DefaultClassificationSource is set to a not used class source' => sub { + plan tests => 1; + t::lib::Mocks::mock_preference('DefaultClassificationSource', 'anscr'); + my @class_sources = $plugin->all(); + + ok(scalar @class_sources == 2, 'it returns "used" class sources and the default one'); + }; + + subtest 'when DefaultClassificationSource is set and "selected" parameter is given' => sub { + plan tests => 1; + t::lib::Mocks::mock_preference('DefaultClassificationSource', 'anscr'); + my @class_sources = $plugin->all({ selected => 'z' }); + ok(scalar @class_sources == 3, 'it returns "used" class sources, the default one and the selected one'); + }; + + $schema->storage->txn_rollback; +}; -- 2.30.2