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

(-)a/t/db_dependent/Circulation/CanBookBeIssued.t (+144 lines)
Line 0 Link Here
1
#!/usr/bin/env perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 2;
21
use Test::NoWarnings;
22
use C4::Members;
23
use C4::Reserves    qw( AddReserve ReservesOnSamePeriod );
24
use C4::Circulation qw( CanBookBeIssued );
25
use Koha::DateUtils qw( dt_from_string );
26
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
30
my $schema = Koha::Database->new->schema;
31
$schema->storage->txn_begin;
32
33
my $builder = t::lib::TestBuilder->new();
34
35
subtest 'Tests for CanBookBeIssued with overlap reserves' => sub {
36
    plan tests => 7;
37
38
    Koha::CirculationRules->set_rules(
39
        {
40
            branchcode   => undef,
41
            categorycode => undef,
42
            itemtype     => undef,
43
            rules        => {
44
                reservesallowed  => 25,
45
                holds_per_record => 1,
46
            }
47
        }
48
    );
49
50
    t::lib::Mocks::mock_preference( 'PreventCheckoutOnSameReservePeriod', 1 );
51
    my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
52
    my $branch       = $builder->build( { source => 'Branch', value => { branchcode => 'BRC' } } );
53
    my $branchcode   = $branch->{branchcode};
54
55
    my $patron_1 = $builder->build_object(
56
        {
57
            class => 'Koha::Patrons',
58
            value => {
59
                branchcode   => $branchcode,
60
                categorycode => $categorycode,
61
            }
62
        }
63
    );
64
65
    my $patron_2 = $builder->build_object(
66
        {
67
            class => 'Koha::Patrons',
68
            value => {
69
                branchcode   => $branchcode,
70
                categorycode => $categorycode,
71
            }
72
        }
73
    );
74
75
    my $biblio     = $builder->build( { source => 'Biblio' } );
76
    my $biblioitem = $builder->build(
77
        {
78
            source => 'Biblioitem',
79
            value  => {
80
                biblionumber => $biblio->{biblionumber},
81
            },
82
        }
83
    );
84
    my $item = $builder->build(
85
        {
86
            source => 'Item',
87
            value  => {
88
                biblionumber     => $biblio->{biblionumber},
89
                biblioitemnumber => $biblioitem->{biblioitemnumber},
90
                withdrawn        => 0,
91
                itemlost         => 0,
92
                notforloan       => 0,
93
            },
94
        }
95
    );
96
97
    my $startdate = dt_from_string();
98
    $startdate->add_duration( DateTime::Duration->new( days => 4 ) );
99
    my $expdate = $startdate->clone();
100
    $expdate->add_duration( DateTime::Duration->new( days => 10 ) );
101
102
    my $reserveid = AddReserve(
103
        {
104
            branchcode       => $branchcode,
105
            borrowernumber   => $patron_1->borrowernumber,
106
            biblionumber     => $item->{biblionumber},
107
            priority         => 1,
108
            reservation_date => $startdate->ymd,
109
            expiration_date  => $expdate->ymd,
110
        }
111
    );
112
    is( defined $reserveid, 1, "Hold has been placed" );
113
114
    my $non_overlap_duedate = dt_from_string();
115
    $non_overlap_duedate->add_duration( DateTime::Duration->new( days => 2 ) );
116
    my ( $error, $question, $alerts ) =
117
        CanBookBeIssued( $patron_2, $item->{barcode}, $non_overlap_duedate, 1, 0 );
118
119
    is_deeply( $error,    {}, "" );
120
    is_deeply( $question, {}, "" );
121
    is_deeply( $alerts,   {}, "" );
122
123
    my $overlap_duedate = dt_from_string();
124
    $overlap_duedate->add_duration( DateTime::Duration->new( days => 5 ) );
125
    ( $error, $question, $alerts ) =
126
        CanBookBeIssued( $patron_2, $item->{barcode}, $overlap_duedate, 1, 0 );
127
128
    is_deeply( $error, {}, "" );
129
    my $expected = {
130
        RESERVED          => 1,
131
        resfirstname      => $patron_1->firstname,
132
        ressurname        => $patron_1->surname,
133
        rescardnumber     => $patron_1->cardnumber,
134
        resborrowernumber => $patron_1->borrowernumber,
135
        resbranchcode     => $patron_1->branchcode,
136
        resreservedate    => $startdate->ymd,
137
        reserve_id        => $reserveid,
138
    };
139
140
    is_deeply( $question, $expected, "Need confirmation" );
141
    is_deeply( $alerts,   {},        "" );
142
};
143
144
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Reserves/ReserveDate.t (-1 / +138 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 7;
21
use Test::Warn;
22
use Test::NoWarnings;
23
24
use MARC::Record;
25
use DateTime::Duration;
26
27
use C4::Biblio;
28
use C4::Items;
29
use C4::Members;
30
use C4::Circulation;
31
use C4::Reserves;
32
use Koha::Holds;
33
use t::lib::Mocks;
34
use t::lib::TestBuilder;
35
36
use Koha::DateUtils;
37
38
use_ok('C4::Reserves');
39
40
# Start transaction
41
my $database = Koha::Database->new();
42
my $schema   = $database->schema();
43
$schema->storage->txn_begin();
44
my $dbh = C4::Context->dbh;
45
$dbh->do('DELETE FROM circulation_rules');
46
47
$dbh->{AutoCommit} = 0;
48
$dbh->{RaiseError} = 1;
49
50
my $builder = t::lib::TestBuilder->new;
51
52
my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
53
my $library      = $builder->build( { source => 'Branch' } )->{branchcode};
54
my $branchcode   = Koha::Libraries->search->next->branchcode;
55
56
my $frameworkcode = q//;
57
58
my $borrower = $builder->build(
59
    {
60
        source => 'Borrower',
61
        value  => {
62
            branchcode   => $branchcode,
63
            categorycode => $categorycode,
64
        }
65
    }
66
);
67
68
my $borrower2 = $builder->build(
69
    {
70
        source => 'Borrower',
71
        value  => {
72
            branchcode   => $branchcode,
73
            categorycode => $categorycode,
74
        }
75
    }
76
);
77
78
my $borrowernumber  = $borrower->{borrowernumber};
79
my $borrowernumber2 = $borrower2->{borrowernumber};
80
81
# Create a helper biblio and item
82
my $bibnum = $builder->build_sample_biblio( { frameworkcode => $frameworkcode } )->biblionumber;
83
my $item   = $builder->build_sample_item( { biblionumber => $bibnum, library => $branchcode, barcode => '333' } );
84
my ( $item_bibnum, $bibitemnum, $itemnumber ) = ( $bibnum, $item->biblioitemnumber, $item->itemnumber );
85
86
C4::Context->set_preference( 'AllowHoldDateInFuture', 1 );
87
t::lib::Mocks::mock_preference( 'PreventReservesOnSamePeriod', 1 );
88
89
C4::Reserves::AddReserve(
90
    {
91
        branchcode       => $branchcode,
92
        borrowernumber   => $borrowernumber,
93
        biblionumber     => $bibnum,
94
        biblioitemnumber => $bibitemnum,
95
        priority         => 1,
96
        reservation_date => '2015-11-01',
97
        expiration_date  => '2015-11-20',
98
    }
99
);
100
101
is(
102
    C4::Reserves::ReservesOnSamePeriod( $bibnum, undef, '2015-11-25', '2015-11-30' ), undef,
103
    "Period doesn't overlaps"
104
);
105
106
ok( C4::Reserves::ReservesOnSamePeriod( $bibnum, undef, '2015-11-02', '2015-11-10' ), "Period overlaps" );
107
108
my $item2 = $builder->build_sample_item(
109
    { biblionumber => $bibnum, homebranch => $branchcode, holdingbranch => $branchcode, barcode => '444' } );
110
my ( $item_bibnum2, $bibitemnum2, $itemnumber2 ) = ( $bibnum, $item2->biblioitemnumber, $item2->itemnumber );
111
112
is(
113
    C4::Reserves::ReservesOnSamePeriod( $bibnum, undef, '2015-11-02', '2015-11-10' ), undef,
114
    "Period overlaps but there is 2 items"
115
);
116
117
C4::Reserves::AddReserve(
118
    {
119
        branchcode       => $branchcode,
120
        borrowernumber   => $borrowernumber2,
121
        biblionumber     => $bibnum,
122
        biblioitemnumber => $bibitemnum,
123
        priority         => 1,
124
        reservation_date => '2016-02-01',
125
        expiration_date  => '2016-02-10',
126
        itemnumber       => $itemnumber,
127
    }
128
);
129
130
is(
131
    C4::Reserves::ReservesOnSamePeriod( $bibnum, $itemnumber, '02/12/2015', '10/12/2015' ), undef,
132
    "Period on item does not overlap (with metric date format)"
133
);
134
135
my $reserve = C4::Reserves::ReservesOnSamePeriod( $bibnum, $itemnumber, '2016-01-31', '2016-02-05' );
136
is( $reserve->[0]->{itemnumber}, $itemnumber, 'Period on item overlaps' );
137
138
$dbh->rollback;

Return to bug 15261