View | Details | Raw Unified | Return to bug 22049
Collapse All | Expand All

(-)a/t/db_dependent/Circulation/MarkIssueReturned.t (-11 / +26 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 6;
20
use Test::More tests => 7;
21
use Test::Exception;
21
use Test::Warn;
22
use Test::Warn;
22
23
23
use t::lib::Mocks;
24
use t::lib::Mocks;
Lines 27-53 use C4::Circulation; Link Here
27
use C4::Context;
28
use C4::Context;
28
use Koha::Checkouts;
29
use Koha::Checkouts;
29
use Koha::Database;
30
use Koha::Database;
31
use Koha::Old::Checkouts;
30
use Koha::Patrons;
32
use Koha::Patrons;
31
33
32
my $schema = Koha::Database->schema;
34
my $schema = Koha::Database->schema;
33
$schema->storage->txn_begin;
34
35
my $builder = t::lib::TestBuilder->new;
35
my $builder = t::lib::TestBuilder->new;
36
36
37
my $library = $builder->build({ source => 'Branch' });
37
$schema->storage->txn_begin;
38
39
my $library = $builder->build_object({ class => 'Koha::Libraries' });
38
40
39
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
41
t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode });
40
42
41
my $patron_category = $builder->build({ source => 'Category', value => { category_type => 'P', enrolmentfee => 0 } });
43
my $category = $builder->build({ source => 'Category', value => { category_type => 'P', enrolmentfee => 0 } });
42
my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
44
my $patron   = $builder->build({ source => 'Borrower', value => { branchcode => $library->branchcode, categorycode => $category->{categorycode} } } );
43
45
44
my $biblioitem = $builder->build( { source => 'Biblioitem' } );
46
my $biblioitem = $builder->build( { source => 'Biblioitem' } );
45
my $item = $builder->build(
47
my $item = $builder->build(
46
    {
48
    {
47
        source => 'Item',
49
        source => 'Item',
48
        value  => {
50
        value  => {
49
            homebranch    => $library->{branchcode},
51
            homebranch    => $library->branchcode,
50
            holdingbranch => $library->{branchcode},
52
            holdingbranch => $library->branchcode,
51
            notforloan    => 0,
53
            notforloan    => 0,
52
            itemlost      => 0,
54
            itemlost      => 0,
53
            withdrawn     => 0,
55
            withdrawn     => 0,
Lines 65-77 subtest 'anonymous patron' => sub { Link Here
65
    like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, 'AnonymousPatron is not set - Fatal error on anonymization' );
67
    like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, 'AnonymousPatron is not set - Fatal error on anonymization' );
66
    Koha::Checkouts->find( $issue->issue_id )->delete;
68
    Koha::Checkouts->find( $issue->issue_id )->delete;
67
69
68
    my $anonymous_borrowernumber = Koha::Patron->new({categorycode => $patron_category->{categorycode}, branchcode => $library->{branchcode} })->store->borrowernumber;
70
    my $anonymous_borrowernumber = Koha::Patron->new({categorycode => $category->{categorycode}, branchcode => $library->branchcode })->store->borrowernumber;
69
    t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_borrowernumber);
71
    t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_borrowernumber);
70
    $issue = C4::Circulation::AddIssue( $patron, $item->{barcode} );
72
    $issue = C4::Circulation::AddIssue( $patron, $item->{barcode} );
71
    eval { C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, undef, 2 ) };
73
    eval { C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, undef, 2 ) };
72
    is ( $@, q||, 'AnonymousPatron is set correctly - no error expected');
74
    is ( $@, q||, 'AnonymousPatron is set correctly - no error expected');
73
};
75
};
74
76
77
subtest 'Manually pass a return date' => sub {
78
79
    plan tests => 2;
80
81
    my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode} );
82
    my $issue_id;
83
84
    eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, '2018-12-25', 0 ) };
85
    is( $issue_id, $issue->issue_id, "Item has been returned" );
86
    my $old_checkout = Koha::Old::Checkouts->find( $issue_id );
87
    is( $old_checkout->returndate, '2018-12-25 00:00:00', 'Manually passed date stored correctly' );
88
89
};
90
75
my ( $issue_id, $issue );
91
my ( $issue_id, $issue );
76
# The next call will return undef for invalid item number
92
# The next call will return undef for invalid item number
77
eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, 'invalid_itemnumber', undef, 0 ) };
93
eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, 'invalid_itemnumber', undef, 0 ) };
78
- 

Return to bug 22049