From 93087a6f01c2816ca0419cf466d7bb23442df0fa Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 3 Mar 2021 08:54:39 -0500 Subject: [PATCH] Bug 27837: Add unit tests Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Rhonda Kuiper Signed-off-by: Tomas Cohen Arazi Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize --- t/db_dependent/Items.t | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index a6a45bf925..4ab2e2dac6 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -981,7 +981,7 @@ subtest 'Split subfields in Item2Marc (Bug 21774)' => sub { }; subtest 'ModItemFromMarc' => sub { - plan tests => 5; + plan tests => 6; $schema->storage->txn_begin; my $builder = t::lib::TestBuilder->new; @@ -1037,5 +1037,46 @@ subtest 'ModItemFromMarc' => sub { is( $item->get_from_storage->cn_sort, 'YYY', 'cn_sort has been updated' ); }; + subtest 'permanent_location' => sub { + plan tests => 6; + + my $item = $builder->build_sample_item; + + # By default, setting location to something new should set permanent location to the same thing + # with the usual exceptions + $item->set({ location => 'A', permanent_location => 'A' })->store; + is( $item->location, 'A', 'initial location set as expected' ); + is( $item->permanent_location, 'A', 'initial permanent location set as expected' ); + + $item->location('B'); + my $marc = C4::Items::Item2Marc( $item->unblessed, $item->biblionumber ); + ModItemFromMarc( $marc, $item->biblionumber, $item->itemnumber ); + + $item = $item->get_from_storage; + is( $item->location, 'B', 'new location set as expected' ); + is( $item->permanent_location, 'B', 'new permanent location set as expected' ); + + # Added a marc mapping for permanent location, allows it to be edited independently + my $mapping = Koha::MarcSubfieldStructure->new( + { + frameworkcode => q{}, + tagfield => '952', + tagsubfield => 'C', + kohafield => 'items.permanent_location', + repeatable => 0 + } + )->store; + Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); + + # Now if we change location, and also pass in a permanent location + # the permanent_location will not be overwritten by location + $item->location('C'); + $marc = C4::Items::Item2Marc( $item->unblessed, $item->biblionumber ); + ModItemFromMarc( $marc, $item->biblionumber, $item->itemnumber ); + $item = $item->get_from_storage; + is( $item->location, 'C', 'next new location set as expected' ); + is( $item->permanent_location, 'B', 'permanent location remains unchanged as expected' ); + }; + $schema->storage->txn_rollback; }; -- 2.20.1