|
Lines 30-36
use Koha::Database;
Link Here
|
| 30 |
|
30 |
|
| 31 |
use t::lib::TestBuilder; |
31 |
use t::lib::TestBuilder; |
| 32 |
|
32 |
|
| 33 |
use Test::More tests => 84; |
33 |
use Test::More tests => 85; |
| 34 |
|
34 |
|
| 35 |
BEGIN { |
35 |
BEGIN { |
| 36 |
use_ok('C4::Circulation'); |
36 |
use_ok('C4::Circulation'); |
|
Lines 908-911
C4::Context->dbh->do("DELETE FROM accountlines");
Link Here
|
| 908 |
is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine'); |
908 |
is( Koha::Account::Lines->search({ issue_id => $issue->id })->count, 1, 'UpdateFine should not create a new accountline when updating an existing fine'); |
| 909 |
} |
909 |
} |
| 910 |
|
910 |
|
|
|
911 |
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub { |
| 912 |
plan tests => 23; |
| 913 |
|
| 914 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
| 915 |
my $holdingbranch = $builder->build( { source => 'Branch' } ); |
| 916 |
my $otherbranch = $builder->build( { source => 'Branch' } ); |
| 917 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
| 918 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
| 919 |
|
| 920 |
my $biblioitem = $builder->build( { source => 'Biblioitem' } ); |
| 921 |
my $item = $builder->build( |
| 922 |
{ source => 'Item', |
| 923 |
value => { |
| 924 |
homebranch => $homebranch->{branchcode}, |
| 925 |
holdingbranch => $holdingbranch->{branchcode}, |
| 926 |
notforloan => 0, |
| 927 |
itemlost => 0, |
| 928 |
withdrawn => 0, |
| 929 |
biblionumber => $biblioitem->{biblionumber} |
| 930 |
} |
| 931 |
} |
| 932 |
); |
| 933 |
|
| 934 |
set_userenv($holdingbranch); |
| 935 |
|
| 936 |
my $issue = AddIssue( $patron_1, $item->{barcode} ); |
| 937 |
is( ref($issue), 'Koha::Schema::Result::Issue' ); # FIXME Should be Koha::Issue |
| 938 |
|
| 939 |
my ( $error, $question, $alerts ); |
| 940 |
|
| 941 |
# AllowReturnToBranch == anywhere |
| 942 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 943 |
## Can be issued from homebranch |
| 944 |
set_userenv($homebranch); |
| 945 |
( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} ); |
| 946 |
is( keys(%$error) + keys(%$alerts), 0 ); |
| 947 |
is( exists $question->{ISSUED_TO_ANOTHER}, 1 ); |
| 948 |
## Can be issued from holdingbranch |
| 949 |
set_userenv($holdingbranch); |
| 950 |
( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} ); |
| 951 |
is( keys(%$error) + keys(%$alerts), 0 ); |
| 952 |
is( exists $question->{ISSUED_TO_ANOTHER}, 1 ); |
| 953 |
## Can be issued from another branch |
| 954 |
( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} ); |
| 955 |
is( keys(%$error) + keys(%$alerts), 0 ); |
| 956 |
is( exists $question->{ISSUED_TO_ANOTHER}, 1 ); |
| 957 |
|
| 958 |
# AllowReturnToBranch == holdingbranch |
| 959 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 960 |
## Cannot be issued from homebranch |
| 961 |
set_userenv($homebranch); |
| 962 |
( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} ); |
| 963 |
is( keys(%$question) + keys(%$alerts), 0 ); |
| 964 |
is( exists $error->{RETURN_IMPOSSIBLE}, 1 ); |
| 965 |
is( $error->{branch_to_return}, $holdingbranch->{branchcode} ); |
| 966 |
## Can be issued from holdinbranch |
| 967 |
set_userenv($holdingbranch); |
| 968 |
( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} ); |
| 969 |
is( keys(%$error) + keys(%$alerts), 0 ); |
| 970 |
is( exists $question->{ISSUED_TO_ANOTHER}, 1 ); |
| 971 |
## Cannot be issued from another branch |
| 972 |
set_userenv($otherbranch); |
| 973 |
( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} ); |
| 974 |
is( keys(%$question) + keys(%$alerts), 0 ); |
| 975 |
is( exists $error->{RETURN_IMPOSSIBLE}, 1 ); |
| 976 |
is( $error->{branch_to_return}, $holdingbranch->{branchcode} ); |
| 977 |
|
| 978 |
# AllowReturnToBranch == homebranch |
| 979 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 980 |
## Can be issued from holdinbranch |
| 981 |
set_userenv($homebranch); |
| 982 |
( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} ); |
| 983 |
is( keys(%$error) + keys(%$alerts), 0 ); |
| 984 |
is( exists $question->{ISSUED_TO_ANOTHER}, 1 ); |
| 985 |
## Cannot be issued from holdinbranch |
| 986 |
set_userenv($holdingbranch); |
| 987 |
( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} ); |
| 988 |
is( keys(%$question) + keys(%$alerts), 0 ); |
| 989 |
is( exists $error->{RETURN_IMPOSSIBLE}, 1 ); |
| 990 |
is( $error->{branch_to_return}, $homebranch->{branchcode} ); |
| 991 |
## Cannot be issued from holdinbranch |
| 992 |
set_userenv($otherbranch); |
| 993 |
( $error, $question, $alerts ) = CanBookBeIssued( $patron_2, $item->{barcode} ); |
| 994 |
is( keys(%$question) + keys(%$alerts), 0 ); |
| 995 |
is( exists $error->{RETURN_IMPOSSIBLE}, 1 ); |
| 996 |
is( $error->{branch_to_return}, $homebranch->{branchcode} ); |
| 997 |
|
| 998 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
| 999 |
}; |
| 1000 |
|
| 1001 |
sub set_userenv { |
| 1002 |
my ( $library ) = @_; |
| 1003 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
| 1004 |
} |
| 1005 |
|
| 911 |
1; |
1006 |
1; |
| 912 |
- |
|
|