|
Lines 1019-1067
subtest 'deletion' => sub {
Link Here
|
| 1019 |
}; |
1019 |
}; |
| 1020 |
|
1020 |
|
| 1021 |
subtest 'renewal_branchcode' => sub { |
1021 |
subtest 'renewal_branchcode' => sub { |
| 1022 |
plan tests => 13; |
1022 |
plan tests => 25; |
| 1023 |
|
1023 |
|
| 1024 |
$schema->storage->txn_begin; |
1024 |
$schema->storage->txn_begin; |
| 1025 |
|
1025 |
|
| 1026 |
my $item = $builder->build_sample_item(); |
1026 |
my $item = $builder->build_sample_item(); |
| 1027 |
my $branch = $builder->build_object({ class => 'Koha::Libraries' }); |
1027 |
my $branch = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 1028 |
my $checkout = $builder->build_object({ |
1028 |
my $checkout = $builder->build_object( |
| 1029 |
class => 'Koha::Checkouts', |
1029 |
{ |
| 1030 |
value => { |
1030 |
class => 'Koha::Checkouts', |
| 1031 |
itemnumber => $item->itemnumber, |
1031 |
value => { |
|
|
1032 |
itemnumber => $item->itemnumber, |
| 1033 |
} |
| 1032 |
} |
1034 |
} |
| 1033 |
}); |
1035 |
); |
| 1034 |
|
1036 |
|
|
|
1037 |
C4::Context->interface('intranet'); |
| 1038 |
t::lib::Mocks::mock_userenv( { branchcode => $branch->branchcode } ); |
| 1035 |
|
1039 |
|
| 1036 |
C4::Context->interface( 'intranet' ); |
1040 |
is( $item->renewal_branchcode, $branch->branchcode, "If interface not opac, we get the branch from context" ); |
| 1037 |
t::lib::Mocks::mock_userenv({ branchcode => $branch->branchcode }); |
1041 |
is( |
|
|
1042 |
$item->renewal_branchcode( { branch => "PANDA" } ), $branch->branchcode, |
| 1043 |
"If interface not opac, we get the branch from context even if we pass one in" |
| 1044 |
); |
| 1045 |
C4::Context->set_userenv( 51, 'userid4tests', undef, 'firstname', 'surname', undef, undef, 0, undef, undef, undef ) |
| 1046 |
; #mock userenv doesn't let us set null branch |
| 1047 |
is( |
| 1048 |
$item->renewal_branchcode( { branch => "PANDA" } ), "PANDA", |
| 1049 |
"If interface not opac, we get the branch we pass one in if context not set" |
| 1050 |
); |
| 1038 |
|
1051 |
|
| 1039 |
is( $item->renewal_branchcode, $branch->branchcode, "If interface not opac, we get the branch from context"); |
1052 |
C4::Context->interface('opac'); |
| 1040 |
is( $item->renewal_branchcode({ branch => "PANDA"}), $branch->branchcode, "If interface not opac, we get the branch from context even if we pass one in"); |
|
|
| 1041 |
C4::Context->set_userenv(51, 'userid4tests', undef, 'firstname', 'surname', undef, undef, 0, undef, undef, undef ); #mock userenv doesn't let us set null branch |
| 1042 |
is( $item->renewal_branchcode({ branch => "PANDA"}), "PANDA", "If interface not opac, we get the branch we pass one in if context not set"); |
| 1043 |
|
1053 |
|
| 1044 |
C4::Context->interface( 'opac' ); |
1054 |
t::lib::Mocks::mock_preference( 'OpacRenewalBranch', undef ); |
|
|
1055 |
is( $item->renewal_branchcode, 'OPACRenew', "If interface opac and OpacRenewalBranch undef, we get OPACRenew" ); |
| 1056 |
is( |
| 1057 |
$item->renewal_branchcode( { branch => 'COW' } ), 'OPACRenew', |
| 1058 |
"If interface opac and OpacRenewalBranch undef, we get OPACRenew even if branch passed" |
| 1059 |
); |
| 1045 |
|
1060 |
|
| 1046 |
t::lib::Mocks::mock_preference('OpacRenewalBranch', undef); |
1061 |
t::lib::Mocks::mock_preference( 'OpacRenewalBranch', 'none' ); |
| 1047 |
is( $item->renewal_branchcode, 'OPACRenew', "If interface opac and OpacRenewalBranch undef, we get OPACRenew"); |
1062 |
is( $item->renewal_branchcode, '', "If interface opac and OpacRenewalBranch is none, we get blank string" ); |
| 1048 |
is( $item->renewal_branchcode({branch=>'COW'}), 'OPACRenew', "If interface opac and OpacRenewalBranch undef, we get OPACRenew even if branch passed"); |
1063 |
is( |
|
|
1064 |
$item->renewal_branchcode( { branch => 'COW' } ), '', |
| 1065 |
"If interface opac and OpacRenewalBranch is none, we get blank string even if branch passed" |
| 1066 |
); |
| 1049 |
|
1067 |
|
| 1050 |
t::lib::Mocks::mock_preference('OpacRenewalBranch', 'none'); |
1068 |
t::lib::Mocks::mock_preference( 'OpacRenewalBranch', 'checkoutbranch' ); |
| 1051 |
is( $item->renewal_branchcode, '', "If interface opac and OpacRenewalBranch is none, we get blank string"); |
1069 |
is( |
| 1052 |
is( $item->renewal_branchcode({branch=>'COW'}), '', "If interface opac and OpacRenewalBranch is none, we get blank string even if branch passed"); |
1070 |
$item->renewal_branchcode, $checkout->branchcode, |
|
|
1071 |
"If interface opac and OpacRenewalBranch set to checkoutbranch, we get branch of checkout" |
| 1072 |
); |
| 1073 |
is( |
| 1074 |
$item->renewal_branchcode( { branch => 'MONKEY' } ), $checkout->branchcode, |
| 1075 |
"If interface opac and OpacRenewalBranch set to checkoutbranch, we get branch of checkout even if branch passed" |
| 1076 |
); |
| 1053 |
|
1077 |
|
| 1054 |
t::lib::Mocks::mock_preference('OpacRenewalBranch', 'checkoutbranch'); |
1078 |
t::lib::Mocks::mock_preference( 'OpacRenewalBranch', 'patronhomebranch' ); |
| 1055 |
is( $item->renewal_branchcode, $checkout->branchcode, "If interface opac and OpacRenewalBranch set to checkoutbranch, we get branch of checkout"); |
1079 |
is( |
| 1056 |
is( $item->renewal_branchcode({branch=>'MONKEY'}), $checkout->branchcode, "If interface opac and OpacRenewalBranch set to checkoutbranch, we get branch of checkout even if branch passed"); |
1080 |
$item->renewal_branchcode, $checkout->patron->branchcode, |
|
|
1081 |
"If interface opac and OpacRenewalBranch set to patronbranch, we get branch of patron" |
| 1082 |
); |
| 1083 |
is( |
| 1084 |
$item->renewal_branchcode( { branch => 'TURKEY' } ), $checkout->patron->branchcode, |
| 1085 |
"If interface opac and OpacRenewalBranch set to patronbranch, we get branch of patron even if branch passed" |
| 1086 |
); |
| 1057 |
|
1087 |
|
| 1058 |
t::lib::Mocks::mock_preference('OpacRenewalBranch','patronhomebranch'); |
1088 |
t::lib::Mocks::mock_preference( 'OpacRenewalBranch', 'itemhomebranch' ); |
| 1059 |
is( $item->renewal_branchcode, $checkout->patron->branchcode, "If interface opac and OpacRenewalBranch set to patronbranch, we get branch of patron"); |
1089 |
is( |
| 1060 |
is( $item->renewal_branchcode({branch=>'TURKEY'}), $checkout->patron->branchcode, "If interface opac and OpacRenewalBranch set to patronbranch, we get branch of patron even if branch passed"); |
1090 |
$item->renewal_branchcode, $item->homebranch, |
|
|
1091 |
"If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item" |
| 1092 |
); |
| 1093 |
is( |
| 1094 |
$item->renewal_branchcode( { branch => 'MANATEE' } ), $item->homebranch, |
| 1095 |
"If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item even if branch passed" |
| 1096 |
); |
| 1097 |
|
| 1098 |
C4::Context->interface('api'); |
| 1099 |
|
| 1100 |
t::lib::Mocks::mock_preference( 'RESTAPIRenewalBranch', undef ); |
| 1101 |
is( $item->renewal_branchcode, 'APIRenew', "If interface api and RESTAPIRenewalBranch undef, we get APIRenew" ); |
| 1102 |
is( |
| 1103 |
$item->renewal_branchcode( { branch => 'COW' } ), 'APIRenew', |
| 1104 |
"If interface api and RESTAPIRenewalBranch undef, we get APIRenew even if branch passed" |
| 1105 |
); |
| 1106 |
|
| 1107 |
t::lib::Mocks::mock_preference( 'RESTAPIRenewalBranch', 'none' ); |
| 1108 |
is( $item->renewal_branchcode, '', "If interface api and RESTAPIRenewalBranch is none, we get blank string" ); |
| 1109 |
is( |
| 1110 |
$item->renewal_branchcode( { branch => 'COW' } ), '', |
| 1111 |
"If interface api and RESTAPIRenewalBranch is none, we get blank string even if branch passed" |
| 1112 |
); |
| 1061 |
|
1113 |
|
| 1062 |
t::lib::Mocks::mock_preference('OpacRenewalBranch','itemhomebranch'); |
1114 |
t::lib::Mocks::mock_preference( 'RESTAPIRenewalBranch', 'checkoutbranch' ); |
| 1063 |
is( $item->renewal_branchcode, $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item"); |
1115 |
is( |
| 1064 |
is( $item->renewal_branchcode({branch=>'MANATEE'}), $item->homebranch, "If interface opac and OpacRenewalBranch set to itemhomebranch, we get homebranch of item even if branch passed"); |
1116 |
$item->renewal_branchcode, $checkout->branchcode, |
|
|
1117 |
"If interface api and RESTAPIRenewalBranch set to checkoutbranch, we get branch of checkout" |
| 1118 |
); |
| 1119 |
is( |
| 1120 |
$item->renewal_branchcode( { branch => 'MONKEY' } ), $checkout->branchcode, |
| 1121 |
"If interface api and RESTAPIRenewalBranch set to checkoutbranch, we get branch of checkout even if branch passed" |
| 1122 |
); |
| 1123 |
|
| 1124 |
t::lib::Mocks::mock_preference( 'RESTAPIRenewalBranch', 'patronhomebranch' ); |
| 1125 |
is( |
| 1126 |
$item->renewal_branchcode, $checkout->patron->branchcode, |
| 1127 |
"If interface api and RESTAPIRenewalBranch set to patronbranch, we get branch of patron" |
| 1128 |
); |
| 1129 |
is( |
| 1130 |
$item->renewal_branchcode( { branch => 'TURKEY' } ), $checkout->patron->branchcode, |
| 1131 |
"If interface api and RESTAPIRenewalBranch set to patronbranch, we get branch of patron even if branch passed" |
| 1132 |
); |
| 1133 |
|
| 1134 |
t::lib::Mocks::mock_preference( 'RESTAPIRenewalBranch', 'itemhomebranch' ); |
| 1135 |
is( |
| 1136 |
$item->renewal_branchcode, $item->homebranch, |
| 1137 |
"If interface api and RESTAPIRenewalBranch set to itemhomebranch, we get homebranch of item" |
| 1138 |
); |
| 1139 |
is( |
| 1140 |
$item->renewal_branchcode( { branch => 'MANATEE' } ), $item->homebranch, |
| 1141 |
"If interface api and RESTAPIRenewalBranch set to itemhomebranch, we get homebranch of item even if branch passed" |
| 1142 |
); |
| 1143 |
|
| 1144 |
t::lib::Mocks::mock_userenv( { branchcode => $branch->branchcode } ); |
| 1145 |
t::lib::Mocks::mock_preference( 'RESTAPIRenewalBranch', 'apiuserbranch' ); |
| 1146 |
is( |
| 1147 |
$item->renewal_branchcode, $branch->branchcode, |
| 1148 |
"If interface api and RESTAPIRenewalBranch set to apiuserbranch, we get branch from userenv" |
| 1149 |
); |
| 1150 |
is( |
| 1151 |
$item->renewal_branchcode( { branch => 'MANATEE' } ), $branch->branchcode, |
| 1152 |
"If interface api and RESTAPIRenewalBranch set to apiuserbranch, we get branch from userenv even if branch passed" |
| 1153 |
); |
| 1154 |
C4::Context->set_userenv( 51, 'userid4tests', undef, 'firstname', 'surname', undef, undef, 0, undef, undef, undef ) |
| 1155 |
; #mock userenv doesn't let us set null branch |
| 1065 |
|
1156 |
|
| 1066 |
$schema->storage->txn_rollback; |
1157 |
$schema->storage->txn_rollback; |
| 1067 |
}; |
1158 |
}; |
| 1068 |
- |
|
|