Bug 20912: (QA follow-up) Rebase error corrections
[koha.git] / t / db_dependent / Circulation / Returns.t
index e97ebe3..88182cd 100644 (file)
@@ -24,10 +24,10 @@ use Test::Warn;
 use t::lib::Mocks;
 use t::lib::TestBuilder;
 
-use C4::Biblio;
+use C4::Members;
 use C4::Circulation;
 use C4::Items;
-use C4::Members;
+use C4::Biblio;
 use Koha::Database;
 use Koha::Account::Lines;
 use Koha::DateUtils;
@@ -41,7 +41,7 @@ use MARC::Field;
 my $branch;
 my $context = Test::MockModule->new('C4::Context');
 $context->mock( 'userenv', sub {
-    return { branch => $branch }
+    return { branch => $branch, number => 1234, firstname => "Adam", surname => "Smaith" }
 });
 
 my $schema = Koha::Database->schema;
@@ -54,7 +54,6 @@ my $rule = Koha::IssuingRule->new(
         categorycode => '*',
         itemtype     => '*',
         branchcode   => '*',
-        maxissueqty  => 99,
         issuelength  => 1,
     }
 );
@@ -87,17 +86,16 @@ subtest "InProcessingToShelvingCart tests" => sub {
 
     t::lib::Mocks::mock_preference( "InProcessingToShelvingCart", 1 );
     AddReturn( $barcode, $branch );
-    $item = GetItem( $itemnumber );
-    is( $item->{location}, 'CART',
+    $item = Koha::Items->find( $itemnumber );
+    is( $item->location, 'CART',
         "InProcessingToShelvingCart functions as intended" );
 
-    $item->{location} = $location;
-    ModItem( $item, undef, $itemnumber );
+    ModItem( {location => $location}, undef, $itemnumber );
 
     t::lib::Mocks::mock_preference( "InProcessingToShelvingCart", 0 );
     AddReturn( $barcode, $branch );
-    $item = GetItem( $itemnumber );
-    is( $item->{location}, $permanent_location,
+    $item = Koha::Items->find( $itemnumber );
+    is( $item->location, $permanent_location,
         "InProcessingToShelvingCart functions as intended" );
 };
 
@@ -177,6 +175,10 @@ subtest "AddReturn logging on statistics table (item-level_itypes=1)" => sub {
         "item-level itype recorded on statistics for return");
     warning_like { AddIssue( $borrower, $item_without_itemtype->{ barcode } ) }
                  [qr/^item-level_itypes set but no itemtype set for item/,
+                 qr/^item-level_itypes set but no itemtype set for item/,
+                 qr/^item-level_itypes set but no itemtype set for item/,
+                 qr/^item-level_itypes set but no itemtype set for item/,
+                 qr/^item-level_itypes set but no itemtype set for item/,
                  qr/^item-level_itypes set but no itemtype set for item/],
                  'Item without itemtype set raises warning on AddIssue';
     warning_like { AddReturn( $item_without_itemtype->{ barcode }, $branch ) }
@@ -279,7 +281,7 @@ subtest "AddReturn logging on statistics table (item-level_itypes=0)" => sub {
 };
 
 subtest 'Handle ids duplication' => sub {
-    plan tests => 6;
+    plan tests => 8;
 
     t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
     t::lib::Mocks::mock_preference( 'CalculateFinesOnReturn', 1 );
@@ -304,8 +306,12 @@ subtest 'Handle ids duplication' => sub {
     $patron = Koha::Patrons->find( $patron->{borrowernumber} );
 
     my $original_checkout = AddIssue( $patron->unblessed, $item->{barcode}, dt_from_string->subtract( days => 50 ) );
-
     my $issue_id = $original_checkout->issue_id;
+    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
+    is( $account_lines->count, 1, '1 account line should exist for this issue_id' );
+    is( $account_lines->next->description, 'Rental', 'patron has been charged the rentalcharge' );
+    $account_lines->delete;
+
     # Create an existing entry in old_issue
     $builder->build({ source => 'OldIssue', value => { issue_id => $issue_id } });
 
@@ -326,14 +332,14 @@ subtest 'Handle ids duplication' => sub {
     is( $messages->{WasReturned}, 0, 'messages should have the WasReturned flag set to 0' );
     is( $messages->{DataCorrupted}, 1, 'messages should have the DataCorrupted flag set to 1' );
 
-    my $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
+    $account_lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber, issue_id => $issue_id });
     is( $account_lines->count, 0, 'No account lines should exist for this issue_id, patron should not have been charged' );
 
     is( Koha::Checkouts->find( $issue_id )->issue_id, $issue_id, 'The issues entry should not have been removed' );
 };
 
 subtest 'BlockReturnOfLostItems' => sub {
-    plan tests => 3;
+    plan tests => 4;
     my $biblio = $builder->build_object( { class => 'Koha::Biblios' } );
     my $item = $builder->build_object(
         {
@@ -357,6 +363,9 @@ subtest 'BlockReturnOfLostItems' => sub {
     is( $doreturn, 0, "With BlockReturnOfLostItems, a checkin of a lost item should be blocked");
     is( $messages->{WasLost}, 1, "... and the WasLost flag should be set");
 
+    $item->discard_changes;
+    is( $item->itemlost, 1, "Item remains lost" );
+
     t::lib::Mocks::mock_preference('BlockReturnOfLostItems', 0);
     ( $doreturn, $messages, $issue ) = AddReturn($item->barcode);
     is( $doreturn, 1, "Without BlockReturnOfLostItems, a checkin of a lost item should not be blocked");