From cca4df22da2d373e8f734c805c3139c20a70d986 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Wed, 3 Jan 2024 00:25:02 +0000 Subject: [PATCH] Bug 34234: add a unit test --- Koha/Template/Plugin/ItemGroups.pm | 6 +- .../prog/en/modules/cataloguing/additem.tt | 4 +- t/db_dependent/Template/Plugin/ItemGroups.t | 64 +++++++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) create mode 100755 t/db_dependent/Template/Plugin/ItemGroups.t diff --git a/Koha/Template/Plugin/ItemGroups.pm b/Koha/Template/Plugin/ItemGroups.pm index 47844478d6..efd1d9b386 100644 --- a/Koha/Template/Plugin/ItemGroups.pm +++ b/Koha/Template/Plugin/ItemGroups.pm @@ -50,15 +50,15 @@ sub listGroups { ); } -=head3 count +=head3 getCount -[% ItemGroups.count %] +[% ItemGroups.getCount %] returns count of item groups on a particular bibliographic record =cut -sub count { +sub getCount { my ( $self, $biblionumber ) = @_; return Koha::Biblio::ItemGroups->search( { biblio_id => $biblionumber }, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt index 8014325538..14fa4187ef 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt @@ -37,7 +37,7 @@ [% INCLUDE 'str/cataloging_additem.inc' %] [% Asset.js("js/cataloging_additem.js") | $raw %] @@ -250,7 +250,7 @@ [% IF op != 'add_item' %] [% END %] -[% IF ItemGroups.count(biblio.biblionumber) && op != 'saveitem' && CAN_user_editcatalogue_manage_item_groups %] +[% IF ItemGroups.getCount(biblio.biblionumber) && op != 'saveitem' && CAN_user_editcatalogue_manage_item_groups %]
Add to item group [% FOREACH ig IN ItemGroups.listGroups(biblio.biblionumber) %] diff --git a/t/db_dependent/Template/Plugin/ItemGroups.t b/t/db_dependent/Template/Plugin/ItemGroups.t new file mode 100755 index 0000000000..858b894ccf --- /dev/null +++ b/t/db_dependent/Template/Plugin/ItemGroups.t @@ -0,0 +1,64 @@ +#!/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::TestBuilder; +use t::lib::Mocks; +use Koha::Biblio::ItemGroups; +use Koha::Template::Plugin::ItemGroups; + +my $schema = Koha::Database->schema; +my $builder = t::lib::TestBuilder->new; + +$schema->storage->txn_begin; + +ok( my $settings = Koha::Template::Plugin::ItemGroups->new(), 'Able to instantiate template plugin' ); + +subtest 'Item_Groups' => sub { + plan tests => 5; + + my $biblio = $builder->build_sample_biblio(); + my $item_group_count = Koha::Template::Plugin::ItemGroups->getCount( $biblio->id ); + + is( $item_group_count, 0, '0 items correctly counted in the item group' ); + + #Add some item groups to the bib + my $item_group_1 = + Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id, display_order => 2, description => "Vol 2" } ) + ->store(); + my $item_group_2 = + Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id, display_order => 3, description => "Vol 3" } ) + ->store(); + my $item_group_3 = + Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id, display_order => 1, description => "Vol 1" } ) + ->store(); + + $item_group_count = Koha::Template::Plugin::ItemGroups->getCount( $biblio->id ); + is( $item_group_count, 3, '3 items correctly counted in the item group' ); + + my $group_1 = Koha::Biblio::ItemGroups->find( $item_group_1->item_group_id ); + is( $group_1->display_order, 2, "Item group 1 should display 2nd" ); + my $group_2 = Koha::Biblio::ItemGroups->find( $item_group_2->item_group_id ); + is( $group_2->display_order, 3, "Item group 2 should display 3rd" ); + my $group_3 = Koha::Biblio::ItemGroups->find( $item_group_3->item_group_id ); + is( $group_3->display_order, 1, "Item group 3 should display 1st" ); + +}; + +$schema->storage->txn_rollback; -- 2.30.2