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

(-)a/Koha/Item.pm (-2 / +2 lines)
Lines 1972-1978 Returns the items associated with this bundle that are not lost Link Here
1972
1972
1973
sub bundle_items_not_lost {
1973
sub bundle_items_not_lost {
1974
    my ($self) = @_;
1974
    my ($self) = @_;
1975
    return $self->bundle_items->search( { itemlost => { '!=' => 0 } } );
1975
    return $self->bundle_items->search( { itemlost => 0 } );
1976
}
1976
}
1977
1977
1978
=head3 bundle_items_lost
1978
=head3 bundle_items_lost
Lines 1985-1991 Returns the items associated with this bundle that are lost Link Here
1985
1985
1986
sub bundle_items_lost {
1986
sub bundle_items_lost {
1987
    my ($self) = @_;
1987
    my ($self) = @_;
1988
    return $self->bundle_items->search( { itemlost => 0 } );
1988
    return $self->bundle_items->search( { itemlost => { '!=' => 0 } } );
1989
}
1989
}
1990
1990
1991
=head3 is_bundle
1991
=head3 is_bundle
(-)a/t/db_dependent/Items.t (-1 / +3 lines)
Lines 541-547 subtest 'SearchItems test' => sub { Link Here
541
541
542
subtest 'Koha::Item(s) tests' => sub {
542
subtest 'Koha::Item(s) tests' => sub {
543
543
544
    plan tests => 7;
544
    plan tests => 9;
545
545
546
    $schema->storage->txn_begin();
546
    $schema->storage->txn_begin();
547
547
Lines 575-584 subtest 'Koha::Item(s) tests' => sub { Link Here
575
    my $homebranch = $item->home_branch();
575
    my $homebranch = $item->home_branch();
576
    is( ref($homebranch), 'Koha::Library', "Got Koha::Library from home_branch method" );
576
    is( ref($homebranch), 'Koha::Library', "Got Koha::Library from home_branch method" );
577
    is( $homebranch->branchcode(), $library1->{branchcode}, "Home branch code matches homebranch" );
577
    is( $homebranch->branchcode(), $library1->{branchcode}, "Home branch code matches homebranch" );
578
    is( ref( $item->home_library ), 'Koha::Library', 'home_library returns a Koha::Library object' );
578
579
579
    my $holdingbranch = $item->holding_branch();
580
    my $holdingbranch = $item->holding_branch();
580
    is( ref($holdingbranch), 'Koha::Library', "Got Koha::Library from holding_branch method" );
581
    is( ref($holdingbranch), 'Koha::Library', "Got Koha::Library from holding_branch method" );
581
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
582
    is( $holdingbranch->branchcode(), $library2->{branchcode}, "Home branch code matches holdingbranch" );
583
    is( ref( $item->holding_library ), 'Koha::Library', 'holding_library returns a Koha::Library object' );
582
584
583
    $biblio = $item->biblio();
585
    $biblio = $item->biblio();
584
    is( ref($item->biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
586
    is( ref($item->biblio), 'Koha::Biblio', "Got Koha::Biblio from biblio method" );
(-)a/t/db_dependent/Koha/Biblio/ItemGroups.t (-1 / +9 lines)
Lines 36-42 t::lib::Mocks::mock_preference('EnableItemGroups', 1); Link Here
36
36
37
subtest 'add_item() and items() tests' => sub {
37
subtest 'add_item() and items() tests' => sub {
38
38
39
    plan tests => 10;
39
    plan tests => 12;
40
40
41
    $schema->storage->txn_begin;
41
    $schema->storage->txn_begin;
42
42
Lines 53-58 subtest 'add_item() and items() tests' => sub { Link Here
53
    my @items = $item_group->items->as_list();
53
    my @items = $item_group->items->as_list();
54
    is( scalar(@items), 1, 'Item group has one item');
54
    is( scalar(@items), 1, 'Item group has one item');
55
    is( $items[0]->id, $item_1->id, 'Item 1 is correct' );
55
    is( $items[0]->id, $item_1->id, 'Item 1 is correct' );
56
    is(
57
        ref( $items[0]->item_group ), 'Koha::Biblio::ItemGroup',
58
        '->item_group should return a Koha::Biblio::ItemGroup object'
59
    );
60
    is(
61
        $items[0]->item_group->item_group_id, $item_group->item_group_id,
62
        '->item_group should return the correct item group'
63
    );
56
64
57
    $item_group->add_item({ item_id => $item_2->id });
65
    $item_group->add_item({ item_id => $item_2->id });
58
    @items = $item_group->items->as_list();
66
    @items = $item_group->items->as_list();
(-)a/t/db_dependent/Koha/Courses.t (+39 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2024 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
24
use t::lib::TestBuilder;
25
26
my $schema  = Koha::Database->new->schema;
27
my $builder = t::lib::TestBuilder->new;
28
29
subtest 'Koha::Course::Reserve->course' => sub {
30
31
    plan tests => 1;
32
33
    $schema->storage->txn_begin;
34
35
    my $reserve = $builder->build_object( { class => 'Koha::Course::Reserves' } );
36
    is( ref( $reserve->course ), 'Koha::Course', '->course should return a Koha::Course object' );
37
38
    $schema->storage->txn_rollback;
39
};
(-)a/t/db_dependent/Koha/Item.t (-7 / +14 lines)
Lines 161-167 subtest 'in_bundle tests' => sub { Link Here
161
};
161
};
162
162
163
subtest 'bundle_items tests' => sub {
163
subtest 'bundle_items tests' => sub {
164
    plan tests => 3;
164
    plan tests => 6;
165
165
166
    $schema->storage->txn_begin;
166
    $schema->storage->txn_begin;
167
167
Lines 189-194 subtest 'bundle_items tests' => sub { Link Here
189
    is( $bundle_items->count, 3,
189
    is( $bundle_items->count, 3,
190
        'bundle_items returns all the bundled items in the set' );
190
        'bundle_items returns all the bundled items in the set' );
191
191
192
    $bundle_item2->itemlost(1)->store;
193
    is( $host_item->bundle_items_not_lost->count,        2 );
194
    is( $host_item->bundle_items_lost->count,            1 );
195
    is( $host_item->bundle_items_lost->next->itemnumber, $bundle_item2->itemnumber );
196
192
    $schema->storage->txn_rollback;
197
    $schema->storage->txn_rollback;
193
};
198
};
194
199
Lines 1157-1174 subtest 'renewal_branchcode' => sub { Link Here
1157
    $schema->storage->txn_rollback;
1162
    $schema->storage->txn_rollback;
1158
};
1163
};
1159
1164
1160
subtest 'Tests for itemtype' => sub {
1165
subtest 'Tests for itemtype|item_type' => sub {
1161
    plan tests => 2;
1166
    plan tests => 4;
1162
    $schema->storage->txn_begin;
1167
    $schema->storage->txn_begin;
1163
1168
1164
    my $biblio = $builder->build_sample_biblio;
1169
    my $biblio = $builder->build_sample_biblio;
1165
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
1170
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
1166
    my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itemtype->itemtype });
1171
    my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, itype => $itemtype->itemtype });
1167
1172
1168
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
1173
    t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
1169
    is( $item->itemtype->itemtype, $item->itype, 'Pref enabled' );
1174
    is( $item->itemtype->itemtype,  $item->itype, 'Pref enabled' );
1170
    t::lib::Mocks::mock_preference('item-level_itypes', 0);
1175
    is( $item->item_type->itemtype, $item->itype, 'Pref enabled' );
1171
    is( $item->itemtype->itemtype, $biblio->biblioitem->itemtype, 'Pref disabled' );
1176
    t::lib::Mocks::mock_preference( 'item-level_itypes', 0 );
1177
    is( $item->itemtype->itemtype,  $biblio->biblioitem->itemtype, 'Pref disabled' );
1178
    is( $item->item_type->itemtype, $biblio->biblioitem->itemtype, 'Pref disabled' );
1172
1179
1173
    $schema->storage->txn_rollback;
1180
    $schema->storage->txn_rollback;
1174
};
1181
};
(-)a/t/db_dependent/Koha/Items.t (-16 / +101 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 17;
22
use Test::More tests => 20;
23
23
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Exception;
25
use Test::Exception;
Lines 1382-1392 subtest 'store' => sub { Link Here
1382
    };
1382
    };
1383
};
1383
};
1384
1384
1385
subtest 'get_transfer' => sub {
1385
subtest 'serial_item' => sub {
1386
    plan tests => 7;
1386
1387
    plan tests => 3;
1388
1389
    $schema->storage->txn_begin;
1390
1391
    my $item = $builder->build_sample_item;
1392
    my $serial_item =
1393
        $builder->build_object( { class => 'Koha::Serial::Items', value => { itemnumber => $item->itemnumber } } );
1394
    is( ref( $item->serial_item ),      'Koha::Serial::Item' );
1395
    is( $item->serial_item->itemnumber, $item->itemnumber );
1396
1397
    is( ref( $item->serial_item->serial ), 'Koha::Serial', 'Koha::Serial::Item->serial returns a Koha::Serial object' );
1398
1399
    $schema->storage->txn_rollback;
1400
1401
};
1402
1403
subtest 'item_group_item' => sub {
1404
1405
    plan tests => 2;
1406
1407
    $schema->storage->txn_begin;
1408
1409
    my $biblio = $builder->build_sample_biblio();
1410
    my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
1411
    my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
1412
1413
    my $item_group = Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id } )->store();
1414
    $item_group->add_item( { item_id => $item_1->itemnumber } );
1415
1416
    is(
1417
        ref( $item_1->item_group_item ), 'Koha::Biblio::ItemGroup::Item',
1418
        '->item_group_item should return a Koha::Biblio::ItemGroup::Item object'
1419
    );
1420
    is( $item_1->item_group_item->item_id, $item_1->itemnumber, '->item_group_item should return the correct item' );
1421
1422
    $schema->storage->txn_rollback;
1423
1424
};
1425
1426
subtest 'course_item' => sub {
1427
1428
    plan tests => 2;
1429
1430
    $schema->storage->txn_begin;
1431
1432
    my $item = $builder->build_sample_item;
1433
    my $course_item =
1434
        $builder->build_object( { class => 'Koha::Course::Items', value => { itemnumber => $item->itemnumber } } );
1435
    is( ref( $item->course_item ), 'Koha::Course::Item', '->course_item should return a Koha::Course::Item object' );
1436
    is( $item->course_item->ci_id, $course_item->ci_id,  '->course_item should return the correct object' );
1437
1438
    $schema->storage->txn_rollback;
1439
1440
};
1441
1442
subtest 'get_transfer|transfer' => sub {
1443
    plan tests => 9;
1387
1444
1388
    my $transfer = $new_item_1->get_transfer();
1445
    my $transfer = $new_item_1->get_transfer();
1389
    is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item is not in transit' );
1446
    is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item is not in transit' );
1447
    is( $new_item_1->transfer, undef );
1390
1448
1391
    my $library_to = $builder->build( { source => 'Branch' } );
1449
    my $library_to = $builder->build( { source => 'Branch' } );
1392
1450
Lines 1408-1413 subtest 'get_transfer' => sub { Link Here
1408
1466
1409
    $transfer = $new_item_1->get_transfer();
1467
    $transfer = $new_item_1->get_transfer();
1410
    is( ref($transfer), 'Koha::Item::Transfer', 'Koha::Item->get_transfer should return a Koha::Item::Transfer object' );
1468
    is( ref($transfer), 'Koha::Item::Transfer', 'Koha::Item->get_transfer should return a Koha::Item::Transfer object' );
1469
    is( ref($new_item_1->transfer), 'Koha::Item::Transfer' );
1411
1470
1412
    my $transfer_2 = $builder->build_object(
1471
    my $transfer_2 = $builder->build_object(
1413
        {
1472
        {
Lines 1459-1479 subtest 'get_transfer' => sub { Link Here
1459
};
1518
};
1460
1519
1461
subtest 'holds' => sub {
1520
subtest 'holds' => sub {
1462
    plan tests => 5;
1521
    plan tests => 7;
1463
1522
1464
    my $biblio = $builder->build_sample_biblio();
1523
    my $biblio = $builder->build_sample_biblio();
1465
    my $item   = $builder->build_sample_item({
1524
    my $item   = $builder->build_sample_item(
1466
        biblionumber => $biblio->biblionumber,
1525
        {
1467
    });
1526
            biblionumber => $biblio->biblionumber,
1468
    is($item->holds->count, 0, "Nothing returned if no holds");
1527
        }
1469
    my $hold1 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'T' }});
1528
    );
1470
    my $hold2 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'W' }});
1529
    is( $item->holds->count, 0,     "Nothing returned if no holds" );
1471
    my $hold3 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'W' }});
