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

(-)a/t/db_dependent/Circulation.t (-36 / +57 lines)
Lines 34-40 use t::lib::Mocks; Link Here
34
use t::lib::TestBuilder;
34
use t::lib::TestBuilder;
35
35
36
use C4::Accounts;
36
use C4::Accounts;
37
use C4::Calendar;
38
use C4::Circulation
37
use C4::Circulation
39
    qw( AddIssue AddReturn CanBookBeRenewed GetIssuingCharges AddRenewal GetSoonestRenewDate GetLatestAutoRenewDate LostItem GetUpcomingDueIssues CanBookBeIssued AddIssuingCharge MarkIssueReturned ProcessOfflinePayment transferbook );
38
    qw( AddIssue AddReturn CanBookBeRenewed GetIssuingCharges AddRenewal GetSoonestRenewDate GetLatestAutoRenewDate LostItem GetUpcomingDueIssues CanBookBeIssued AddIssuingCharge MarkIssueReturned ProcessOfflinePayment transferbook );
40
use C4::Biblio;
39
use C4::Biblio;
Lines 59-64 use Koha::Account::Offsets; Link Here
59
use Koha::ActionLogs;
58
use Koha::ActionLogs;
60
use Koha::Notice::Messages;
59
use Koha::Notice::Messages;
61
use Koha::Cache::Memory::Lite;
60
use Koha::Cache::Memory::Lite;
61
use Koha::DiscreteCalendar;
62
62
63
my $builder = t::lib::TestBuilder->new;
63
my $builder = t::lib::TestBuilder->new;
64
64
Lines 121-128 my $mocked_datetime = Test::MockModule->new('DateTime'); Link Here
121
$mocked_datetime->mock( 'now', sub { return $now_value->clone; } );
121
$mocked_datetime->mock( 'now', sub { return $now_value->clone; } );
122
122
123
my $cache = Koha::Caches->get_instance();
123
my $cache = Koha::Caches->get_instance();
124
$dbh->do(q|DELETE FROM special_holidays|);
124
$dbh->do(q|DELETE FROM discrete_calendar|);
125
$dbh->do(q|DELETE FROM repeatable_holidays|);
126
my $branches = Koha::Libraries->search();
125
my $branches = Koha::Libraries->search();
127
for my $branch ( $branches->next ) {
126
for my $branch ( $branches->next ) {
128
    my $key = $branch->branchcode . "_holidays";
127
    my $key = $branch->branchcode . "_holidays";
Lines 3758-3772 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
3758
    t::lib::Mocks::mock_preference( 'SuspensionsCalendar', 'noSuspensionsWhenClosed' );
3757
    t::lib::Mocks::mock_preference( 'SuspensionsCalendar', 'noSuspensionsWhenClosed' );
3759
3758
3760
    # Adding a holiday 2 days ago
3759
    # Adding a holiday 2 days ago
3761
    my $calendar     = C4::Calendar->new( branchcode => $library->{branchcode} );
3760
    my $calendar     = Koha::DiscreteCalendar->new({ branchcode => $library->{branchcode} });
3762
    my $two_days_ago = $now->clone->subtract( days => 2 );
3761
    my $two_days_ago = $now->clone->subtract( days => 2 );
3763
    $calendar->insert_single_holiday(
3762
    $calendar->edit_holiday({
3764
        day         => $two_days_ago->day,
3763
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
3765
        month       => $two_days_ago->month,
3764
        override     => 1,
3766
        year        => $two_days_ago->year,
3765
        start_date   => $two_days_ago,
3767
        title       => 'holidayTest-2d',
3766
        end_date     => $two_days_ago,
3768
        description => 'holidayDesc 2 days ago'
3767
        title        => 'holidayTest-2d',
3769
    );
3768
        description  => 'holidayDesc 2 days ago'
3769
    });
3770
3770
3771
    # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday)
3771
    # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday)
3772
    $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) );
3772
    $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) );
Lines 3782-3794 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
3782
3782
3783
    # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped
3783
    # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped
3784
    my $two_days_ahead = $now->clone->add( days => 2 );
3784
    my $two_days_ahead = $now->clone->add( days => 2 );
3785
    $calendar->insert_single_holiday(
3785
    $calendar->edit_holiday({
3786
        day         => $two_days_ahead->day,
3786
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
3787
        month       => $two_days_ahead->month,
3787
        start_date   => $two_days_ahead,
3788
        year        => $two_days_ahead->year,
3788
        end_date     => $two_days_ahead,
3789
        title       => 'holidayTest+2d',
3789
        title        => 'holidayTest+2d',
3790
        description => 'holidayDesc 2 days ahead'
3790
        description  => 'holidayDesc 2 days ahead'
3791
    );
3791
    });
3792
3792
3793
    # Same as above, but we should skip D+2
3793
    # Same as above, but we should skip D+2
3794
    $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 );
3794
    $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 );
Lines 3804-3816 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
3804
3804
3805
    # Adding another holiday, day of expiration date
3805
    # Adding another holiday, day of expiration date
3806
    my $expected_expiration_dt = dt_from_string($expected_expiration);
3806
    my $expected_expiration_dt = dt_from_string($expected_expiration);
3807
    $calendar->insert_single_holiday(
3807
    $calendar->edit_holiday({
3808
        day         => $expected_expiration_dt->day,
3808
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
3809
        month       => $expected_expiration_dt->month,
3809
        start_date   => $expected_expiration_dt,
3810
        year        => $expected_expiration_dt->year,
3810
        end_date     => $expected_expiration_dt,
3811
        title       => 'holidayTest_exp',
3811
        title        => 'holidayTest_exp',
3812
        description => 'holidayDesc on expiration date'
3812
        description  => 'holidayDesc on expiration date'
3813
    );
3813
    });
3814
3814
3815
    # Expiration date will be the day after
3815
    # Expiration date will be the day after
3816
    test_debarment_on_checkout(
3816
    test_debarment_on_checkout(
Lines 3892-3897 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
3892
        $message->{WasReturned} && exists $message->{PrevDebarred}, 1,
3892
        $message->{WasReturned} && exists $message->{PrevDebarred}, 1,
3893
        'Previously debarred message for Addreturn when overdue'
3893
        'Previously debarred message for Addreturn when overdue'
3894
    );
3894
    );
3895
3896
    # delete holidays
3897
    $calendar->edit_holiday({
3898
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
3899
        start_date   => $two_days_ago,
3900
        end_date     => $expected_expiration_dt,
3901
        title        => '',
3902
        description  => ''
3903
    });
