Bug 27837: Unit tests for blank permanent location
authorNick Clemens <nick@bywatersolutions.com>
Mon, 3 May 2021 14:44:49 +0000 (14:44 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 19 May 2021 13:06:39 +0000 (15:06 +0200)
Bug 27837: (QA follow-up) Minor Spelling/Typo correction

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Items.t

index ef4de8f..23ee75f 100755 (executable)
@@ -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 empty 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;