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

(-)a/t/db_dependent/Holds.t (-3 / +99 lines)
Lines 7-13 use t::lib::TestBuilder; Link Here
7
7
8
use C4::Context;
8
use C4::Context;
9
9
10
use Test::More tests => 74;
10
use Test::More tests => 75;
11
use Test::Exception;
11
use Test::Exception;
12
12
13
use MARC::Record;
13
use MARC::Record;
Lines 22-34 use Koha::Biblios; Link Here
22
use Koha::CirculationRules;
22
use Koha::CirculationRules;
23
use Koha::Database;
23
use Koha::Database;
24
use Koha::DateUtils qw( dt_from_string output_pref );
24
use Koha::DateUtils qw( dt_from_string output_pref );
25
use Koha::Holds;
25
use Koha::Holds qw( search );
26
use Koha::Checkout;
26
use Koha::Checkout;
27
use Koha::Item::Transfer::Limits;
27
use Koha::Item::Transfer::Limits;
28
use Koha::Items;
28
use Koha::Items;
29
use Koha::Libraries;
29
use Koha::Libraries;
30
use Koha::Library::Groups;
30
use Koha::Library::Groups;
31
use Koha::Patrons;
31
use Koha::Patrons;
32
use Koha::Hold qw( get_items_that_can_fill );
33
use Koha::Item::Transfers;
32
34
33
BEGIN {
35
BEGIN {
34
    use FindBin;
36
    use FindBin;
Lines 1702-1704 subtest 'ModReserve can only update expirationdate for found holds' => sub { Link Here
1702
    $schema->storage->txn_rollback;
1704
    $schema->storage->txn_rollback;
1703
1705
1704
};
1706
};
1705
- 
1707
1708
subtest 'Koha::Holds->get_items_that_can_fill returns items with datecancelled and datearrived' => sub {
1709
    plan tests => 4;
1710
    # biblio item with date arrived and date cancelled
1711
    my $biblio1 = $builder->build_sample_biblio();
1712
    my $item1 = $builder->build_sample_item({ biblionumber => $biblio1->biblionumber });
1713
1714
    my $transfer1 = $builder->build_object({ class => "Koha::Item::Transfers", value => {
1715
        datecancelled => '2022-06-12',
1716
        itemnumber => $item1->itemnumber
1717
    }});
1718
1719
    my $hold1 = $builder->build_object({ class => 'Koha::Holds', value => {
1720
        biblionumber => $biblio1->biblionumber,
1721
        itemnumber => undef,
1722
        itemtype => undef,
1723
        found => undef
1724
    }});
1725
1726
    # biblio item with date arrived and NO date cancelled
1727
    my $biblio2 = $builder->build_sample_biblio();
1728
    my $item2 = $builder->build_sample_item({ biblionumber => $biblio2->biblionumber });
1729
1730
    my $transfer2 = $builder->build_object({ class => "Koha::Item::Transfers", value => {
1731
        datecancelled => undef,
1732
        itemnumber => $item2->itemnumber
1733
    }});
1734
1735
    my $hold2 = $builder->build_object({ class => 'Koha::Holds', value => {
1736
        biblionumber => $biblio2->biblionumber,
1737
        itemnumber => undef,
1738
        itemtype => undef,
1739
        found => undef
1740
    }});
1741
1742
    # biblio item with NO date arrived and date cancelled
1743
    my $biblio3 = $builder->build_sample_biblio();
1744
    my $item3 = $builder->build_sample_item({ biblionumber => $biblio3->biblionumber });
1745
1746
    my $transfer3 = $builder->build_object({ class => "Koha::Item::Transfers", value => {
1747
        datecancelled => '2022-06-12',
1748
        itemnumber => $item3->itemnumber,
1749
        datearrived => undef
1750
    }});
1751
1752
    my $hold3 = $builder->build_object({ class => 'Koha::Holds', value => {
1753
        biblionumber => $biblio3->biblionumber,
1754
        itemnumber => undef,
1755
        itemtype => undef,
1756
        found => undef
1757
    }});
1758
1759
1760
    # biblio item with NO date arrived and NO date cancelled
1761
    my $biblio4 = $builder->build_sample_biblio();
1762
    my $item4 = $builder->build_sample_item({ biblionumber => $biblio4->biblionumber });
1763
1764
    my $transfer4 = $builder->build_object({ class => "Koha::Item::Transfers", value => {
1765
        datecancelled => undef,
1766
        itemnumber => $item4->itemnumber,
1767
        datearrived => undef
1768
    }});
1769
1770
    my $hold4 = $builder->build_object({ class => 'Koha::Holds', value => {
1771
        biblionumber => $biblio4->biblionumber,
1772
        itemnumber => undef,
1773
        itemtype => undef,
1774
        found => undef
1775
    }});
1776
1777
    # create the holds which get_items_that_can_fill will be ran on
1778
    my $holds1 = Koha::Holds->search({reserve_id => $hold1->id});
1779
    my $holds2 = Koha::Holds->search({reserve_id => $hold2->id});
1780
    my $holds3 = Koha::Holds->search({reserve_id => $hold3->id});
1781
    my $holds4 = Koha::Holds->search({reserve_id => $hold4->id});
1782
1783
    my $items_that_can_fill1 = $holds1->get_items_that_can_fill;
1784
    my $items_that_can_fill2 = $holds2->get_items_that_can_fill;
1785
    my $items_that_can_fill3 = $holds3->get_items_that_can_fill;
1786
    my $items_that_can_fill4 = $holds4->get_items_that_can_fill;
1787
1788
    # get the item number that will be compared to with the items that are called which get_items_that_can_fill returns
1789
    my %item_unblessed1 = $item1->unblessed;
1790
    # used for first test case
1791
1792
    my %items_that_can_fill_unblessed1 = $items_that_can_fill1->unblessed;
1793
    my %items_that_can_fill_unblessed2 = $items_that_can_fill2->unblessed;
1794
    my %items_that_can_fill_unblessed3 = $items_that_can_fill3->unblessed;
1795
    my %items_that_can_fill_unblessed4 = $items_that_can_fill4->unblessed;
1796
1797
    is($items_that_can_fill_unblessed1{"itemnumber"}, $item_unblessed1{"itemnumber"}, "Koha::Holds->get_items_that_can_fill returns item with defined datearrived and datecancelled");
1798
    is($items_that_can_fill_unblessed2{"itemnumber"}, undef, "Koha::Holds->get_items_that_can_fill doesn't return item with defined datearrived and undefined datecancelled");
1799
    is($items_that_can_fill_unblessed3{"itemnumber"}, undef, "Koha::Holds->get_items_that_can_fill doesn't return item with undefined datearrived and defined datecancelled");
1800
    is($items_that_can_fill_unblessed3{"itemnumber"}, undef, "Koha::Holds->get_items_that_can_fill doesn't return item with undefined datearrived and undefined datecancelled");
1801
}

Return to bug 30447