@ -156,30 +156,11 @@ subtest "as_marc_field() tests" => sub {
} ;
subtest 'pickup_locations' = > sub {
plan tests = > 119 ;
$ schema - > storage - > txn_begin ;
my $ dbh = C4::Context - > dbh ;
# Cleanup database
Koha::Holds - > search - > delete ;
$ dbh - > do ( 'DELETE FROM issues' ) ;
Koha::Patrons - > search - > delete ;
Koha::Items - > search - > delete ;
Koha::Libraries - > search - > delete ;
Koha::CirculationRules - > search - > delete ;
Koha::CirculationRules - > set_rules (
{
categorycode = > undef ,
itemtype = > undef ,
branchcode = > undef ,
rules = > {
reservesallowed = > 25 ,
}
}
) ;
my $ root1 = $ builder - > build_object ( { class = > 'Koha::Library::Groups' , value = > { ft_local_hold_group = > 1 , branchcode = > undef } } ) ;
my $ root2 = $ builder - > build_object ( { class = > 'Koha::Library::Groups' , value = > { ft_local_hold_group = > 1 , branchcode = > undef } } ) ;
my $ library1 = $ builder - > build_object ( { class = > 'Koha::Libraries' , value = > { pickup_location = > 1 , } } ) ;
@ -192,13 +173,12 @@ subtest 'pickup_locations' => sub {
my $ group2_1 = $ builder - > build_object ( { class = > 'Koha::Library::Groups' , value = > { parent_id = > $ root2 - > id , branchcode = > $ library3 - > branchcode } } ) ;
my $ group2_2 = $ builder - > build_object ( { class = > 'Koha::Library::Groups' , value = > { parent_id = > $ root2 - > id , branchcode = > $ library4 - > branchcode } } ) ;
my $ itemtype = $ builder - > build_object ( { class = > 'Koha::ItemTypes' , value = > { itemtype = > 'test' } } ) ;
my $ item1 = $ builder - > build_sample_item (
{
homebranch = > $ library1 - > branchcode ,
holdingbranch = > $ library2 - > branchcode ,
barcode = > '1' ,
itype = > 'test' ,
ccode = > 'Gollum'
}
) - > store ;
@ -208,25 +188,40 @@ subtest 'pickup_locations' => sub {
homebranch = > $ library3 - > branchcode ,
holdingbranch = > $ library4 - > branchcode ,
barcode = > '3' ,
itype = > 'test' ,
itype = > $ item1 - > itype ,
}
) - > store ;
Koha::CirculationRules - > set_rules (
{
categorycode = > undef ,
itemtype = > $ item1 - > itype ,
branchcode = > undef ,
rules = > {
reservesallowed = > 25 ,
}
}
) ;
my $ patron1 = $ builder - > build_object ( { class = > 'Koha::Patrons' , value = > { branchcode = > $ library1 - > branchcode , firstname = > '1' } } ) ;
my $ patron4 = $ builder - > build_object ( { class = > 'Koha::Patrons' , value = > { branchcode = > $ library4 - > branchcode , firstname = > '4' } } ) ;
my $ all_count = Koha::Libraries - > search ( { pickup_location = > 1 } ) - > count ( ) ;
plan tests = > ( $ all_count + 1 ) * 7 + 31 + 60 ;
my $ results = {
"1-1-1-any" = > 3 ,
"1-1-1-any" = > $ all_count ,
"1-1-1-holdgroup" = > 2 ,
"1-1-1-patrongroup" = > 2 ,
"1-1-1-homebranch" = > 1 ,
"1-1-1-holdingbranch" = > 1 ,
"1-1-2-any" = > 3 ,
"1-1-2-any" = > $ all_count ,
"1-1-2-holdgroup" = > 2 ,
"1-1-2-patrongroup" = > 2 ,
"1-1-2-homebranch" = > 1 ,
"1-1-2-holdingbranch" = > 1 ,
"1-1-3-any" = > 3 ,
"1-1-3-any" = > $ all_count ,
"1-1-3-holdgroup" = > 2 ,
"1-1-3-patrongroup" = > 2 ,
"1-1-3-homebranch" = > 1 ,
@ -236,7 +231,7 @@ subtest 'pickup_locations' => sub {
"1-4-1-patrongroup" = > 0 ,
"1-4-1-homebranch" = > 0 ,
"1-4-1-holdingbranch" = > 0 ,
"1-4-2-any" = > 3 ,
"1-4-2-any" = > $ all_count ,
"1-4-2-holdgroup" = > 2 ,
"1-4-2-patrongroup" = > 1 ,
"1-4-2-homebranch" = > 1 ,
@ -251,7 +246,7 @@ subtest 'pickup_locations' => sub {
"3-1-1-patrongroup" = > 0 ,
"3-1-1-homebranch" = > 0 ,
"3-1-1-holdingbranch" = > 0 ,
"3-1-2-any" = > 3 ,
"3-1-2-any" = > $ all_count ,
"3-1-2-holdgroup" = > 1 ,
"3-1-2-patrongroup" = > 2 ,
"3-1-2-homebranch" = > 0 ,
@ -266,12 +261,12 @@ subtest 'pickup_locations' => sub {
"3-4-1-patrongroup" = > 0 ,
"3-4-1-homebranch" = > 0 ,
"3-4-1-holdingbranch" = > 0 ,
"3-4-2-any" = > 3 ,
"3-4-2-any" = > $ all_count ,
"3-4-2-holdgroup" = > 1 ,
"3-4-2-patrongroup" = > 1 ,
"3-4-2-homebranch" = > 0 ,
"3-4-2-holdingbranch" = > 1 ,
"3-4-3-any" = > 3 ,
"3-4-3-any" = > $ all_count ,
"3-4-3-holdgroup" = > 1 ,
"3-4-3-patrongroup" = > 1 ,
"3-4-3-homebranch" = > 0 ,
@ -365,7 +360,7 @@ subtest 'pickup_locations' => sub {
) ;
my $ pickup_locations = $ item1 - > pickup_locations ( { patron = > $ patron1 } ) - > as_list ;
is ( scalar @$ pickup_locations , 2 , "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library" ) ;
is ( scalar @$ pickup_locations , $ all_count - 1 , "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library" ) ;
$ builder - > build_object (
{
@ -380,11 +375,11 @@ subtest 'pickup_locations' => sub {
) ;
$ pickup_locations = $ item1 - > pickup_locations ( { patron = > $ patron1 } ) - > as_list ;
is ( scalar @$ pickup_locations , 1 , "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries" ) ;
is ( scalar @$ pickup_locations , $ all_count - 2 , "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries" ) ;
t::lib::Mocks:: mock_preference ( 'BranchTransferLimitsType' , 'ccode' ) ;
$ pickup_locations = $ item1 - > pickup_locations ( { patron = > $ patron1 } ) - > as_list ;
is ( scalar @$ pickup_locations , 3 , "With no transfer limits of type ccode we get back the libraries that are pickup locations" ) ;
is ( scalar @$ pickup_locations , $ all_count , "With no transfer limits of type ccode we get back the libraries that are pickup locations" ) ;
$ builder - > build_object (
{
@ -399,7 +394,7 @@ subtest 'pickup_locations' => sub {
) ;
$ pickup_locations = $ item1 - > pickup_locations ( { patron = > $ patron1 } ) - > as_list ;
is ( scalar @$ pickup_locations , 2 , "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library" ) ;
is ( scalar @$ pickup_locations , $ all_count - 1 , "With a transfer limits we get back the libraries that are pickup locations minus 1 limited library" ) ;
$ builder - > build_object (
{
@ -414,7 +409,7 @@ subtest 'pickup_locations' => sub {
) ;
$ pickup_locations = $ item1 - > pickup_locations ( { patron = > $ patron1 } ) - > as_list ;
is ( scalar @$ pickup_locations , 1 , "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries" ) ;
is ( scalar @$ pickup_locations , $ all_count - 2 , "With 2 transfer limits we get back the libraries that are pickup locations minus 2 limited libraries" ) ;
t::lib::Mocks:: mock_preference ( 'UseBranchTransferLimits' , 0 ) ;