|
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 => 85; |
33 |
use Test::More tests => 86; |
| 34 |
|
34 |
|
| 35 |
BEGIN { |
35 |
BEGIN { |
| 36 |
use_ok('C4::Circulation'); |
36 |
use_ok('C4::Circulation'); |
|
Lines 998-1003
subtest 'CanBookBeIssued & AllowReturnToBranch' => sub {
Link Here
|
| 998 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
998 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
| 999 |
}; |
999 |
}; |
| 1000 |
|
1000 |
|
|
|
1001 |
subtest 'AddIssue & AllowReturnToBranch' => sub { |
| 1002 |
plan tests => 9; |
| 1003 |
|
| 1004 |
my $homebranch = $builder->build( { source => 'Branch' } ); |
| 1005 |
my $holdingbranch = $builder->build( { source => 'Branch' } ); |
| 1006 |
my $otherbranch = $builder->build( { source => 'Branch' } ); |
| 1007 |
my $patron_1 = $builder->build( { source => 'Borrower' } ); |
| 1008 |
my $patron_2 = $builder->build( { source => 'Borrower' } ); |
| 1009 |
|
| 1010 |
my $biblioitem = $builder->build( { source => 'Biblioitem' } ); |
| 1011 |
my $item = $builder->build( |
| 1012 |
{ source => 'Item', |
| 1013 |
value => { |
| 1014 |
homebranch => $homebranch->{branchcode}, |
| 1015 |
holdingbranch => $holdingbranch->{branchcode}, |
| 1016 |
notforloan => 0, |
| 1017 |
itemlost => 0, |
| 1018 |
withdrawn => 0, |
| 1019 |
biblionumber => $biblioitem->{biblionumber} |
| 1020 |
} |
| 1021 |
} |
| 1022 |
); |
| 1023 |
|
| 1024 |
set_userenv($holdingbranch); |
| 1025 |
|
| 1026 |
my $ref_issue = 'Koha::Schema::Result::Issue'; # FIXME Should be Koha::Issue |
| 1027 |
my $issue = AddIssue( $patron_1, $item->{barcode} ); |
| 1028 |
|
| 1029 |
my ( $error, $question, $alerts ); |
| 1030 |
|
| 1031 |
# AllowReturnToBranch == homebranch |
| 1032 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'anywhere' ); |
| 1033 |
## Can be issued from homebranch |
| 1034 |
set_userenv($homebranch); |
| 1035 |
is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue ); |
| 1036 |
set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue |
| 1037 |
## Can be issued from holdinbranch |
| 1038 |
set_userenv($holdingbranch); |
| 1039 |
is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue ); |
| 1040 |
set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue |
| 1041 |
## Can be issued from another branch |
| 1042 |
set_userenv($otherbranch); |
| 1043 |
is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue ); |
| 1044 |
set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue |
| 1045 |
|
| 1046 |
# AllowReturnToBranch == holdinbranch |
| 1047 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'holdingbranch' ); |
| 1048 |
## Cannot be issued from homebranch |
| 1049 |
set_userenv($homebranch); |
| 1050 |
is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '' ); |
| 1051 |
## Can be issued from holdingbranch |
| 1052 |
set_userenv($holdingbranch); |
| 1053 |
is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue ); |
| 1054 |
set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue |
| 1055 |
## Cannot be issued from another branch |
| 1056 |
set_userenv($otherbranch); |
| 1057 |
is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '' ); |
| 1058 |
|
| 1059 |
# AllowReturnToBranch == homebranch |
| 1060 |
t::lib::Mocks::mock_preference( 'AllowReturnToBranch', 'homebranch' ); |
| 1061 |
## Can be issued from homebranch |
| 1062 |
set_userenv($homebranch); |
| 1063 |
is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), $ref_issue ); |
| 1064 |
set_userenv($holdingbranch); AddIssue( $patron_1, $item->{barcode} ); # Reinsert the original issue |
| 1065 |
## Cannot be issued from holdinbranch |
| 1066 |
set_userenv($holdingbranch); |
| 1067 |
is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '' ); |
| 1068 |
## Cannot be issued from another branch |
| 1069 |
set_userenv($otherbranch); |
| 1070 |
is ( ref( AddIssue( $patron_2, $item->{barcode} ) ), '' ); |
| 1071 |
# TODO t::lib::Mocks::mock_preference('AllowReturnToBranch', 'homeorholdingbranch'); |
| 1072 |
}; |
| 1073 |
|
| 1074 |
|
| 1001 |
sub set_userenv { |
1075 |
sub set_userenv { |
| 1002 |
my ( $library ) = @_; |
1076 |
my ( $library ) = @_; |
| 1003 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
1077 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, $library->{branchname}, '', '', ''); |
| 1004 |
- |
|
|