Lines 25-30
use t::lib::TestBuilder;
Link Here
|
25 |
|
25 |
|
26 |
use C4::Circulation; |
26 |
use C4::Circulation; |
27 |
use C4::Context; |
27 |
use C4::Context; |
|
|
28 |
use C4::Members; |
28 |
use Koha::Database; |
29 |
use Koha::Database; |
29 |
|
30 |
|
30 |
my $schema = Koha::Database->schema; |
31 |
my $schema = Koha::Database->schema; |
Lines 32-39
$schema->storage->txn_begin;
Link Here
|
32 |
|
33 |
|
33 |
my $builder = t::lib::TestBuilder->new; |
34 |
my $builder = t::lib::TestBuilder->new; |
34 |
|
35 |
|
35 |
t::lib::Mocks::mock_preference('AnonymousPatron', ''); |
|
|
36 |
|
37 |
my $library = $builder->build({ source => 'Branch' }); |
36 |
my $library = $builder->build({ source => 'Branch' }); |
38 |
|
37 |
|
39 |
C4::Context->_new_userenv('xxx'); |
38 |
C4::Context->_new_userenv('xxx'); |
Lines 56-73
my $item = $builder->build(
Link Here
|
56 |
} |
55 |
} |
57 |
} |
56 |
} |
58 |
); |
57 |
); |
59 |
my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode} ); |
|
|
60 |
|
61 |
eval { C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, 'dropbox_branch', 'returndate', 2 ) }; |
62 |
like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, 'Fatal error on anonymization' ); |
63 |
|
58 |
|
|
|
59 |
subtest 'anonymous patron' => sub { |
60 |
plan tests => 2; |
61 |
# The next call will raise an error, because data are not correctly set |
62 |
t::lib::Mocks::mock_preference('AnonymousPatron', ''); |
63 |
my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode} ); |
64 |
eval { C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, 'dropbox_branch', 'returndate', 2 ) }; |
65 |
like ( $@, qr<Fatal error: the patron \(\d+\) .* AnonymousPatron>, 'AnonymousPatron is not set - Fatal error on anonymization' ); |
66 |
Koha::Checkouts->find( $issue->issue_id )->delete; |
67 |
|
68 |
my $anonymous_borrowernumber = C4::Members::AddMember( categorycode => $patron_category->{categorycode}, branchcode => $library->{branchcode} ); |
69 |
t::lib::Mocks::mock_preference('AnonymousPatron', $anonymous_borrowernumber); |
70 |
$issue = C4::Circulation::AddIssue( $patron, $item->{barcode} ); |
71 |
eval { C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, 'dropbox_branch', 'returndate', 2 ) }; |
72 |
is ( $@, q||, 'AnonymousPatron is set correctly - no error expected'); |
73 |
}; |
74 |
|
75 |
my ( $issue_id, $issue ); |
64 |
# The next call will return undef for invalid item number |
76 |
# The next call will return undef for invalid item number |
65 |
my $issue_id; |
|
|
66 |
eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, 'invalid_itemnumber', 'dropbox_branch', 'returndate', 0 ) }; |
77 |
eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, 'invalid_itemnumber', 'dropbox_branch', 'returndate', 0 ) }; |
67 |
is( $@, '', 'No die triggered by invalid itemnumber' ); |
78 |
is( $@, '', 'No die triggered by invalid itemnumber' ); |
68 |
is( $issue_id, undef, 'No issue_id returned' ); |
79 |
is( $issue_id, undef, 'No issue_id returned' ); |
69 |
|
80 |
|
70 |
# In the next call we return the item and try it another time |
81 |
# In the next call we return the item and try it another time |
|
|
82 |
$issue = C4::Circulation::AddIssue( $patron, $item->{barcode} ); |
71 |
eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, undef, undef, 0 ) }; |
83 |
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)" ); |
84 |
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 ) }; |
85 |
eval { $issue_id = C4::Circulation::MarkIssueReturned( $patron->{borrowernumber}, $item->{itemnumber}, undef, undef, 0 ) }; |
74 |
- |
|
|