3895
};
3904
};
3896
3905
3897
subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub {
3906
subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub {
Lines 6095-6113 subtest 'Incremented fee tests' => sub { Link Here
6095
    $accountline->delete();
6104
    $accountline->delete();
6096
    $issue->delete();
6105
    $issue->delete();
6097
6106
6098
    my $calendar = C4::Calendar->new( branchcode => $library->id );
6107
    my $calendar = Koha::DiscreteCalendar->new({ branchcode => $library->id });
6099
6108
6100
    # DateTime 1..7 (Mon..Sun), C4::Calendar 0..6 (Sun..Sat)
6109
    # DateTime 1..7 (Mon..Sun), Koha::DiscreteCalender 1..7 (Sun..Sat)
6101
    my $closed_day =
6110
    my $closed_day =
6102
          ( $dt_from->day_of_week == 6 ) ? 0
6111
        ( $dt_from->day_of_week == 7 ) ? 1
6103
        : ( $dt_from->day_of_week == 7 ) ? 1
6112
      : $dt_from->day_of_week + 1;
6104
        :                                  $dt_from->day_of_week + 1;
6105
    my $closed_day_name = $dt_from->clone->add( days => 1 )->day_name;
6113
    my $closed_day_name = $dt_from->clone->add( days => 1 )->day_name;
6106
    $calendar->insert_week_day_holiday(
6114
    $calendar->edit_holiday({
6107
        weekday     => $closed_day,
6115
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
6108
        title       => 'Test holiday',
6116
        weekday      => $closed_day,
6109
        description => 'Test holiday'
6117
        start_date   => $dt_from,
6110
    );
6118
        end_date     => $dt_from,
6119
        title        => 'Test holiday',
6120
        description  => 'Test holiday'
6121
    });
6111
    $issue       = AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
6122
    $issue       = AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
6112
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
6123
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
6113
    is(
6124
    is(
Lines 6227-6233 subtest 'Incremented fee tests' => sub { Link Here
6227
    $accountline->delete();
6238
    $accountline->delete();
6228
    $issue->delete();
6239
    $issue->delete();
6229
6240
6230
    $calendar->delete_holiday( weekday => $closed_day );
6241
    $calendar->edit_holiday({
6242
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
6243
        delete_type  => 1,
6244
        override     => 1,
6245
        weekday      => $closed_day,
6246
        start_date   => $dt_from,
6247
        end_date     => $dt_from,
6248
        title        => '',
6249
        description  => '',
6250
    });
6251
6231
    $issue       = AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
6252
    $issue       = AddIssue( $patron, $item->barcode, $dt_to, undef, $dt_from );
6232
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
6253
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
6233
    is(
6254
    is(
(-)a/t/db_dependent/Circulation/CalcDateDue.t (-114 / +167 lines)
Lines 9-15 use DBI; Link Here
9
use DateTime;
9
use DateTime;
10
use t::lib::Mocks;
10
use t::lib::Mocks;
11
use t::lib::TestBuilder;
11
use t::lib::TestBuilder;
12
use C4::Calendar;
12
use Koha::DiscreteCalendar;
13
use Koha::DateUtils qw( dt_from_string );
13
use Koha::DateUtils qw( dt_from_string );
14
use Koha::Library::Hours;
14
use Koha::Library::Hours;
15
use Koha::CirculationRules;
15
use Koha::CirculationRules;
Lines 40-45 my $issuelength = 10; Link Here
40
my $renewalperiod = 5;
40
my $renewalperiod = 5;
41
my $lengthunit    = 'days';
41
my $lengthunit    = 'days';
42
42
43
$builder->fill_discrete_calendar({ branchcode => $library->branchcode, start_date => $dateexpiry, days => 365 });
44
43
Koha::CirculationRules->search()->delete();
45
Koha::CirculationRules->search()->delete();
44
Koha::CirculationRules->set_rules(
46
Koha::CirculationRules->set_rules(
45
    {
47
    {
Lines 79-101 is( $date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays' ) Link Here
79
81
80
# Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and
82
# Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and
81
# useDaysMode different from 'Days', return should forward the dateexpiry.
83
# useDaysMode different from 'Days', return should forward the dateexpiry.
82
my $calendar = C4::Calendar->new( branchcode => $branchcode );
84
my $calendar = Koha::DiscreteCalendar->new({ branchcode => $branchcode });
83
$calendar->insert_single_holiday(
85
$calendar->edit_holiday({
84
    day         => 1,
86
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
85
    month       => 1,
87
    override     => 1,
86
    year        => 2013,
88
    start_date   => dt_from_string($dateexpiry, 'iso'),
87
    title       => 'holidayTest',
89
    end_date     => dt_from_string($dateexpiry, 'iso'),
88
    description => 'holidayDesc'
90
    title        => 'holidayTest',
89
);
91
    description  => 'holidayDesc'
92
});
90
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
93
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
91
is( $date, '2012-12-31T23:59:00', 'date expiry should be 2013-01-01 -1 day' );
94
is( $date, '2012-12-31T23:59:00', 'date expiry should be 2013-01-01 -1 day' );
92
$calendar->insert_single_holiday(
95
$calendar->edit_holiday({
93
    day         => 31,
96
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
94
    month       => 12,
97
    override     => 1,
95
    year        => 2012,
98
    start_date   => dt_from_string('2012-12-31', 'iso'),
96
    title       => 'holidayTest',
99
    end_date     => dt_from_string('2012-12-31', 'iso'),
97
    description => 'holidayDesc'
100
    title        => 'holidayTest',
98
);
101
    description  => 'holidayDesc'
102
});
99
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
103
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
100
is( $date, '2012-12-30T23:59:00', 'date expiry should be 2013-01-01 -2 day' );
104
is( $date, '2012-12-30T23:59:00', 'date expiry should be 2013-01-01 -2 day' );
101
105
Lines 137-149 is( Link Here
137
# Now let's add a closed day on the expected renewal date, it should
141
# Now let's add a closed day on the expected renewal date, it should
138
# roll forward as per Datedue (i.e. one day at a time)
142
# roll forward as per Datedue (i.e. one day at a time)
139
# For issues...
143
# For issues...
140
$calendar->insert_single_holiday(
144
my $issue_date = dt_from_string('2013-02-' . (9 + $issuelength), 'iso');
141
    day         => 9 + $issuelength,
145
$calendar->edit_holiday({
142
    month       => 2,
146
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
143
    year        => 2013,
147
    override     => 1,
144
    title       => 'DayweekTest1',
148
    start_date   => $issue_date,
145
    description => 'DayweekTest1'
149
    end_date     => $issue_date,
146
);
150
    title        => 'DayweekTest1',
151
    description  => 'DayweekTest1'
152
});
147
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
153
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
148
is(
154
is(
149
    $date, '2013-02-' . ( 9 + $issuelength + 1 ) . 'T23:59:00',
155
    $date, '2013-02-' . ( 9 + $issuelength + 1 ) . 'T23:59:00',
Lines 151-170 is( Link Here
151
);
157
);
152
158
153
# Remove the holiday we just created
159
# Remove the holiday we just created
154
$calendar->delete_holiday(
160
$calendar->edit_holiday({
155
    day   => 9 + $issuelength,
161
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
156
    month => 2,
162
    override     => 1,
157
    year  => 2013
163
    start_date   => $issue_date,
158
);
164
    end_date     => $issue_date,
165
    title        => '',
166
    description  => '',
167
});
159
168
160
# ...and for renewals...
169
# ...and for renewals...
161
$calendar->insert_single_holiday(
170
my $renewal_date = dt_from_string('2013-02-' . (9 + $renewalperiod), 'iso');
162
    day         => 9 + $renewalperiod,
171
$calendar->edit_holiday({
163
    month       => 2,
172
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
164
    year        => 2013,
173
    override     => 1,
165
    title       => 'DayweekTest2',
174
    start_date   => $renewal_date,
166
    description => 'DayweekTest2'
175
    end_date     => $renewal_date,
167
);
176
    title        => 'DayweekTest2',
177
    description  => 'DayweekTest2'
178
});
168
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
179
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
169
is(
180
is(
170
    $date, '2013-02-' . ( 9 + $renewalperiod + 1 ) . 'T23:59:00',
181
    $date, '2013-02-' . ( 9 + $renewalperiod + 1 ) . 'T23:59:00',
Lines 172-182 is( Link Here
172
);
183
);
173
184
174
# Remove the holiday we just created
185
# Remove the holiday we just created
175
$calendar->delete_holiday(
186
$calendar->edit_holiday({
176
    day   => 9 + $renewalperiod,
187
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
177
    month => 2,
188
    override     => 1,
178
    year  => 2013,
189
    start_date   => $renewal_date,
179
);
190
    end_date     => $renewal_date,
191
    title        => '',
192
    description  => '',
193
});
180
194
181
# Now we test it does the right thing if the loan and renewal periods
195
# Now we test it does the right thing if the loan and renewal periods
182
# are a multiple of 7 days
196
# are a multiple of 7 days
Lines 212-224 my $dayweek_borrower = $builder->build_object( Link Here
212
226
213
# For issues...
227
# For issues...
214
$start_date = DateTime->new( { year => 2013, month => 2, day => 9 } );
228
$start_date = DateTime->new( { year => 2013, month => 2, day => 9 } );
215
$calendar->insert_single_holiday(
229
my $holiday_date = $start_date->clone();
216
    day         => 9 + $dayweek_issuelength,
230
$holiday_date->add(days => $dayweek_issuelength);
217
    month       => 2,
231
$calendar->edit_holiday({
218
    year        => 2013,
232
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
219
    title       => 'DayweekTest3',
233
    override     => 1,
220
    description => 'DayweekTest3'
234
    start_date   => $holiday_date,
221
);
235
    end_date     => $holiday_date,
236
    title        => 'DayweekTest3',
237
    description  => 'DayweekTest3'
238
});
222
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
239
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
223
my $issue_should_add       = $dayweek_issuelength + 7;
240
my $issue_should_add       = $dayweek_issuelength + 7;
224
my $dayweek_issue_expected = $start_date->add( days => $issue_should_add );
241
my $dayweek_issue_expected = $start_date->add( days => $issue_should_add );
Lines 228-248 is( Link Here
228
);
245
);
229
246
230
# Remove the holiday we just created
247
# Remove the holiday we just created
231
$calendar->delete_holiday(
248
$calendar->edit_holiday({
232
    day   => 9 + $dayweek_issuelength,
249
    holiday_type    => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
233
    month => 2,
250
    override        => 1,
234
    year  => 2013,
251
    start_date      => $holiday_date,
235
);
252
    end_date        => $holiday_date,
253
    title           => '',
254
    description     => '',
255
});
236
256
237
# ...and for renewals...
257
# ...and for renewals...
238
$start_date = DateTime->new( { year => 2013, month => 2, day => 9 } );
258
$start_date = DateTime->new( { year => 2013, month => 2, day => 9 } );
239
$calendar->insert_single_holiday(
259
$holiday_date = $start_date->clone();
240
    day         => 9 + $dayweek_renewalperiod,
260
$holiday_date->add(days => $dayweek_renewalperiod);
241
    month       => 2,
261
$calendar->edit_holiday({
242
    year        => 2013,
262
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
243
    title       => 'DayweekTest4',
263
    override     => 1,
244
    description => 'DayweekTest4'
264
    start_date   => $holiday_date,
245
);
265
    end_date     => $holiday_date,
266
    title        => 'DayweekTest4',
267
    description  => 'DayweekTest4'
268
});
246
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, 1 );
269
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower, 1 );
247
my $renewal_should_add       = $dayweek_renewalperiod + 7;
270
my $renewal_should_add       = $dayweek_renewalperiod + 7;
248
my $dayweek_renewal_expected = $start_date->add( days => $renewal_should_add );
271
my $dayweek_renewal_expected = $start_date->add( days => $renewal_should_add );
Lines 252-262 is( Link Here
252
);
275
);
253
276
254
# Remove the holiday we just created
277
# Remove the holiday we just created
255
$calendar->delete_holiday(
278
$calendar->edit_holiday({
256
    day   => 9 + $dayweek_renewalperiod,
279
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
257
    month => 2,
280
    override     => 1,
258
    year  => 2013,
281
    start_date   => $holiday_date,
259
);
282
    end_date     => $holiday_date,
283
    title        => '',
284
    description  => '',
285
});
260
286
261
# Now test it continues to roll forward by 7 days until it finds
287
# Now test it continues to roll forward by 7 days until it finds
262
# an open day, so we create a 3 week period of closed Saturdays
288
# an open day, so we create a 3 week period of closed Saturdays
Lines 264-293 $start_date = DateTime->new( { year => 2013, month => 2, day => 9 } ); Link Here
264
my $expected_rolled_date = DateTime->new( { year => 2013, month => 3, day => 9 } );
290
my $expected_rolled_date = DateTime->new( { year => 2013, month => 3, day => 9 } );
265
my $holiday = $start_date->clone();
291
my $holiday = $start_date->clone();
266
$holiday->add( days => 7 );
292
$holiday->add( days => 7 );
267
$calendar->insert_single_holiday(
293
$calendar->edit_holiday({
268
    day         => $holiday->day,
294
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
269
    month       => $holiday->month,
295
    override     => 1,
270
    year        => 2013,
296
    start_date   => $holiday,
271
    title       => 'DayweekTest5',
297
    end_date     => $holiday,
272
    description => 'DayweekTest5'
298
    title        => 'DayweekTest5',
273
);
299
    description  => 'DayweekTest5'
300
});
274
$holiday->add( days => 7 );
301
$holiday->add( days => 7 );
275
$calendar->insert_single_holiday(
302
$calendar->edit_holiday({
276
    day         => $holiday->day,
303
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
277
    month       => $holiday->month,
304
    override     => 1,
278
    year        => 2013,
305
    start_date   => $holiday,
279
    title       => 'DayweekTest6',
306
    end_date     => $holiday,
280
    description => 'DayweekTest6'
307
    title        => 'DayweekTest6',
281
);
308
    description  => 'DayweekTest6'
309
});
282
$holiday->add( days => 7 );
310
$holiday->add( days => 7 );
283
$calendar->insert_single_holiday(
311
$calendar->edit_holiday({
284
    day         => $holiday->day,
312
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
285
    month       => $holiday->month,
313
    override     => 1,
286
    year        => 2013,
314
    start_date   => $holiday,
287
    title       => 'DayweekTest7',
315
    end_date     => $holiday,
288
    description => 'DayweekTest7'
316
    title        => 'DayweekTest7',
289
);
317
    description  => 'DayweekTest7'
290
318
});
291
# For issues...
319
# For issues...
292
$date                   = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
320
$date                   = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
293
$dayweek_issue_expected = $start_date->add( days => $issue_should_add );
321
$dayweek_issue_expected = $start_date->add( days => $issue_should_add );
Lines 309-342 is( Link Here
309
$start_date = DateTime->new( { year => 2013, month => 2, day => 9 } );
337
$start_date = DateTime->new( { year => 2013, month => 2, day => 9 } );
310
my $del_holiday = $start_date->clone();
338
my $del_holiday = $start_date->clone();
311
$del_holiday->add( days => 7 );
339
$del_holiday->add( days => 7 );
312
$calendar->delete_holiday(
340
$calendar->edit_holiday({
313
    day   => $del_holiday->day,
341
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
314
    month => $del_holiday->month,
342
    override     => 1,
315
    year  => 2013
343
    start_date   => $del_holiday,
316
);
344
    end_date     => $del_holiday,
345
    title        => '',
346
    description  => '',
347
});
317
$del_holiday->add( days => 7 );
348
$del_holiday->add( days => 7 );
318
$calendar->delete_holiday(
349
$calendar->edit_holiday({
319
    day   => $del_holiday->day,
350
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
320
    month => $del_holiday->month,
351
    override     => 1,
321
    year  => 2013
352
    start_date   => $del_holiday,
322
);
353
    end_date     => $del_holiday,
354
    title        => '',
355
    description  => '',
356
});
323
$del_holiday->add( days => 7 );
357
$del_holiday->add( days => 7 );
324
$calendar->delete_holiday(
358
$calendar->edit_holiday({
325
    day   => $del_holiday->day,
359
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
326
    month => $del_holiday->month,
360
    override     => 1,
327
    year  => 2013
361
    start_date   => $del_holiday,
328
);
362
    end_date     => $del_holiday,
363
    title        => '',
364
    description  => '',
365
});
329
366
330
# Now test that useDaysMode "Dayweek" doesn't try to roll forward onto
367
# Now test that useDaysMode "Dayweek" doesn't try to roll forward onto
331
# a permanently closed day and instead rolls forward just one day
368
# a permanently closed day and instead rolls forward just one day
332
$start_date = DateTime->new( { year => 2013, month => 2, day => 9 } );
369
$start_date = DateTime->new( { year => 2013, month => 2, day => 9 } );
333
370
334
# Our tests are concerned with Saturdays, so let's close on Saturdays
371
# Our tests are concerned with Saturdays, so let's close on Saturdays
335
$calendar->insert_week_day_holiday(
372
$calendar->edit_holiday({
336
    weekday     => 6,
373
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
337
    title       => "Saturday closure",
374
    weekday      => 7,
338
    description => "Closed on Saturdays"
375
    override     => 1,
339
);
376
    start_date   => $start_date,
377
    end_date     => $start_date,
378
    title        => "Saturday closure",
379
    description  => "Closed on Saturdays"
380
});
340
381
341
# For issues...
382
# For issues...
342
$date                   = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
383
$date                   = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $dayweek_borrower );
Lines 356-362 is( Link Here
356
);
397
);
357
398
358
# Remove the holiday we just created
399
# Remove the holiday we just created
359
$calendar->delete_holiday( weekday => 6 );
400
$calendar->edit_holiday({
401
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
402
    weekday      => 7,
403
    override     => 1,
404
    delete_type  => 1,
405
    start_date   => $start_date,
406
    end_date     => $start_date,
407
    title        => '',
408
    description  => '',
409
});
360
410
361
# Renewal period of 0 is valid
411
# Renewal period of 0 is valid
362
Koha::CirculationRules->search()->delete();
412
Koha::CirculationRules->search()->delete();
Lines 415-420 my $open = DateTime->new( year => 2023, month => 5, day => 1, hour => 10 )->hms Link Here
415
my $close = DateTime->new( year => 2023, month => 5, day => 1, hour => 16 )->hms;
465
my $close = DateTime->new( year => 2023, month => 5, day => 1, hour => 16 )->hms;
416
my $now   = DateTime->new( year => 2023, month => 5, day => 1, hour => 14 );
466
my $now   = DateTime->new( year => 2023, month => 5, day => 1, hour => 14 );
417
467
468
$builder->fill_discrete_calendar({ branchcode => $library1->{branchcode}, start_date => $now });
469
418
foreach ( 0 .. 6 ) {
470
foreach ( 0 .. 6 ) {
419
471
420
    # library opened 4 hours ago and closes in 2 hours.
472
    # library opened 4 hours ago and closes in 2 hours.
Lines 449-462 is( Link Here
449
my $holiday_tomorrow = $now->clone->add( days => 1 );
501
my $holiday_tomorrow = $now->clone->add( days => 1 );
450
502
451
# consider calendar
503
# consider calendar
452
my $library1_calendar = C4::Calendar->new( branchcode => $library1->{branchcode} );
504
my $library1_calendar = Koha::DiscreteCalendar->new({ branchcode => $library1->{branchcode} });
453
$library1_calendar->insert_single_holiday(
505
$library1_calendar->edit_holiday({
454
    day         => $holiday_tomorrow->day,
506
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
455
    month       => $holiday_tomorrow->month,
507
    start_date  => $holiday_tomorrow,
456
    year        => $holiday_tomorrow->year,
508
    end_date    => $holiday_tomorrow,
457
    title       => 'testholiday',
509
    title       => 'testholiday',
458
    description => 'testholiday'
510
    description => 'testholiday',
459
);
511
    override    => 1,
512
});
460
Koha::CirculationRules->set_rules(
513
Koha::CirculationRules->set_rules(
461
    {
514
    {
462
        categorycode => $patron_category->categorycode,
515
        categorycode => $patron_category->categorycode,
(-)a/t/db_dependent/Circulation/CalcFine.t (+1 lines)
Lines 29-34 my $branch = $builder->build( Link Here
29
        source => 'Branch',
29
        source => 'Branch',
30
    }
30
    }
31
);
31
);
32
$builder->fill_discrete_calendar({ branchcode => $branch->{branchcode}, start_date => '2000-01-01' });
32
33
33
my $category = $builder->build(
34
my $category = $builder->build(
34
    {
35
    {
(-)a/t/db_dependent/Circulation/maxsuspensiondays.t (-5 / +10 lines)
Lines 21-26 $schema->storage->txn_begin; Link Here
21
my $builder = t::lib::TestBuilder->new;
21
my $builder = t::lib::TestBuilder->new;
22
my $dbh     = C4::Context->dbh;
22
my $dbh     = C4::Context->dbh;
23
23
24
# clear any holidays to avoid throwing off the suspension day
25
# calculations
26
$dbh->do('DELETE FROM discrete_calendar');
27
24
my $branchcode      = $builder->build( { source => 'Branch' } )->{branchcode};
28
my $branchcode      = $builder->build( { source => 'Branch' } )->{branchcode};
25
my $itemtype        = $builder->build( { source => 'Itemtype' } )->{itemtype};
29
my $itemtype        = $builder->build( { source => 'Itemtype' } )->{itemtype};
26
my $patron_category = $builder->build( { source => 'Category' } );
30
my $patron_category = $builder->build( { source => 'Category' } );
Lines 70-80 my $itemnumber = Koha::Item->new( Link Here
70
    }
74
    }
71
)->store->itemnumber;
75
)->store->itemnumber;
72
76
73
# clear any holidays to avoid throwing off the suspension day
74
# calculations
75
$dbh->do('DELETE FROM special_holidays');
76
$dbh->do('DELETE FROM repeatable_holidays');
77
78
my $daysago20   = dt_from_string->add_duration( DateTime::Duration->new( days => -20 ) );
77
my $daysago20   = dt_from_string->add_duration( DateTime::Duration->new( days => -20 ) );
79
my $daysafter40 = dt_from_string->add_duration( DateTime::Duration->new( days =>  40 ) );
78
my $daysafter40 = dt_from_string->add_duration( DateTime::Duration->new( days =>  40 ) );
80
79
Lines 131-136 subtest "suspension_chargeperiod" => sub { Link Here
131
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
130
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
132
    my $item   = $builder->build_sample_item;
131
    my $item   = $builder->build_sample_item;
133
132
133
    $builder->fill_discrete_calendar({ branchcode => $patron->{branchcode}, days => 365 });
134
    $builder->fill_discrete_calendar({ branchcode => $item->homebranch, days => 365 });
135
134
    my $last_year    = dt_from_string->clone->subtract( years => 1 );
136
    my $last_year    = dt_from_string->clone->subtract( years => 1 );
135
    my $today        = dt_from_string;
137
    my $today        = dt_from_string;
136
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today );
138
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today );
Lines 159-164 subtest "maxsuspensiondays" => sub { Link Here
159
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
161
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
160
    my $item   = $builder->build_sample_item;
162
    my $item   = $builder->build_sample_item;
161
163
164
    $builder->fill_discrete_calendar({ branchcode => $patron->{branchcode}, days => 365 });
165
    $builder->fill_discrete_calendar({ branchcode => $item->homebranch, days => 365 });
166
162
    my $last_year    = dt_from_string->clone->subtract( years => 1 );
167
    my $last_year    = dt_from_string->clone->subtract( years => 1 );
163
    my $today        = dt_from_string;
168
    my $today        = dt_from_string;
164
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today );
169
    my $new_debar_dt = C4::Circulation::_calculate_new_debar_dt( $patron, $item, $last_year, $today );
(-)a/t/db_dependent/DiscreteCalendar.t (+464 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2015 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
use Test::More tests => 50;
22
use Test::MockModule;
23
24
use t::lib::TestBuilder;
25
26
use C4::Context;
27
use C4::Output;
28
use Koha::DateUtils qw ( dt_from_string );
29
use Koha::DiscreteCalendar;
30
31
32
my $module_context = Test::MockModule->new('C4::Context');
33
my $today = DateTime->today;
34
my $schema = Koha::Database->new->schema;
35
$schema->storage->txn_begin;
36
37
my $builder = t::lib::TestBuilder->new;
38
39
my $branch1 = $builder->build( { source => 'Branch' } )->{branchcode};
40
my $branch2 = $builder->build( { source => 'Branch' } )->{branchcode};
41
42
$builder->fill_discrete_calendar({ branchcode => $branch1, days => 365 });
43
44
$schema->resultset('DiscreteCalendar')->search({
45
    branchcode  => $branch1
46
})->update_all({
47
    is_opened    => 1,
48
    holiday_type => '',
49
    note         => '',
50
    open_hour    => '08:00:00',
51
    close_hour   => '16:00:00'
52
});
53
54
isnt($branch1,'', "First branch to do tests. BranchCode => $branch1");
55
isnt($branch2,'', "Second branch to do tests. BranchCode => $branch2");
56
57
#2 Calendars to make sure branches are treated separately.
58
my $calendar = Koha::DiscreteCalendar->new({branchcode => $branch1});
59
my $calendar2 = Koha::DiscreteCalendar->new({branchcode => $branch2});
60
61
my $unique_holiday = DateTime->today;
62
$calendar->edit_holiday({
63
    title => "Single holiday Today",
64
    holiday_type=> $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
65
    start_date=>$unique_holiday,
66
    end_date=>$unique_holiday
67
});
68
is($calendar->is_opened($unique_holiday), 0, "Branch closed today : $unique_holiday");
69
70
my @unique_holidays = $calendar->get_unique_holidays();
71
is(scalar @unique_holidays, 1, "Set of exception holidays at 1");
72
73
my $yesterday = DateTime->today->subtract(days => 1);
74
$calendar->edit_holiday({
75
    title => "Single holiday Today",
76
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
77
    start_date => $yesterday,
78
    end_date => $yesterday
79
});
80
is($calendar->is_opened($yesterday), 1, "Cannot edit dates in the past without override : $yesterday is not a holiday");
81
82
$calendar->edit_holiday({
83
    title => "Single holiday Today",
84
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
85
    start_date => $yesterday,
86
    end_date => $yesterday,
87
    override => 1
88
});
89
is($calendar->is_opened($yesterday), 0, "Can edit dates in the past without override : $yesterday is a holiday");
90
91
92
my $days_between_start = DateTime->today;
93
my $days_between_end = DateTime->today->add(days => 6);
94
my $days_between = $calendar->days_between($days_between_start, $days_between_end)->in_units('days');
95
is($days_between, 5, "Days between skips holiday");
96
97
my $repeatable_holiday = DateTime->today->add(days => 1);
98
$calendar->edit_holiday({
99
    title => "repeatable",
100
    holiday_type=> $Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE},
101
    start_date=>$repeatable_holiday,
102
    end_date=>$repeatable_holiday
103
});
104
is($calendar->is_opened($repeatable_holiday), 0, "Branch not opened on $repeatable_holiday");
105
106
my @repeatable_holidays = $calendar->get_repeatable_holidays();
107
is(scalar @repeatable_holidays, 1, "Set of repeatable holidays at 1");
108
109
# 1 being mysql DAYOFWEEK() for Sunday
110
$calendar->edit_holiday({
111
    title => "Weekly",
112
    weekday=>1,
113
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
114
    start_date=>$today,
115
    end_date=>$today
116
});
117
my @weekly_holidays = $calendar->get_week_days_holidays();
118
is(scalar @weekly_holidays, 1, "Set of weekly holidays at 1");
119
120
my $sunday = DateTime->today->add(days =>( 7 - $today->day_of_week));
121
is($calendar->is_opened($sunday), 0, "Branch not opened on " . $sunday->day_name ."s");
122
123
my $unique_holiday_range_start = DateTime->today->add(days => 2);
124
my $unique_holiday_range_end = DateTime->today->add(days => 7);
125
$calendar->edit_holiday({
126
    title => "Single holiday range",
127
    holiday_type=>"E",
128
    start_date=>$unique_holiday_range_start,
129
    end_date=>$unique_holiday_range_end
130
});
131
@unique_holidays = $calendar->get_unique_holidays();
132
is(scalar @unique_holidays, 7, "Set of exception holidays at 7");
133
134
my $repeatable_holiday_range_start = DateTime->today->add(days => 8);
135
my $repeatable_holiday_range_end = DateTime->today->add(days => 13);
136
$calendar->edit_holiday({
137
    title => "Repeatable holiday range",
138
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE},
139
    start_date=>$repeatable_holiday_range_start,
140
    end_date=>$repeatable_holiday_range_end
141
});
142
@repeatable_holidays = $calendar->get_repeatable_holidays();
143
is(scalar @repeatable_holidays, 7, "Set of repeatable holidays at 7");
144
145
#Hourly loan
146
# ex :
147
# item due      : 2017-01-24 11:00:00
148
# item returned : 2017-01-26 10:00:00
149
# Branch closed : 2017-01-25
150
# Open/close hours : 08:00 to 16:00 (8h day)
151
# Hours due : 5 hours on 2017-01-24 + 2 hours on 2017-01-26 = 7hours
152
153
my $open_hours_since_start = dt_from_string->truncate(to => 'day')->add(days => 40, hours => 11);
154
my $open_hours_since_end = dt_from_string->truncate(to => 'day')->add(days => 42, hours => 10);
155
my $holiday_between =  dt_from_string->truncate(to => 'day')->add(days => 41);
156
$calendar->edit_holiday({
157
    title => '',
158
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
159
    start_date=>$open_hours_since_start,
160
    end_date=>$open_hours_since_end
161
});
162
163
$calendar->edit_holiday({
164
    title => "Single holiday",
165
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
166
    start_date=> $holiday_between,
167
    end_date=>$holiday_between
168
});
169
my $open_hours_between = $calendar->open_hours_between($open_hours_since_start, $open_hours_since_end);
170
is($open_hours_between, 7, "7 Hours open between $open_hours_since_start and $open_hours_since_end");
171
172
my $christmas = DateTime->new(
173
    year  => $today->year(),
174
    month => 12,
175
    day   => 25,
176
);
177
$calendar->edit_holiday({
178
    title => "Christmas",
179
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE},
180
    start_date=>$christmas,
181
    end_date=>$christmas,
182
    override => 1, # necessary if unit tests are run between Christmas and the first of the year
183
});
184
is($calendar->is_opened($christmas), 0, "Branch closed on Christmas : $christmas");
185
186
my $newyear = DateTime->new(
187
    year  => $today->year() +1,
188
    month => 1,
189
    day   => 1,
190
);
191
192
$calendar->edit_holiday({
193
    title => "New Year",
194
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{REPEATABLE},
195
    start_date=>$newyear,
196
    end_date=>$newyear
197
});
198
is($calendar->is_opened($newyear), 0, "Branch closed on New Year : $newyear");
199
200
#Hours between :
201
my $date_due = DateTime->today->add(days => 1);
202
my $date_returned = DateTime->today->add(hours => 8);
203
my $hours_between = $calendar->hours_between($date_due, $date_returned);
204
205
is($hours_between->in_units('hours'), 16, "Date due $date_due, returned $date_returned, 16 hours in advance");
206
207
$date_due = DateTime->today->add(days => 1);
208
$date_returned = DateTime->today->add(days => 1, hours => 16);
209
$hours_between = $calendar->hours_between($date_due, $date_returned);
210
211
is($hours_between->in_units('hours'), 16, "Date due $date_due, returned $date_returned, 16 hours late");
212
213
214
#delete holidays
215
is($calendar->is_opened($today), 0, "Today is closed");
216
$calendar->edit_holiday({
217
    title => '',
218
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
219
    start_date=>$unique_holiday,
220
    end_date=>$unique_holiday
221
});
222
is($calendar->is_opened($today), 1, "Today's holiday was removed");
223
224
$calendar->edit_holiday({
225
    title => '',
226
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
227
    start_date => $yesterday,
228
    end_date => $yesterday,
229
    override => 1
230
});
231
is($calendar->is_opened($yesterday), 1, "Yesterdays's holiday was removed with override");
232
233
my $new_open_hours = '08:00';
234
$calendar->edit_holiday({
235
    title => '',
236
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
237
    open_hour=>$new_open_hours,
238
    close_hour=>'',
239
    start_date=>$today,
240
    end_date=>$today
241
});
242
is($calendar->get_date_info($today, $branch1)->{open_hour}, '08:00:00', "Open hour changed to 08:00:00");
243
244
isnt($calendar->get_date_info($today, $branch1)->{close_hour}, '', "Close hour not removed");
245
246
my $delete_range_end = DateTime->today->add(days => 30);
247
$calendar->edit_holiday({
248
    title => '',
249
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
250
    start_date=>$today,
251
    end_date=>$delete_range_end
252
});
253
254
255
is($calendar->is_opened($today), 1, "Today's holiday was already removed");
256
is($calendar->is_opened(DateTime->today->add(days => 1)), 1, "Tomorrow's holiday was removed");
257
is($calendar->is_opened($delete_range_end), 1, "End of range holiday was removed");
258
259
#Check if other branch was affected
260
my @unique_holidays_branch2 = $calendar2->get_unique_holidays();
261
is(scalar @unique_holidays_branch2, 0, "Set of exception holidays at 0 for branch => $branch2");
262
my @repeatable_holidays_branch2 = $calendar2->get_repeatable_holidays();
263
is(scalar @repeatable_holidays_branch2, 0, "Set of repeatable holidays at 0 for branch => $branch2");
264
my @weekly_holidays_branch2 = $calendar2->get_week_days_holidays();
265
is(scalar @weekly_holidays_branch2, 0, "Set of weekly holidays at 0 for branch => $branch2");
266
267
268
#Tests for addDate()
269
270
my $one_day_dur = DateTime::Duration->new( days => 1 );
271
my $negative_one_day_dur = DateTime::Duration->new( days => - 1 );
272
my $two_day_dur = DateTime::Duration->new( days => 2 );
273
my $seven_day_dur = DateTime::Duration->new( days => 7 );
274
275
#Preference useDaysMode Calendar
276
$calendar->{days_mode} = 'Calendar';
277
$unique_holiday->add(days => 1);
278
my $tomorrow = DateTime->today->add(days => 1);
279
$calendar->edit_holiday({
280
    title => "Single holiday Today",
281
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
282
    start_date=>$tomorrow,
283
    end_date=>$tomorrow
284
});
285
286
is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(),
287
    $today->add(days => 2)->ymd(),
288
    'Single day add (Calendar)' );
289
290
is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(),
291
    $today->add(days => 2)->ymd(),
292
    'Two days add, skips holiday (Calendar)' );
293
294
cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
295
    $today->add(days => 7)->ymd(),
296
    'Add 7 days (Calendar)' );
297
#Closed Sunday
298
$calendar->edit_holiday({
299
    title => "Weekly",
300
    weekday=>1,
301
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
302
    start_date=>$today,
303
    end_date=>$today
304
});
305
is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
306
    'addDate skips closed Sunday (Calendar)' );
307
#to remove the closed sundays
308
$today = DateTime->today;
309
$calendar->edit_holiday({
310
    title => '',
311
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
312
    start_date=>$today,
313
    end_date=>$delete_range_end
314
});
315
316
is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(),
317
    $today->add(days => - 1)->ymd(),
318
    'Negative call to addDate (Calendar)' );
319
320
#Preference useDaysMode DateDue
321
$calendar->{days_mode} = 'Datedue';
322
#clean everything
323
$today = DateTime->today;
324
$calendar->edit_holiday({
325
    title => '',
326
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
327
    start_date=>$today,
328
    end_date=>$delete_range_end
329
});
330
$calendar->edit_holiday({
331
    title => "Single holiday Today",
332
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
333
    start_date=>$tomorrow,
334
    end_date=>$tomorrow
335
});
336
337
is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(),
338
    $today->add(days => 2)->ymd(),
339
    'Single day add' );
340
341
is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(),
342
    $today->add(days => 2)->ymd(),
343
    'Two days add, skips holiday (Datedue)' );
344
345
cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
346
    $today->add(days => 7)->ymd(),
347
    'Add 7 days (Datedue)' );
348
#Closed Sunday
349
$calendar->edit_holiday({
350
    title => "Weekly",
351
    weekday=>1,
352
    holiday_type=> $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
353
    start_date=>$today,
354
    end_date=>$today
355
});
356
is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
357
    'addDate skips closed Sunday (Datedue)' );
358
#to remove the closed sundays
359
$today = DateTime->today;
360
$calendar->edit_holiday({
361
    title => '',
362
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
363
    start_date=>$today,
364
    end_date=>$delete_range_end
365
});
366
367
is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(),
368
    $today->add(days => - 1)->ymd(),
369
    'Negative call to addDate (Datedue)' );
370
371
#Preference useDaysMode Days
372
$calendar->{days_mode} = 'Days';
373
#clean everything
374
$today = DateTime->today;
375
$calendar->edit_holiday({
376
    title => '',
377
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{NONE},
378
    start_date=>$today,
379
    end_date=>$delete_range_end
380
});
381
$calendar->edit_holiday({
382
    title => "Single holiday Today",
383
    holiday_type=>$Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
384
    start_date=>$tomorrow,
385
    end_date=>$tomorrow
386
});
387
is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(),
388
    $today->add(days => 1)->ymd(),
389
    'Single day add' );
390
391
is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(),
392
    $today->add(days => 2)->ymd(),
393
    'Two days add, skips holiday (Days)' );
394
395
cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq',
396
    $today->add(days => 7)->ymd(),
397
    'Add 7 days (Days)' );
398
#Closed Sunday
399
$calendar->edit_holiday({
400
    title => "Weekly",
401
    weekday => 1,
402
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
403
    start_date => $today,
404
    end_date => $today
405
});
406
is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1,
407
    'addDate skips closed Sunday (Days)' );
