Bug 24545: Fix license statements
[srvgit] / t / db_dependent / Items.t
index 0130824..369935e 100755 (executable)
@@ -2,19 +2,18 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
 use Data::Dumper;
@@ -313,18 +312,16 @@ subtest 'GetItemsInfo tests' => sub {
     is( $results[0]->{ restrictedvalueopac }, "Restricted Access OPAC",
         'GetItemsInfo returns a restricted value description (OPAC)' );
 
-    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckout', 0 );
     #place item into holds queue
     my $dbh = C4::Context->dbh;
+    @results = GetItemsInfo( $biblio->biblionumber );
+    is( $results[0]->{ has_pending_hold }, "0",
+        'Hold not marked as pending/unavailable if nothing in tmp_holdsqueue for item' );
+
     $dbh->do(q{INSERT INTO tmp_holdsqueue (biblionumber, itemnumber, surname, borrowernumber ) VALUES (?, ?, "Zorro", 42)}, undef, $item_bibnum, $itemnumber);
     @results = GetItemsInfo( $biblio->biblionumber );
     is( $results[0]->{ has_pending_hold }, "1",
-        'Hold marked as pending/unavailable if not AllowItemsOnHoldCheckout' );
-    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckout', 1 );
-    @results = GetItemsInfo( $biblio->biblionumber );
-    is( $results[0]->{ has_pending_hold }, undef,
-        'Hold not marked as pending/unavailable if AllowItemsOnHoldCheckout' );
-
+        'Hold marked as pending/unavailable if tmp_holdsqueue is not empty for item' );
 
     $schema->storage->txn_rollback;
 };
@@ -370,7 +367,7 @@ subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
 };
 
 subtest 'SearchItems test' => sub {
-    plan tests => 14;
+    plan tests => 15;
 
     $schema->storage->txn_begin;
     my $dbh = C4::Context->dbh;
@@ -404,6 +401,7 @@ subtest 'SearchItems test' => sub {
         homebranch => $library2->{branchcode},
         holdingbranch => $library2->{branchcode},
         itype => $itemtype->{itemtype},
+        issues => 3,
     }, $biblio->biblionumber);
 
     my ($items, $total_results);
@@ -545,6 +543,25 @@ subtest 'SearchItems test' => sub {
     my $cpl_items_after = SearchItemsByField( 'homebranch', $library1->{branchcode});
     is( ( scalar( @$cpl_items_after ) - scalar ( @$cpl_items_before ) ), 1, 'SearchItemsByField should return something' );
 
+    # Issues count may be NULL
+    $filter = {
+        conjunction => 'AND',
+        filters => [
+            {
+                field => 'issues',
+                query => 0,
+                operator => '=',
+            },
+            {
+                field => 'homebranch',
+                query => $library1->{branchcode},
+                operator => '=',
+            },
+        ],
+    };
+    ($items, $total_results) = SearchItems($filter);
+    is($total_results, 1, "Search items.issues is NULL with filter issues = 0");
+
     $schema->storage->txn_rollback;
 };
 
@@ -567,7 +584,7 @@ subtest 'Koha::Item(s) tests' => sub {
 
     # Create a biblio and item for testing
     t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
-    my $biblio = $builder->build_sample_biblio();
+    my $biblio = $builder->build_sample_biblio({title => 'Silence in the library'});
     my ( $item_bibnum, $item_bibitemnum, $itemnumber ) = AddItem(
         {
             homebranch    => $library1->{branchcode},
@@ -589,7 +606,7 @@ subtest 'Koha::Item(s) tests' => sub {
     is( ref($holdingbranch), 'Koha::Library', "Got Koha::Library from holding_branch method" );
     is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
 
-    my $biblio = $item->biblio();
+    $biblio = $item->biblio();
     is( ref($biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
     is( $biblio->title(), 'Silence in the library', 'Title matches biblio title' );