1530
    is( $item->first_hold,   undef, 'No hold yet' );
1472
1531
    my $yesterday = dt_from_string->subtract( days => 1 )->ymd;
1473
    is($item->holds()->count,3,"Three holds found");
1532
    my $hold1     = $builder->build(
1474
    is($item->holds({found => 'W'})->count,2,"Two waiting holds found");
1533
        {
1475
    is_deeply($item->holds({found => 'T'})->next->unblessed,$hold1,"Found transit holds matches the hold");
1534
            source => 'Reserve',
1476
    is($item->holds({found => undef})->count, 0,"Nothing returned if no matching holds");
1535
            value  => {
1536
                itemnumber => $item->itemnumber, found => 'T', reservedate => $yesterday, suspend => 0, priority => 2
1537
            }
1538
        }
1539
    );
1540
    my $hold2 = $builder->build(
1541
        {
1542
            source => 'Reserve',
1543
            value  => {
1544
                itemnumber => $item->itemnumber, found => 'W', reservedate => $yesterday, suspend => 0, priority => 1
1545
            }
1546
        }
1547
    );
1548
    my $hold3 = $builder->build(
1549
        {
1550
            source => 'Reserve',
1551
            value  => {
1552
                itemnumber => $item->itemnumber, found => 'W', reservedate => $yesterday, suspend => 0, priority => 3
1553
            }
1554
        }
1555
    );
