Bug 27837: Add unit tests
authorKyle M Hall <kyle@bywatersolutions.com>
Wed, 3 Mar 2021 13:54:39 +0000 (08:54 -0500)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 19 May 2021 12:52:19 +0000 (14:52 +0200)
Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Rhonda Kuiper <rkuiper@roundrocktexas.gov>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
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 a6a45bf..4ab2e2d 100755 (executable)
@@ -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;
 };