@@ -, +, @@ the top in Circulation.t --- t/db_dependent/Circulation.t | 96 ++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 49 deletions(-) --- a/t/db_dependent/Circulation.t +++ a/t/db_dependent/Circulation.t @@ -48,6 +48,53 @@ use Koha::Account::Lines; use Koha::Account::Offsets; use Koha::ActionLogs; +sub set_userenv { + my ( $library ) = @_; + t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} }); +} + +sub str { + my ( $error, $question, $alert ) = @_; + my $s; + $s = %$error ? ' (error: ' . join( ' ', keys %$error ) . ')' : ''; + $s .= %$question ? ' (question: ' . join( ' ', keys %$question ) . ')' : ''; + $s .= %$alert ? ' (alert: ' . join( ' ', keys %$alert ) . ')' : ''; + return $s; +} + +sub test_debarment_on_checkout { + my ($params) = @_; + my $item = $params->{item}; + my $library = $params->{library}; + my $patron = $params->{patron}; + my $due_date = $params->{due_date} || dt_from_string; + my $return_date = $params->{return_date} || dt_from_string; + my $expected_expiration_date = $params->{expiration_date}; + + $expected_expiration_date = output_pref( + { + dt => $expected_expiration_date, + dateformat => 'sql', + dateonly => 1, + } + ); + my @caller = caller; + my $line_number = $caller[2]; + AddIssue( $patron, $item->{barcode}, $due_date ); + + my ( undef, $message ) = AddReturn( $item->{barcode}, $library->{branchcode}, undef, $return_date ); + is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' ) + or diag('AddReturn returned message ' . Dumper $message ); + my $debarments = Koha::Patron::Debarments::GetDebarments( + { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); + is( scalar(@$debarments), 1, 'Test at line ' . $line_number ); + + is( $debarments->[0]->{expiration}, + $expected_expiration_date, 'Test at line ' . $line_number ); + Koha::Patron::Debarments::DelUniqueDebarment( + { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); +}; + my $schema = Koha::Database->schema; $schema->storage->txn_begin; my $builder = t::lib::TestBuilder->new; @@ -3112,55 +3159,6 @@ subtest 'ProcessOfflinePayment() tests' => sub { $schema->storage->txn_rollback; }; - - -sub set_userenv { - my ( $library ) = @_; - t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} }); -} - -sub str { - my ( $error, $question, $alert ) = @_; - my $s; - $s = %$error ? ' (error: ' . join( ' ', keys %$error ) . ')' : ''; - $s .= %$question ? ' (question: ' . join( ' ', keys %$question ) . ')' : ''; - $s .= %$alert ? ' (alert: ' . join( ' ', keys %$alert ) . ')' : ''; - return $s; -} - -sub test_debarment_on_checkout { - my ($params) = @_; - my $item = $params->{item}; - my $library = $params->{library}; - my $patron = $params->{patron}; - my $due_date = $params->{due_date} || dt_from_string; - my $return_date = $params->{return_date} || dt_from_string; - my $expected_expiration_date = $params->{expiration_date}; - - $expected_expiration_date = output_pref( - { - dt => $expected_expiration_date, - dateformat => 'sql', - dateonly => 1, - } - ); - my @caller = caller; - my $line_number = $caller[2]; - AddIssue( $patron, $item->{barcode}, $due_date ); - - my ( undef, $message ) = AddReturn( $item->{barcode}, $library->{branchcode}, undef, $return_date ); - is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' ) - or diag('AddReturn returned message ' . Dumper $message ); - my $debarments = Koha::Patron::Debarments::GetDebarments( - { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); - is( scalar(@$debarments), 1, 'Test at line ' . $line_number ); - - is( $debarments->[0]->{expiration}, - $expected_expiration_date, 'Test at line ' . $line_number ); - Koha::Patron::Debarments::DelUniqueDebarment( - { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); -}; - subtest 'Incremented fee tests' => sub { plan tests => 11; --