From a86f485ed1a1b7baa184d78ccc16a16bbc0f6bf9 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 3 May 2021 14:44:49 +0000 Subject: [PATCH] Bug 27837: Unit tests for blank permanent location --- t/db_dependent/Items.t | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index ef4de8f20b..ff611b4d0e 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -1038,7 +1038,7 @@ subtest 'ModItemFromMarc' => sub { }; subtest 'permanent_location' => sub { - plan tests => 6; + plan tests => 10; # Make sure items.permanent_location is not mapped Koha::MarcSubfieldStructures->search( @@ -1047,6 +1047,13 @@ subtest 'ModItemFromMarc' => sub { kohafield => 'items.permanent_location', } )->delete; + Koha::MarcSubfieldStructures->search( + { + frameworkcode => q{}, + tagfield => '952', + tagsubfield => 'C', + } + )->delete; Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); my $item = $builder->build_sample_item; @@ -1072,7 +1079,9 @@ subtest 'ModItemFromMarc' => sub { tagfield => '952', tagsubfield => 'C', kohafield => 'items.permanent_location', - repeatable => 0 + repeatable => 0, + tab => 10, + hidden => 0, } )->store; Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); @@ -1085,6 +1094,34 @@ subtest 'ModItemFromMarc' => sub { $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' ); + + $item->permanent_location(undef)->more_subfields_xml(undef)->store; + # Clear values from the DB + $item = $item->get_from_storage; + + # Update the location + $item->location('D'); + $marc = C4::Items::Item2Marc( $item->unblessed, $item->biblionumber ); + # Remove the permanent_location field from the form + $marc->field('952')->delete_subfield("C"); + ModItemFromMarc( $marc, $item->biblionumber, $item->itemnumber ); + $item = $item->get_from_storage; + is( $item->location, 'D', 'next new location set as expected' ); + is( $item->permanent_location, 'D', 'permanent location is updated if not previously set and no value passed' ); + + # Clear values from the DB + $item->permanent_location(undef)->more_subfields_xml(undef)->store; + $item = $item->get_from_storage; + + # This time nothing is set, but we pass an emty string + $item->permanent_location(""); + $item->location('E'); + $marc = C4::Items::Item2Marc( $item->unblessed, $item->biblionumber ); + ModItemFromMarc( $marc, $item->biblionumber, $item->itemnumber ); + $item = $item->get_from_storage; + is( $item->location, 'E', 'next new location set as expected' ); + is( $item->permanent_location, undef, 'permanent location is not updated if previously set as blank string' ); + }; $schema->storage->txn_rollback; -- 2.11.0