Bug 29826: Manage call of Template Plugin Branches GetName() with null or empty branc...
[srvgit] / t / db_dependent / Template / Plugin / Branches.t
index 4c149df..a1145d6 100755 (executable)
@@ -38,7 +38,7 @@ my $builder = t::lib::TestBuilder->new;
 
 subtest 'all() tests' => sub {
 
-    plan tests => 18;
+    plan tests => 19;
 
     $schema->storage->txn_begin;
 
@@ -68,6 +68,9 @@ subtest 'all() tests' => sub {
     $name = $plugin->GetName(undef);
     is($name, '', 'received empty string as name of NULL/undefined library code');
 
+    $name = $plugin->GetName(q{});
+    is($name, '', 'received empty string as name of empty string library code');
+
     is($plugin->GetLoggedInBranchcode(), '', 'no active library code if there is no active user session');
     is($plugin->GetLoggedInBranchname(), '', 'no active library name if there is no active user session');
 
@@ -112,7 +115,7 @@ subtest 'all() tests' => sub {
 
 subtest 'pickup_locations() tests' => sub {
 
-    plan tests => 8;
+    plan tests => 9;
 
     $schema->storage->txn_begin;
 
@@ -155,7 +158,8 @@ subtest 'pickup_locations() tests' => sub {
     $biblio_class->mock(
         'pickup_locations',
         sub {
-            return [$library_2];
+            return Koha::Libraries->search(
+                { branchcode => $library_2->branchcode } );
         }
     );
 
@@ -167,6 +171,27 @@ subtest 'pickup_locations() tests' => sub {
     is( scalar @{$pickup_locations}, 1, 'Only the library returned by $biblio->pickup_locations is returned' );
     is( $pickup_locations->[0]->{branchcode}, $library_2->branchcode, 'Not cheating' );
 
+    subtest 'Koha::Item->pickup_locations and Koha::Biblio->pickup_locations empty tests' => sub {
+
+        plan tests => 2;
+
+        my $biblio_class = Test::MockModule->new('Koha::Biblio');
+        $biblio_class->mock( 'pickup_locations', sub { return Koha::Libraries->new->empty } );
+
+        my $biblio = $builder->build_sample_biblio;
+
+        my @pickup_locations = @{$plugin->pickup_locations({ search_params => { biblio => $biblio->id } })};
+        is( scalar @pickup_locations, 0, 'No pickup locations returned' );
+
+        my $item_class = Test::MockModule->new('Koha::Item');
+        $item_class->mock( 'pickup_locations', sub { return Koha::Libraries->new->empty } );
+
+        my $item = $builder->build_sample_item;
+
+        @pickup_locations = @{$plugin->pickup_locations({ search_params => { item => $item->id } })};
+        is( scalar @pickup_locations, 0, 'No pickup locations returned' );
+    };
+
     subtest 'selected tests' => sub {
 
         plan tests => 4;