Browse Source

Bug 14591: Update unit tests

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Kyle Hall 5 years ago
committed by root
parent
commit
004609e468
  1. 43
      t/db_dependent/Circulation.t
  2. 10
      t/db_dependent/Circulation/StoreLastBorrower.t
  3. 10
      t/db_dependent/Koha/Patrons.t

43
t/db_dependent/Circulation.t

@ -1652,8 +1652,7 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
; # Add another overdue ; # Add another overdue
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' ); t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' );
AddReturn( $item_1->{barcode}, $library->{branchcode}, AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, dt_from_string );
undef, undef, dt_from_string );
my $debarments = Koha::Patron::Debarments::GetDebarments( my $debarments = Koha::Patron::Debarments::GetDebarments(
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
is( scalar(@$debarments), 1 ); is( scalar(@$debarments), 1 );
@ -1669,8 +1668,7 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
); );
is( $debarments->[0]->{expiration}, $expected_expiration ); is( $debarments->[0]->{expiration}, $expected_expiration );
AddReturn( $item_2->{barcode}, $library->{branchcode}, AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, dt_from_string );
undef, undef, dt_from_string );
$debarments = Koha::Patron::Debarments::GetDebarments( $debarments = Koha::Patron::Debarments::GetDebarments(
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
is( scalar(@$debarments), 1 ); is( scalar(@$debarments), 1 );
@ -1690,8 +1688,7 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue AddIssue( $patron, $item_1->{barcode}, $five_days_ago ); # Add an overdue
AddIssue( $patron, $item_2->{barcode}, $ten_days_ago ) AddIssue( $patron, $item_2->{barcode}, $ten_days_ago )
; # Add another overdue ; # Add another overdue
AddReturn( $item_1->{barcode}, $library->{branchcode}, AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, dt_from_string );
undef, undef, dt_from_string );
$debarments = Koha::Patron::Debarments::GetDebarments( $debarments = Koha::Patron::Debarments::GetDebarments(
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
is( scalar(@$debarments), 1 ); is( scalar(@$debarments), 1 );
@ -1704,8 +1701,7 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
); );
is( $debarments->[0]->{expiration}, $expected_expiration ); is( $debarments->[0]->{expiration}, $expected_expiration );
AddReturn( $item_2->{barcode}, $library->{branchcode}, AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, dt_from_string );
undef, undef, dt_from_string );
$debarments = Koha::Patron::Debarments::GetDebarments( $debarments = Koha::Patron::Debarments::GetDebarments(
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
is( scalar(@$debarments), 1 ); is( scalar(@$debarments), 1 );
@ -1934,25 +1930,25 @@ subtest 'AddReturn | is_overdue' => sub {
# specify return date 5 days before => no overdue # specify return date 5 days before => no overdue
AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
AddReturn( $item->{barcode}, $library->{branchcode}, undef, undef, $ten_days_ago ); AddReturn( $item->{barcode}, $library->{branchcode}, undef, $ten_days_ago );
is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' ); is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
# specify return date 5 days later => overdue # specify return date 5 days later => overdue
AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
AddReturn( $item->{barcode}, $library->{branchcode}, undef, undef, $five_days_ago ); AddReturn( $item->{barcode}, $library->{branchcode}, undef, $five_days_ago );
is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' ); is( int($patron->account->balance()), 5, 'AddReturn: pass return_date => overdue' );
Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
# specify dropbox date 5 days before => no overdue # specify dropbox date 5 days before => no overdue
AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago AddIssue( $patron->unblessed, $item->{barcode}, $five_days_ago ); # date due was 5d ago
AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $ten_days_ago ); AddReturn( $item->{barcode}, $library->{branchcode}, $ten_days_ago );
is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' ); is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' );
Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
# specify dropbox date 5 days later => overdue, or... not # specify dropbox date 5 days later => overdue, or... not
AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago AddIssue( $patron->unblessed, $item->{barcode}, $ten_days_ago ); # date due was 10d ago
AddReturn( $item->{barcode}, $library->{branchcode}, undef, 1, undef, $five_days_ago ); AddReturn( $item->{barcode}, $library->{branchcode}, $five_days_ago );
is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue in dropbox mode' ); # FIXME? This is weird, the FU fine is created ( _CalculateAndUpdateFine > C4::Overdues::UpdateFine ) then remove later (in _FixOverduesOnReturn). Looks like it is a feature is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue in dropbox mode' ); # FIXME? This is weird, the FU fine is created ( _CalculateAndUpdateFine > C4::Overdues::UpdateFine ) then remove later (in _FixOverduesOnReturn). Looks like it is a feature
Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete;
}; };
@ -2335,7 +2331,7 @@ subtest '_FixAccountForLostAndReturned' => sub {
}; };
subtest '_FixOverduesOnReturn' => sub { subtest '_FixOverduesOnReturn' => sub {
plan tests => 10; plan tests => 6;
my $biblio = $builder->build_sample_biblio({ author => 'Hall, Kylie' }); my $biblio = $builder->build_sample_biblio({ author => 'Hall, Kylie' });
@ -2389,24 +2385,6 @@ subtest '_FixOverduesOnReturn' => sub {
is( $accountline->accounttype, 'FFOR', 'Open fine ( account type FU ) has been set to fine forgiven ( account type FFOR )'); is( $accountline->accounttype, 'FFOR', 'Open fine ( account type FU ) has been set to fine forgiven ( account type FFOR )');
is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" ); is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" );
is( $offset->amount, '-99.000000', "Amount of offset is correct" ); is( $offset->amount, '-99.000000', "Amount of offset is correct" );
## Run again, with dropbox mode enabled
$accountline->set(
{
accounttype => 'FU',
amountoutstanding => 99.00,
}
)->store();
C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $item->itemnumber, 0, 1 );
$accountline->_result()->discard_changes();
$offset = Koha::Account::Offsets->search({ debit_id => $accountline->id, type => 'Dropbox' })->next();
is( $accountline->amountoutstanding + 0, 90, 'Fine has been reduced to 90' );
is( $accountline->accounttype, 'F', 'Open fine ( account type FU ) has been closed out ( account type F )');
is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via dropbox" );
is( $offset->amount, '-9.000000', "Amount of offset is correct" );
}; };
subtest 'Set waiting flag' => sub { subtest 'Set waiting flag' => sub {
@ -3007,8 +2985,7 @@ sub test_debarment_on_checkout {
my $line_number = $caller[2]; my $line_number = $caller[2];
AddIssue( $patron, $item->{barcode}, $due_date ); AddIssue( $patron, $item->{barcode}, $due_date );
my ( undef, $message ) = AddReturn( $item->{barcode}, $library->{branchcode}, my ( undef, $message ) = AddReturn( $item->{barcode}, $library->{branchcode}, undef, $return_date );
undef, undef, $return_date );
is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' ) is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' )
or diag('AddReturn returned message ' . Dumper $message ); or diag('AddReturn returned message ' . Dumper $message );
my $debarments = Koha::Patron::Debarments::GetDebarments( my $debarments = Koha::Patron::Debarments::GetDebarments(

10
t/db_dependent/Circulation/StoreLastBorrower.t

@ -19,10 +19,10 @@ use Modern::Perl;
use Test::More tests => 1; use Test::More tests => 1;
use C4::Context;
use C4::Circulation; use C4::Circulation;
use C4::Context;
use Koha::Database; use Koha::Database;
use Koha::DateUtils;
use Koha::Items; use Koha::Items;
use t::lib::Mocks; use t::lib::Mocks;
@ -69,7 +69,7 @@ subtest 'Test StoreLastBorrower' => sub {
my $patron_object = $item_object->last_returned_by(); my $patron_object = $item_object->last_returned_by();
is( $patron_object, undef, 'Koha::Item::last_returned_by returned undef' ); is( $patron_object, undef, 'Koha::Item::last_returned_by returned undef' );
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, undef, '2010-10-10' ); my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, dt_from_string('2010-10-10') );
$item_object = Koha::Items->find( $item->{itemnumber} ); $item_object = Koha::Items->find( $item->{itemnumber} );
$patron_object = $item_object->last_returned_by(); $patron_object = $item_object->last_returned_by();
@ -92,7 +92,7 @@ subtest 'Test StoreLastBorrower' => sub {
} }
); );
( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, undef, '2010-10-10' ); ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, dt_from_string('2010-10-10') );
$item_object = Koha::Items->find( $item->{itemnumber} ); $item_object = Koha::Items->find( $item->{itemnumber} );
$patron_object = $item_object->last_returned_by(); $patron_object = $item_object->last_returned_by();
@ -133,7 +133,7 @@ subtest 'Test StoreLastBorrower' => sub {
}, },
} }
); );
( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, undef, '2010-10-10' ); ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, $patron->{branchcode}, undef, dt_from_string('2010-10-10') );
$item_object = Koha::Items->find( $item->{itemnumber} ); $item_object = Koha::Items->find( $item->{itemnumber} );
is( $item_object->last_returned_by, undef, 'Last patron to return item should not be stored if StoreLastBorrower if off' ); is( $item_object->last_returned_by, undef, 'Last patron to return item should not be stored if StoreLastBorrower if off' );

