@ -92,63 +92,119 @@ subtest 'store' => sub {
$ item - > delete ;
subtest 'permanent_location' = > sub {
plan tests = > 7 ;
plan tests = > 2 ;
my $ location = 'my_loc' ;
my $ attributes = {
homebranch = > $ library - > { branchcode } ,
holdingbranch = > $ library - > { branchcode } ,
biblionumber = > $ biblio - > biblionumber ,
location = > $ location ,
subtest 'location passed to ->store' = > sub {
plan tests = > 7 ;
my $ location = 'my_loc' ;
my $ attributes = {
homebranch = > $ library - > { branchcode } ,
holdingbranch = > $ library - > { branchcode } ,
biblionumber = > $ biblio - > biblionumber ,
location = > $ location ,
} ;
{
# NewItemsDefaultLocation not set
t::lib::Mocks:: mock_preference ( 'NewItemsDefaultLocation' , '' ) ;
# Not passing permanent_location on creating the item
my $ item = Koha::Item - > new ( $ attributes ) - > store - > get_from_storage ;
is ( $ item - > location , $ location ,
'location must have been set to location if given' ) ;
is ( $ item - > permanent_location , $ item - > location ,
'permanent_location must have been set to location if not given' ) ;
$ item - > delete ;
# Passing permanent_location on creating the item
$ item = Koha::Item - > new (
{ %$ attributes , permanent_location = > 'perm_loc' } )
- > store - > get_from_storage ;
is ( $ item - > permanent_location , 'perm_loc' ,
'permanent_location must have been kept if given' ) ;
$ item - > delete ;
}
{
# NewItemsDefaultLocation set
my $ default_location = 'default_location' ;
t::lib::Mocks:: mock_preference ( 'NewItemsDefaultLocation' , $ default_location ) ;
# Not passing permanent_location on creating the item
my $ item = Koha::Item - > new ( $ attributes ) - > store - > get_from_storage ;
is ( $ item - > location , $ location ,
'location must have been kept if given' ) ;
is ( $ item - > permanent_location , $ location ,
'permanent_location must have been set to the location given' ) ;
$ item - > delete ;
# Passing permanent_location on creating the item
$ item = Koha::Item - > new (
{ %$ attributes , permanent_location = > 'perm_loc' } )
- > store - > get_from_storage ;
is ( $ item - > location , $ location ,
'location must have been kept if given' ) ;
is ( $ item - > permanent_location , 'perm_loc' ,
'permanent_location must have been kept if given' ) ;
$ item - > delete ;
}
} ;
{
# NewItemsDefaultLocation not set
t::lib::Mocks:: mock_preference ( 'NewItemsDefaultLocation' , '' ) ;
# Not passing permanent_location on creating the item
my $ item = Koha::Item - > new ( $ attributes ) - > store - > get_from_storage ;
is ( $ item - > location , $ location ,
'location must have been set to location if given' ) ;
is ( $ item - > permanent_location , $ item - > location ,
'permanent_location must have been set to location if not given' ) ;
$ item - > delete ;
# Passing permanent_location on creating the item
$ item = Koha::Item - > new (
{ %$ attributes , permanent_location = > 'perm_loc' } )
- > store - > get_from_storage ;
is ( $ item - > permanent_location , 'perm_loc' ,
'permanent_location must have been kept if given' ) ;
$ item - > delete ;
}
subtest 'location NOT passed to ->store' = > sub {
plan tests = > 7 ;
{
# NewItemsDefaultLocation set
my $ default_location = 'default_location' ;
t::lib::Mocks:: mock_preference ( 'NewItemsDefaultLocation' , $ default_location ) ;
# Not passing permanent_location on creating the item
my $ item = Koha::Item - > new ( $ attributes ) - > store - > get_from_storage ;
is ( $ item - > location , $ default_location ,
'location must have been set to default_location even if given' # FIXME this sounds wrong! Must be done in any cases?
) ;
is ( $ item - > permanent_location , $ location ,
'permanent_location must have been set to the location given' ) ;
$ item - > delete ;
# Passing permanent_location on creating the item
$ item = Koha::Item - > new (
{ %$ attributes , permanent_location = > 'perm_loc' } )
- > store - > get_from_storage ;
is ( $ item - > location , $ default_location ,
'location must have been set to default_location even if given' # FIXME this sounds wrong! Must be done in any cases?
) ;
is ( $ item - > permanent_location , $ location ,
'permanent_location must have been set to the location given'
) ;
$ item - > delete ;
}
my $ attributes = {
homebranch = > $ library - > { branchcode } ,
holdingbranch = > $ library - > { branchcode } ,
biblionumber = > $ biblio - > biblionumber ,
} ;
{
# NewItemsDefaultLocation not set
t::lib::Mocks:: mock_preference ( 'NewItemsDefaultLocation' , '' ) ;
# Not passing permanent_location on creating the item
my $ item = Koha::Item - > new ( $ attributes ) - > store - > get_from_storage ;
is ( $ item - > location , undef ,
'location not passed and no default, it is undef' ) ;
is ( $ item - > permanent_location , $ item - > location ,
'permanent_location must have been set to location if not given' ) ;
$ item - > delete ;
# Passing permanent_location on creating the item
$ item = Koha::Item - > new (
{ %$ attributes , permanent_location = > 'perm_loc' } )
- > store - > get_from_storage ;
is ( $ item - > permanent_location , 'perm_loc' ,
'permanent_location must have been kept if given' ) ;
$ item - > delete ;
}
{
# NewItemsDefaultLocation set
my $ default_location = 'default_location' ;
t::lib::Mocks:: mock_preference ( 'NewItemsDefaultLocation' , $ default_location ) ;
# Not passing permanent_location on creating the item
my $ item = Koha::Item - > new ( $ attributes ) - > store - > get_from_storage ;
is ( $ item - > location , $ default_location ,
'location must have been set to default location if not given' ) ;
is ( $ item - > permanent_location , $ default_location ,
'permanent_location must have been set to the default location as well' ) ;
$ item - > delete ;
# Passing permanent_location on creating the item
$ item = Koha::Item - > new (
{ %$ attributes , permanent_location = > 'perm_loc' } )
- > store - > get_from_storage ;
is ( $ item - > location , $ default_location ,
'location must have been set to default location if not given' ) ;
is ( $ item - > permanent_location , 'perm_loc' ,
'permanent_location must have been kept if given' ) ;
$ item - > delete ;
}
} ;
} ;