408
409
is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(),
410
    $today->add(days => - 1)->ymd(),
411
    'Negative call to addDate (Days)' );
412
413
#Days_forward
414
415
#clean the range
416
$today = DateTime->today;
417
$calendar->edit_holiday({
418
    title => '',
419
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
420
    start_date => $today,
421
    end_date => DateTime->today->add(days => 20)
422
});
423
my $forwarded_dt = $calendar->days_forward($today, 10);
424
425
my $expected = $today->clone;
426
$expected->add(days => 10);
427
is($forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 10 days');
428
429
#Added a holiday
430
$unique_holiday = DateTime->today->add(days => 15);
431
$calendar->edit_holiday({
432
    title => "Single holiday Today",
433
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
434
    start_date => $unique_holiday,
435
    end_date => $unique_holiday
436
});
437
$forwarded_dt = $calendar->days_forward($today, 20);
438
439
$expected->add(days => 11);
440
is($forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 20 days + 1 day for holiday');
441
442
$forwarded_dt = $calendar->days_forward($today, 0);
443
is($forwarded_dt->ymd, $today->ymd, '0 day should return start dt');
444
445
$forwarded_dt = $calendar->days_forward($today, -2);
446
is($forwarded_dt->ymd, $today->ymd, 'negative day should return start dt');
447
448
#copying a branch to an other
449
is($calendar2->is_opened($tomorrow), 1, "$branch2 opened tomorrow");
450
#Added a goliday tomorrow for branch1
451
$calendar->edit_holiday({
452
    title => "Single holiday Today",
453
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
454
    start_date => $tomorrow,
455
    end_date => $tomorrow
456
});
457
#Copy dates from branch1 to branch2
458
$calendar->copy_to_branch($branch2);
459
#Check if branch2 is also closed tomorrow after copying from branch1
460
is($calendar2->is_opened($tomorrow), 0, "$branch2 close tomorrow after copying from $branch1");
461
462
$schema->storage->txn_rollback;
463
464
1;
(-)a/t/db_dependent/Fines.t (+6 lines)
Lines 10-15 use Koha::DateUtils qw( dt_from_string ); Link Here
10
use Test::NoWarnings;
10
use Test::NoWarnings;
11
use Test::More tests => 6;
11
use Test::More tests => 6;
12
12
13
use t::lib::TestBuilder;
14
13
my $schema = Koha::Database->new->schema;
15
my $schema = Koha::Database->new->schema;
14
$schema->storage->txn_begin;
16
$schema->storage->txn_begin;
15
my $dbh = C4::Context->dbh;
17
my $dbh = C4::Context->dbh;
Lines 32-37 my $issuingrule = Koha::CirculationRules->set_rules( Link Here
32
    }
34
    }
33
);
35
);
34
36
37
my $builder = t::lib::TestBuilder->new();
38
$builder->fill_discrete_calendar({ branchcode => '' });
39
$builder->fill_discrete_calendar({ branchcode => '', start_date => '2000-01-01' });
40
35
ok( $issuingrule, 'Issuing rule created' );
41
ok( $issuingrule, 'Issuing rule created' );
36
42
37
my $period_start = dt_from_string('2000-01-01');
43
my $period_start = dt_from_string('2000-01-01');
(-)a/t/db_dependent/Hold.t (-4 / +18 lines)
Lines 22-28 use C4::Context; Link Here
22
use C4::Biblio qw( AddBiblio );
22
use C4::Biblio qw( AddBiblio );
23
use Koha::Database;
23
use Koha::Database;
24
use Koha::Libraries;
24
use Koha::Libraries;
25
use C4::Calendar;
25
use Koha::DiscreteCalendar;
26
use Koha::Patrons;
26
use Koha::Patrons;
27
use Koha::Holds;
27
use Koha::Holds;
28
use Koha::Item;
28
use Koha::Item;
Lines 78-86 my $hold = Koha::Hold->new( Link Here
78
);
78
);
79
$hold->store();
79
$hold->store();
80
80
81
my $b1_cal = C4::Calendar->new( branchcode => $branches[1]->{branchcode} );
81
$builder->fill_discrete_calendar({
82
$b1_cal->insert_single_holiday( day => 2, month => 1, year => 2017, title => "Morty Day", description => "Rick" )
82
    branchcode => $branches[1]->{branchcode},
83
    ;    #Add a holiday
83
    start_date => '2017-01-01',
84
    days => dt_from_string->delta_days( dt_from_string( '2017-01-01' ) )->in_units( 'days'),
85
});
86
my $b1_cal = Koha::DiscreteCalendar->new({ branchcode => $branches[1]->{branchcode} });
87
88
my $holiday = dt_from_string('2017-01-02', 'iso');
89
$b1_cal->edit_holiday({
90
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
91
    override     => 1,
92
    start_date   => $holiday,
93
    end_date     => $holiday,
94
    title        => "Morty Day",
95
    description  => "Rick"
96
});     #Add a holiday
97
84
my $today = dt_from_string;
98
my $today = dt_from_string;
85
is(
99
is(
86
    $hold->age(), $today->delta_days( dt_from_string('2017-01-01') )->in_units('days'),
100
    $hold->age(), $today->delta_days( dt_from_string('2017-01-01') )->in_units('days'),
(-)a/t/db_dependent/Holds.t (-1 lines)
Lines 14-20 use Test::Exception; Link Here
14
use MARC::Record;
14
use MARC::Record;
15
15
16
use C4::Biblio;
16
use C4::Biblio;
17
use C4::Calendar;
18
use C4::Items;
17
use C4::Items;
19
use C4::Reserves
18
use C4::Reserves
20
    qw( AddReserve CalculatePriority ModReserve AutoUnsuspendReserves SuspendAll ModReserveMinusPriority AlterPriority CanItemBeReserved CheckReserves MoveReserve );
19
    qw( AddReserve CalculatePriority ModReserve AutoUnsuspendReserves SuspendAll ModReserveMinusPriority AlterPriority CanItemBeReserved CheckReserves MoveReserve );
(-)a/t/db_dependent/Holds/WaitingReserves.t (-28 / +16 lines)
Lines 17-24 my $schema = Koha::Database->new->schema; Link Here
17
$schema->storage->txn_begin;
17
$schema->storage->txn_begin;
18
18
19
my $dbh = C4::Context->dbh;
19
my $dbh = C4::Context->dbh;
20
$dbh->do(q{DELETE FROM special_holidays});
20
$dbh->do(q{DELETE FROM discrete_calendar});
21
$dbh->do(q{DELETE FROM repeatable_holidays});
22
$dbh->do("DELETE FROM reserves");
21
$dbh->do("DELETE FROM reserves");
23
22
24
my $builder = t::lib::TestBuilder->new();
23
my $builder = t::lib::TestBuilder->new();
Lines 41-46 $builder->build( Link Here
41
    }
40
    }
42
);
41
);
43
42
43
$builder->fill_discrete_calendar({ branchcode => 'LIB1' });
44
my $calendar = Koha::DiscreteCalendar->new({ branchcode => 'LIB1' });
45
44
$builder->build(
46
$builder->build(
45
    {
47
    {
46
        source => 'Branch',
48
        source => 'Branch',
Lines 170-205 my $reserve3 = $builder->build( Link Here
170
my $special_holiday1_dt = $today->clone;
172
my $special_holiday1_dt = $today->clone;
171
$special_holiday1_dt->add( days => 2 );
173
$special_holiday1_dt->add( days => 2 );
172
174
173
my $holiday = $builder->build(
175
$calendar->edit_holiday({
174
    {
176
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
175
        source => 'SpecialHoliday',
177
    start_date   => $special_holiday1_dt,
176
        value  => {
178
    end_date     => $special_holiday1_dt,
177
            branchcode  => 'LIB1',
179
    title        => 'My special holiday',
178
            day         => $special_holiday1_dt->day,
180
});
179
            month       => $special_holiday1_dt->month,
180
            year        => $special_holiday1_dt->year,
181
            title       => 'My special holiday',
182
            isexception => 0
183
        },
184
    }
185
);
186
181
187
my $special_holiday2_dt = $today->clone;
182
my $special_holiday2_dt = $today->clone;
188
$special_holiday2_dt->add( days => 4 );
183
$special_holiday2_dt->add( days => 4 );
189
184
190
my $holiday2 = $builder->build(
185
$calendar->edit_holiday({
191
    {
186
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
192
        source => 'SpecialHoliday',
187
    start_date   => $special_holiday2_dt,
193
        value  => {
188
    end_date     => $special_holiday2_dt,
194
            branchcode  => 'LIB1',
189
    title        => 'My special holiday 2',
195
            day         => $special_holiday2_dt->day,
190
});
196
            month       => $special_holiday2_dt->month,
197
            year        => $special_holiday2_dt->year,
198
            title       => 'My special holiday 2',
199
            isexception => 0
200
        },
201
    }
202
);
203
191
204
Koha::Caches->get_instance->flush_all;
192
Koha::Caches->get_instance->flush_all;
205
193
(-)a/t/db_dependent/HoldsQueue.t (-9 / +10 lines)
Lines 12-18 use Test::NoWarnings; Link Here
12
use Test::More tests => 65;
12
use Test::More tests => 65;
13
use Data::Dumper;
13
use Data::Dumper;
14
14
15
use C4::Calendar;
15
use Koha::DiscreteCalendar;
16
use C4::Context;
16
use C4::Context;
17
use C4::Members;
17
use C4::Members;
18
use C4::Circulation qw( AddIssue AddReturn );
18
use C4::Circulation qw( AddIssue AddReturn );
Lines 392-409 is( Link Here
392
# have 1 row in the holds queue
392
# have 1 row in the holds queue
393
t::lib::Mocks::mock_preference( 'HoldsQueueSkipClosed', 1 );
393
t::lib::Mocks::mock_preference( 'HoldsQueueSkipClosed', 1 );
394
my $today = dt_from_string();
394
my $today = dt_from_string();
395
C4::Calendar->new( branchcode => $branchcodes[0] )->insert_single_holiday(
395
my $calendar = Koha::DiscreteCalendar->new({ branchcode => $branchcodes[0] });
396
    day         => $today->day(),
396
$calendar->edit_holiday({
397
    month       => $today->month(),
397
    holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
398
    year        => $today->year(),
398
    start_date   => $today,
399
    title       => "$today",
399
    end_date     => $today,
400
    description => "$today",
400
    title        => "$today",
401
);
401
    description  => "$today",
402
});
402
403
403
# If the test below is removed, another tests using the holiday will fail. For some reason if we call is_holiday now
404
# If the test below is removed, another tests using the holiday will fail. For some reason if we call is_holiday now
404
# the holiday will get set in cache correctly, but not if we let C4::HoldsQueue call is_holiday instead.
405
# the holiday will get set in cache correctly, but not if we let C4::HoldsQueue call is_holiday instead.
405
is(
406
is(
406
    Koha::Calendar->new( branchcode => $branchcodes[0] )->is_holiday($today), 1,
407
    $calendar->is_holiday($today), 1,
407
    'Is today a holiday for pickup branch'
408
    'Is today a holiday for pickup branch'
408
);
409
);
409
C4::HoldsQueue::CreateQueue();
410
C4::HoldsQueue::CreateQueue();
(-)a/t/db_dependent/Koha/Charges/Fees.t (-19 / +32 lines)
Lines 29-35 use t::lib::TestBuilder; Link Here
29
use t::lib::Dates;
29
use t::lib::Dates;
30
30
31
use Time::Fake;
31
use Time::Fake;
32
use C4::Calendar;
32
use Koha::DiscreteCalendar;
33
use Koha::DateUtils qw(dt_from_string);
33
use Koha::DateUtils qw(dt_from_string);
34
34
35
BEGIN {
35
BEGIN {
Lines 363-389 subtest 'accumulate_rentalcharge tests' => sub { Link Here
363
    );
363
    );
364
    $itemtype->rentalcharge_daily_calendar(1)->store();
364
    $itemtype->rentalcharge_daily_calendar(1)->store();
365
365
366
    my $calendar = C4::Calendar->new( branchcode => $library->id );
366
    my $calendar = Koha::DiscreteCalendar->new({ branchcode => $library->id });
367
367
368
    # DateTime 1..7 (Mon..Sun), C4::Calendar 0..6 (Sun..Sat)
368
    # DateTime 1..7 (Mon..Sun), Koha::DiscreteCalendar 1..7 (Sun..Sat)
369
    my $closed_day =
369
    my $closed_day =
370
          ( $dt_from->day_of_week == 6 ) ? 0
370
        ( $dt_from->day_of_week == 7 ) ? 1
371
        : ( $dt_from->day_of_week == 7 ) ? 1
371
      : $dt_from->day_of_week + 1;
372
        :                                  $dt_from->day_of_week + 1;
372
    $calendar->edit_holiday({
373
    $calendar->insert_week_day_holiday(
373
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
374
        weekday     => $closed_day,
374
        weekday      => $closed_day,
375
        title       => 'Test holiday',
375
        override     => 1,
376
        description => 'Test holiday'
376
        start_date   => $dt_from,
377
    );
377
        end_date     => $dt_from,
378
        title        => 'Test holiday',
379
        description  => 'Test holiday'
380
    });
378
    $charge = $fees->accumulate_rentalcharge();
381
    $charge = $fees->accumulate_rentalcharge();
379
    my $day_names = {
382
    my $day_names = {
380
        0 => 'Sunday',
383
        1 => 'Sunday',
381
        1 => 'Monday',
384
        2 => 'Monday',
382
        2 => 'Tuesday',
385
        3 => 'Tuesday',
383
        3 => 'Wednesday',
386
        4 => 'Wednesday',
384
        4 => 'Thursday',
387
        5 => 'Thursday',
385
        5 => 'Friday',
388
        6 => 'Friday',
386
        6 => 'Saturday'
389
        7 => 'Saturday'
387
    };
390
    };
388
    my $dayname = $day_names->{$closed_day};
391
    my $dayname = $day_names->{$closed_day};
389
    is(
392
    is(
Lines 437-443 subtest 'accumulate_rentalcharge tests' => sub { Link Here
437
    );
440
    );
438
441
439
    $itemtype->rentalcharge_hourly_calendar(1)->store();
442
    $itemtype->rentalcharge_hourly_calendar(1)->store();
440
    $calendar->delete_holiday( weekday => $closed_day );
443
    $calendar->edit_holiday({
444
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
445
        weekday      => $closed_day,
446
        override     => 1,
447
        today        => $dt_from,           # To override past date when deleting holiday type
448
        delete_type  => 1,
449
        start_date   => $dt_from,
450
        end_date     => $dt_from,
451
        title        => '',
452
        description  => '',
453
    });
441
    $charge = $fees->accumulate_rentalcharge();
454
    $charge = $fees->accumulate_rentalcharge();
442
    is(
455
    is(
443
        $charge, 24.00,
456
        $charge, 24.00,
(-)a/t/db_dependent/Koha/CurbsidePickups.t (-7 / +17 lines)
Lines 21-30 use Test::NoWarnings; Link Here
21
use Test::More tests => 5;
21
use Test::More tests => 5;
22
use Test::Exception;
22
use Test::Exception;
23
23
24
use C4::Calendar;
25
use Koha::CurbsidePickups;
24
use Koha::CurbsidePickups;
26
use Koha::CurbsidePickupPolicies;
25
use Koha::CurbsidePickupPolicies;
27
use Koha::Calendar;
26
use Koha::DiscreteCalendar;
28
use Koha::Database;
27
use Koha::Database;
29
use Koha::DateUtils qw( dt_from_string );
28
use Koha::DateUtils qw( dt_from_string );
30
29
Lines 152-170 subtest 'Create a pickup' => sub { Link Here
152
151
153
    # Day is a holiday
152
    # Day is a holiday
154
    Koha::Caches->get_instance->flush_all;
153
    Koha::Caches->get_instance->flush_all;
155
    C4::Calendar->new( branchcode => $library->branchcode )->insert_week_day_holiday(
154
    my $calendar = Koha::DiscreteCalendar->new({ branchcode => $library->branchcode });
156
        weekday     => 1,
155
    $calendar->edit_holiday({
156
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{WEEKLY},
157
        weekday      => 2,
158
        start_date   => $schedule_dt,
159
        end_date     => $schedule_dt,
157
        title       => '',
160
        title       => '',
158
        description => 'Mondays',
161
        description => 'Mondays',
159
    );
162
    });
160
    my $calendar = Koha::Calendar->new( branchcode => $library->branchcode );
161
    throws_ok {
163
    throws_ok {
162
        Koha::CurbsidePickup->new( { %$params, scheduled_pickup_datetime => $schedule_dt } )->store;
164
        Koha::CurbsidePickup->new( { %$params, scheduled_pickup_datetime => $schedule_dt } )->store;
163
    }
165
    }
164
    'Koha::Exceptions::CurbsidePickup::LibraryIsClosed',
166
    'Koha::Exceptions::CurbsidePickup::LibraryIsClosed',
165
        'Cannot create a pickup on a holiday';
167
        'Cannot create a pickup on a holiday';
166
168
167
    C4::Context->dbh->do(q{DELETE FROM repeatable_holidays});
169
    $calendar->edit_holiday({
170
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{NONE},
171
        weekday      => 2,
172
        delete_type  => 1,
173
        start_date   => $schedule_dt,
174
        end_date     => $schedule_dt,
175
        description  => '',
176
    });
177
168
    Koha::Caches->get_instance->flush_all;
178
    Koha::Caches->get_instance->flush_all;
169
};
179
};
170
180
(-)a/t/db_dependent/Koha/ItemTypes.t (-1 lines)
Lines 25-31 use Test::More tests => 19; Link Here
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
27
27
28
use C4::Calendar;
29
use Koha::Biblioitems;
28
use Koha::Biblioitems;
30
use Koha::Libraries;
29
use Koha::Libraries;
31
use Koha::Database;
30
use Koha::Database;
(-)a/t/db_dependent/Reserves/CancelExpiredReserves.t (-13 / +7 lines)
Lines 91-109 subtest 'CancelExpiredReserves tests incl. holidays' => sub { Link Here
91
    );
91
    );
92
92
93
    Koha::Caches->get_instance()->flush_all();
93
    Koha::Caches->get_instance()->flush_all();
94
    my $holiday = $builder->build(
94
    $builder->fill_discrete_calendar({ branchcode => 'LIB1 '});
95
        {
95
    my $calendar = Koha::DiscreteCalendar->new({ branchcode => 'LIB1' })->edit_holiday({
96
            source => 'SpecialHoliday',
96
        holiday_type => $Koha::DiscreteCalendar::HOLIDAYS->{EXCEPTION},
97
            value  => {
97
        start_date   => $today,
98
                branchcode  => 'LIB1',
98
        end_date     => $today,
99
                day         => $today->day,
99
        title        => 'My holiday',
100
                month       => $today->month,
100
    });
101
                year        => $today->year,
102
                title       => 'My holiday',
103
                isexception => 0
104
            },
105
        }
106
    );
107
101
108
    CancelExpiredReserves();
102
    CancelExpiredReserves();
109
    my $r3 = Koha::Holds->find( $reserve3->{reserve_id} );
103
    my $r3 = Koha::Holds->find( $reserve3->{reserve_id} );
(-)a/t/lib/TestBuilder.pm (-2 / +31 lines)
Lines 6-12 use Koha::Database; Link Here
6
use C4::Biblio qw( AddBiblio );
6
use C4::Biblio qw( AddBiblio );
7
use Koha::Biblios;
7
use Koha::Biblios;
8
use Koha::Items;
8
use Koha::Items;
9
use Koha::DateUtils qw( dt_from_string );
9
use Koha::DateUtils qw( dt_from_string output_pref );
10
10
11
use Bytes::Random::Secure;
11
use Bytes::Random::Secure;
12
use Carp         qw( carp );
12
use Carp         qw( carp );
Lines 152-157 sub build { Link Here
152
            if scalar @{ $fk->{keys} } == 1;
152
            if scalar @{ $fk->{keys} } == 1;
153
    }
153
    }
154
154
155
    if ($source eq 'Branch') {
156
        $self->fill_discrete_calendar({ branchcode => $col_values->{branchcode} });
157
    }
158
155
    # store this record and return hashref
159
    # store this record and return hashref
156
    return $self->_storeColumnValues(
160
    return $self->_storeColumnValues(
157
        {
161
        {
Lines 230-235 sub build_sample_ill_request { Link Here
230
    )->store->get_from_storage;
234
    )->store->get_from_storage;
231
}
235
}
232
236
237
sub fill_discrete_calendar {
238
    my ( $self, $args ) = @_;
239
240
    my $branchcode = $args->{branchcode} || '';
241
    my $start_date = ($args->{start_date}) ? dt_from_string($args->{start_date}) : DateTime->today();
242
    my $days = $args->{days} || 60;
243
244
    my $end_date = $start_date->clone();
245
    $start_date->add(days => 0 - $days);
246
    $end_date->add(days => $days);
247
248
    for (1; $start_date <= $end_date; $start_date->add(days => 1)) {
249
        my $data = {
250
            date       => output_pref( { dt => $start_date, dateformat => 'iso', dateonly => 1 }),
251
            branchcode => $branchcode,
252
            is_opened  => 1,
253
            open_hour  => "08:00:00",
254
            close_hour => "17:00:00",
255
        };
256
257
        $self->schema->resultset( "DiscreteCalendar" )->update_or_create( $data );
258
    }
259
260
    return
261
}
262
233
# ------------------------------------------------------------------------------
263
# ------------------------------------------------------------------------------
234
# Internal helper routines
264
# Internal helper routines
235
265
236
- 

Return to bug 17015