10
t/db_dependent/Koha/Patrons.t

@ -868,8 +868,8 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
} }
); );
my ( $returned_1, undef, undef ) = C4::Circulation::AddReturn( $item_1->{barcode}, undef, undef, undef, '2010-10-10' ); my ( $returned_1, undef, undef ) = C4::Circulation::AddReturn( $item_1->{barcode}, undef, undef, dt_from_string('2010-10-10') );
my ( $returned_2, undef, undef ) = C4::Circulation::AddReturn( $item_2->{barcode}, undef, undef, undef, '2011-11-11' ); my ( $returned_2, undef, undef ) = C4::Circulation::AddReturn( $item_2->{barcode}, undef, undef, dt_from_string('2011-11-11') );
is( $returned_1 && $returned_2, 1, 'The items should have been returned' ); is( $returned_1 && $returned_2, 1, 'The items should have been returned' );
my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } ); my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } );
@ -932,7 +932,7 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
} }
); );
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, dt_from_string('2010-10-10') );
is( $returned, 1, 'The item should have been returned' ); is( $returned, 1, 'The item should have been returned' );
my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } ); my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } );
ok( $rows_affected > 0, 'AnonymiseIssueHistory should not return any error if success' ); ok( $rows_affected > 0, 'AnonymiseIssueHistory should not return any error if success' );
@ -973,7 +973,7 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
} }
); );
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, dt_from_string('2010-10-10') );
is( $returned, 1, 'The item should have been returned' ); is( $returned, 1, 'The item should have been returned' );
my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } ); my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } );
ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' );
@ -1011,7 +1011,7 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
} }
); );
my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, dt_from_string('2010-10-10') );
is( Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->count, 0 ); is( Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->count, 0 );
Koha::Patrons->find( $patron->{borrowernumber})->delete; Koha::Patrons->find( $patron->{borrowernumber})->delete;
}; };

Loading…
Cancel
Save