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

(-)a/t/db_dependent/Circulation/MarkIssueReturned.t (-24 / +19 lines)
Lines 17-35 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 2;
20
use Test::More tests => 6;
21
use Test::Warn;
21
use Test::Warn;
22
22
23
use t::lib::Mocks;
23
use t::lib::Mocks;
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
25
26
use C4::Circulation;
26
use C4::Circulation;
27
use C4::Members;
27
use C4::Context;
28
use Koha::Library;
28
use Koha::Database;
29
29
30
my $schema = Koha::Database->schema;
30
my $schema = Koha::Database->schema;
31
my $dbh = C4::Context->dbh;
32
33
$schema->storage->txn_begin;
31
$schema->storage->txn_begin;
34
32
35
my $builder = t::lib::TestBuilder->new;
33
my $builder = t::lib::TestBuilder->new;
Lines 37-55 my $builder = t::lib::TestBuilder->new; Link Here
37
t::lib::Mocks::mock_preference('AnonymousPatron', '');
35
t::lib::Mocks::mock_preference('AnonymousPatron', '');
38
36
39
my $library = $builder->build({ source => 'Branch' });
37
my $library = $builder->build({ source => 'Branch' });
40
my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
41
38
42
C4::Context->_new_userenv('xxx');
39
C4::Context->_new_userenv('xxx');
43
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');
40
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', '');
44
41
45
my %item_branch_infos = (
46
    homebranch => $library->{branchcode},
47
    holdingbranch => $library->{branchcode},
48
);
49
50
my $borrowernumber = AddMember( categorycode => $categorycode, branchcode => $library->{branchcode} );
51
my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
42
my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
52
    my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
43
my $patron = $builder->build({ source => 'Borrower', value => { branchcode => $library->{branchcode}, categorycode => $patron_category->{categorycode} } } );
53
44
54
my $biblioitem = $builder->build( { source => 'Biblioitem' } );
45
my $biblioitem = $builder->build( { source => 'Biblioitem' } );
55
my $item = $builder->build(
46
my $item = $builder->build(
Lines 65-81 my $item = $builder->build( Link Here
65
        }
56
        }
66
    }
57
    }
67
);
58
);
68
C4::Circulation::AddIssue( $patron, $item->{barcode} );
59
my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode} );
69
60
70
eval { C4::Circulation::MarkIssueReturned( $borrowernumber, $item->{itemnumber}, 'dropbox_branch', 'returndate', 2 ) };
61
eval { C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, 'dropbox_branch', 'returndate', 2 ) };
71
like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, );
62
like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, 'Fatal error on anonymization' );
72
63
73
my $anonymous_borrowernumber = AddMember( categorycode => $categorycode, branchcode => $library->{branchcode} );
64
# The next call will return undef for invalid item number
74
t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_borrowernumber);
65
my $issue_id;
75
# The next call will raise an error, because data are not correctly set
66
eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, 'invalid_itemnumber', 'dropbox_branch', 'returndate', 0 ) };
76
$dbh->{PrintError} = 0;
67
is( $@, '', 'No die triggered by invalid itemnumber' );
77
eval { C4::Circulation::MarkIssueReturned( $borrowernumber, 'itemnumber', 'dropbox_branch', 'returndate', 2 ) };
68
is( $issue_id, undef, 'No issue_id returned' );
78
unlike ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, );
79
69
80
$schema->storage->txn_rollback;
70
# In the next call we return the item and try it another time
71
eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, undef, undef, 0 ) };
72
is( $issue_id, $issue->issue_id, "Item has been returned (issue $issue_id)" );
73
eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, undef, undef, 0 ) };
74
is( $@, '', 'No crash on returning item twice' );
75
is( $issue_id, undef, 'Cannot return an item twice' );
81
76
82
- 
77
$schema->storage->txn_rollback;

Return to bug 19487