|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 2; |
22 |
use Test::More tests => 3; |
| 23 |
|
23 |
|
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
|
Lines 140-142
subtest 'set_pickup_location() tests' => sub {
Link Here
|
| 140 |
|
140 |
|
| 141 |
$schema->storage->txn_rollback; |
141 |
$schema->storage->txn_rollback; |
| 142 |
}; |
142 |
}; |
| 143 |
- |
143 |
|
|
|
144 |
subtest 'is_pickup_location_valid() tests' => sub { |
| 145 |
|
| 146 |
plan tests => 4; |
| 147 |
|
| 148 |
$schema->storage->txn_begin; |
| 149 |
|
| 150 |
my $mock_biblio = Test::MockModule->new('Koha::Biblio'); |
| 151 |
my $mock_item = Test::MockModule->new('Koha::Item'); |
| 152 |
|
| 153 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
| 154 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
| 155 |
my $library_3 = $builder->build_object({ class => 'Koha::Libraries' }); |
| 156 |
|
| 157 |
# let's control what Koha::Biblio->pickup_locations returns, for testing |
| 158 |
$mock_biblio->mock( 'pickup_locations', sub { |
| 159 |
return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } ); |
| 160 |
}); |
| 161 |
# let's mock what Koha::Item->pickup_locations returns, for testing |
| 162 |
$mock_item->mock( 'pickup_locations', sub { |
| 163 |
return Koha::Libraries->search( { branchcode => [ $library_2->branchcode, $library_3->branchcode ] } ); |
| 164 |
}); |
| 165 |
|
| 166 |
my $biblio = $builder->build_sample_biblio; |
| 167 |
my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); |
| 168 |
|
| 169 |
# Test biblio-level holds |
| 170 |
my $biblio_hold = $builder->build_object( |
| 171 |
{ |
| 172 |
class => "Koha::Holds", |
| 173 |
value => { |
| 174 |
biblionumber => $biblio->biblionumber, |
| 175 |
branchcode => $library_3->branchcode, |
| 176 |
itemnumber => undef, |
| 177 |
} |
| 178 |
} |
| 179 |
); |
| 180 |
|
| 181 |
ok( !$biblio_hold->is_pickup_location_valid({ library_id => $library_1->branchcode }), 'Pickup location invalid'); |
| 182 |
ok( $biblio_hold->is_pickup_location_valid({ library_id => $library_2->id }), 'Pickup location valid'); |
| 183 |
|
| 184 |
# Test item-level holds |
| 185 |
my $item_hold = $builder->build_object( |
| 186 |
{ |
| 187 |
class => "Koha::Holds", |
| 188 |
value => { |
| 189 |
biblionumber => $biblio->biblionumber, |
| 190 |
branchcode => $library_3->branchcode, |
| 191 |
itemnumber => $item->itemnumber, |
| 192 |
} |
| 193 |
} |
| 194 |
); |
| 195 |
|
| 196 |
ok( !$item_hold->is_pickup_location_valid({ library_id => $library_1->branchcode }), 'Pickup location invalid'); |
| 197 |
ok( $item_hold->is_pickup_location_valid({ library_id => $library_2->id }), 'Pickup location valid' ); |
| 198 |
|
| 199 |
$schema->storage->txn_rollback; |
| 200 |
}; |