Bug 27589: Unit test
[srvgit] / t / db_dependent / ILSDI_Services.t
index adc1ade..3818762 100755 (executable)
@@ -300,7 +300,7 @@ subtest 'LookupPatron test' => sub {
 
 subtest 'Holds test' => sub {
 
-    plan tests => 7;
+    plan tests => 8;
 
     $schema->storage->txn_begin;
 
@@ -412,21 +412,55 @@ subtest 'Holds test' => sub {
     $reply = C4::ILSDI::Services::HoldItem( $query );
     is( $reply->{code}, 'damaged', "Item is damaged" );
 
-    my $module = new Test::MockModule('C4::Context');
+    my $module = Test::MockModule->new('C4::Context');
     $module->mock('userenv', sub { { patron => $patron } });
     my $issue = C4::Circulation::AddIssue($patron, $item3->barcode);
     t::lib::Mocks::mock_preference( 'AllowHoldsOnPatronsPossessions', '0' );
 
-    $query = new CGI;
+    $query = CGI->new;
     $query->param( 'patron_id', $patron->{borrowernumber});
     $query->param( 'bib_id', $item3->biblionumber);
     $query->param( 'item_id', $item3->itemnumber);
     $query->param( 'pickup_location', $origin_branch->{branchcode});
     $reply = C4::ILSDI::Services::HoldItem( $query );
 
-    is( $reply->{code}, 'itemAlreadyOnLoan', "Patron has issued same book" );
+    is( $reply->{code}, 'alreadypossession', "Patron has issued same book" );
     is( $reply->{pickup_location}, undef, "No reserve placed");
 
+    # Test Patron cannot reserve if expired and BlockExpiredPatronOpacActions
+    my $category = $builder->build({
+        source => 'Category',
+        value => { BlockExpiredPatronOpacActions => -1 }
+        });
+
+    my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode };
+
+    my $expired_borrowernumber = Koha::Patron->new({
+        firstname =>  'Expired',
+        surname => 'Patron',
+        categorycode => $category->{categorycode},
+        branchcode => $branch_1,
+        dateexpiry => '2000-01-01',
+    })->store->borrowernumber;
+
+    t::lib::Mocks::mock_preference('BlockExpiredPatronOpacActions', 1);
+
+    my $item5 = $builder->build({
+        source => 'Item',
+        value => {
+            biblionumber => $biblio_with_no_item->biblionumber,
+            damaged => 0,
+        }
+    });
+
+    $query = CGI->new;
+    $query->param( 'patron_id', $expired_borrowernumber);
+    $query->param( 'bib_id', $biblio_with_no_item->biblionumber);
+    $query->param( 'item_id', $item5->{itemnumber});
+
+    $reply = C4::ILSDI::Services::HoldItem( $query );
+    is( $reply->{code}, 'PatronExpired', "Patron is expired" );
+
     $schema->storage->txn_rollback;
 };
 
@@ -572,7 +606,7 @@ subtest 'Holds test with start_date and end_date' => sub {
 
 subtest 'GetRecords' => sub {
 
-    plan tests => 1;
+    plan tests => 8;
 
     $schema->storage->txn_begin;
 
@@ -591,6 +625,24 @@ subtest 'GetRecords' => sub {
         }
     );
 
+    my $patron = $builder->build({
+        source => 'Borrower',
+    });
+
+    my $issue = $builder->build({
+        source => 'Issue',
+        value => {
+            itemnumber => $item->itemnumber,
+        }
+    });
+
+    my $hold = $builder->build({
+        source => 'Reserve',
+        value => {
+            biblionumber => $item->biblionumber,
+        }
+    });
+
     ModItemTransfer($item->itemnumber, $branch1->{branchcode}, $branch2->{branchcode});
 
     my $cgi = CGI->new;
@@ -608,6 +660,17 @@ subtest 'GetRecords' => sub {
     is_deeply($reply->{record}->[0]->{items}->{item}->[0]->{transfer}, $expected,
         'GetRecords returns transfer informations');
 
+    # Check informations exposed
+    my $reply_issue = $reply->{record}->[0]->{issues}->{issue}->[0];
+    is($reply_issue->{itemnumber}, $item->itemnumber, 'GetRecords has an issue tag');
+    is($reply_issue->{borrowernumber}, undef, 'GetRecords does not expose borrowernumber in issue tag');
+    is($reply_issue->{surname}, undef, 'GetRecords does not expose surname in issue tag');
+    is($reply_issue->{firstname}, undef, 'GetRecords does not expose firstname in issue tag');
+    is($reply_issue->{cardnumber}, undef, 'GetRecords does not expose cardnumber in issue tag');
+    my $reply_reserve = $reply->{record}->[0]->{reserves}->{reserve}->[0];
+    is($reply_reserve->{biblionumber}, $item->biblionumber, 'GetRecords has a reserve tag');
+    is($reply_reserve->{borrowernumber}, undef, 'GetRecords does not expose borrowernumber in reserve tag');
+
     $schema->storage->txn_rollback;
 };