View | Details | Raw Unified | Return to bug 26273
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Biblios.t (-2 / +82 lines)
Lines 19-26 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
23
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
26
24
use MARC::Field;
27
use MARC::Field;
25
28
26
use C4::Items;
29
use C4::Items;
Lines 221-223 subtest 'custom_cover_image_url' => sub { Link Here
221
};
224
};
222
225
223
$schema->storage->txn_rollback;
226
$schema->storage->txn_rollback;
224
- 
227
228
subtest 'pickup_locations() tests' => sub {
229
230
    plan tests => 1;
231
232
    $schema->storage->txn_begin;
233
234
    # Build 8 libraries
235
    my $l_1 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
236
    my $l_2 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
237
    my $l_3 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
238
    my $l_4 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
239
    my $l_5 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
240
    my $l_6 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
241
    my $l_7 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
242
    my $l_8 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1 } });
243
244
    # Mock Koha::Item->pickup_locations so we have control on the output
245
    # The $switch variable controls the output.
246
    my $switch  = 0;
247
    my $queries = [
248
        { branchcode => [ $l_1->branchcode, $l_2->branchcode ] },
249
        { branchcode => [ $l_3->branchcode, $l_4->branchcode ] },
250
        { branchcode => [ $l_5->branchcode, $l_6->branchcode ] },
251
        { branchcode => [ $l_7->branchcode, $l_8->branchcode ] }
252
    ];
253
254
    my $mock_item = Test::MockModule->new('Koha::Item');
255
    $mock_item->mock(
256
        'pickup_locations',
257
        sub {
258
            my $query = $queries->[$switch];
259
            $switch++;
260
            return Koha::Libraries->search($query);
261
        }
262
    );
263
264
    # Two biblios
265
    my $biblio_1 = $builder->build_sample_biblio;
266
    my $biblio_2 = $builder->build_sample_biblio;
267
268
    # Two items each
269
    my $item_1_1 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber });
270
    my $item_1_2 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber });
271
    my $item_2_1 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber });
272
    my $item_2_2 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber });
273
274
    my $biblios = Koha::Biblios->search(
275
        {
276
            biblionumber => [ $biblio_1->biblionumber, $biblio_2->biblionumber ]
277
        }
278
    );
279
280
    my $library_ids = [
281
        Koha::Libraries->search(
282
            {
283
                branchcode => [
284
                    $l_1->branchcode, $l_2->branchcode, $l_3->branchcode,
285
                    $l_4->branchcode, $l_5->branchcode, $l_6->branchcode,
286
                    $l_7->branchcode, $l_8->branchcode
287
                ]
288
            },
289
            { order_by => ['branchname'] }
290
        )->_resultset->get_column('branchcode')->all
291
    ];
292
293
    my $pickup_locations_ids = [
294
        $biblios->pickup_locations->_resultset->get_column('branchcode')->all
295
    ];
296
297
    is_deeply(
298
        $library_ids,
299
        $pickup_locations_ids,
300
        'The addition of all biblios+items pickup locations is returned'
301
    );
302
303
    $schema->storage->txn_rollback;
304
};

Return to bug 26273