1556
1557
    is( $item->holds()->count,                   3, "Three holds found" );
1558
    is( $item->holds( { found => 'W' } )->count, 2, "Two waiting holds found" );
1559
    is_deeply( $item->holds( { found => 'T' } )->next->unblessed, $hold1, "Found transit holds matches the hold" );
1560
    is( $item->holds( { found => undef } )->count, 0,                    "Nothing returned if no matching holds" );
1561
    is( $item->first_hold->reserve_id,             $hold2->{reserve_id}, '->first_hold returns the correct hold' );
1477
};
1562
};
1478
1563
1479
subtest 'biblio' => sub {
1564
subtest 'biblio' => sub {
(-)a/t/db_dependent/api/v1/biblios.t (-3 / +34 lines)
Lines 35-41 use C4::Circulation qw( AddIssue AddReturn ); Link Here
35
35
36
use Koha::Biblios;
36
use Koha::Biblios;
37
use Koha::Database;
37
use Koha::Database;
38
use Koha::DateUtils qw (dt_from_string);
38
use Koha::DateUtils qw (dt_from_string output_pref);
39
use Koha::Checkouts;
39
use Koha::Checkouts;
40
use Koha::Old::Checkouts;
40
use Koha::Old::Checkouts;
41
41
Lines 165-171 subtest 'get() tests' => sub { Link Here
165
165
166
subtest 'get_items() tests' => sub {
166
subtest 'get_items() tests' => sub {
167
167
168
    plan tests => 11;
168
    plan tests => 12;
169
169
170
    $schema->storage->txn_begin;
170
    $schema->storage->txn_begin;
171
171
Lines 202-207 subtest 'get_items() tests' => sub { Link Here
202
        ->status_is(200)
202
        ->status_is(200)
203
        ->json_has( '/0/_strings/home_library_id/str' => $item_1->holding_branch->branchname, '_strings are embedded' );
203
        ->json_has( '/0/_strings/home_library_id/str' => $item_1->holding_branch->branchname, '_strings are embedded' );
204
204
205
    subtest 'first_hold+strings' => sub {
206
207
        plan tests => 6;
208
209
        my $patron = $builder->build_object(
210
            {
211
                class => 'Koha::Patrons',
212
                value => {
213
                    flags        => 1,
214
                }
215
            }
216
        );
217
        $patron->set_password( { password => $password, skip_validation => 1 } );
218
        my $userid         = $patron->userid;
219
        my $pickup_library = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } );
220
221
        my $item = $builder->build_sample_item;
222
        my $data = {
223
            patron_id         => $patron->borrowernumber,
224
            biblio_id         => $item->biblionumber,
225
            item_id           => $item->itemnumber,
226
            pickup_library_id => $pickup_library->branchcode,
227
            expiration_date   => output_pref( { dt => DateTime->now->add(days => "3")->truncate(to => 'day'), dateformat => 'iso', dateonly => 1 } ),
228
        };
229
        $t->post_ok( "//$userid:$password@/api/v1/holds" => json => $data )->status_is(201)->json_has('/hold_id');
230
231
        $t->get_ok( "//$userid:$password@/api/v1/biblios/"
232
                . $item->biblionumber
233
                . "/items" => { "x-koha-embed" => "first_hold+strings" } )->status_is(200)
234
            ->json_is( '/0/first_hold/_strings/pickup_library_id' => { type => 'library', str => $pickup_library->branchname } );
235
    };
236
205
    $schema->storage->txn_rollback;
237
    $schema->storage->txn_rollback;
206
};
238
};
207
239
208
- 

Return to bug 36535