Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# Copyright 2015 Koha Development team |
4 |
# Copyright 2020 BULAC |
5 |
# |
6 |
# This file is part of Koha |
7 |
# |
8 |
# Koha is free software; you can redistribute it and/or modify it |
9 |
# under the terms of the GNU General Public License as published by |
10 |
# the Free Software Foundation; either version 3 of the License, or |
11 |
# (at your option) any later version. |
12 |
# |
13 |
# Koha is distributed in the hope that it will be useful, but |
14 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
# GNU General Public License for more details. |
17 |
# |
18 |
# You should have received a copy of the GNU General Public License |
19 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
20 |
|
21 |
use Modern::Perl; |
22 |
|
23 |
use Test::More tests => 4; |
24 |
|
25 |
use Koha::Holidays::RepeatingHolidays; |
26 |
use Koha::Database; |
27 |
use Koha::Libraries; |
28 |
|
29 |
use t::lib::TestBuilder; |
30 |
|
31 |
my $schema = Koha::Database->new->schema; |
32 |
$schema->storage->txn_begin; |
33 |
|
34 |
my $builder = t::lib::TestBuilder->new; |
35 |
|
36 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
37 |
|
38 |
my $nb_of_holidays = Koha::Holidays::RepeatingHolidays->search->count; |
39 |
my $new_holiday_1 = Koha::Holidays::RepeatingHoliday->new( |
40 |
{ |
41 |
branchcode => $library->branchcode, |
42 |
weekday => undef, |
43 |
day => 25, |
44 |
month => 12, |
45 |
title => "Christmas", |
46 |
description => "Holiday" |
47 |
} |
48 |
)->store; |
49 |
|
50 |
my $new_holiday_2 = Koha::Holidays::RepeatingHoliday->new( |
51 |
{ |
52 |
branchcode => $library->branchcode, |
53 |
weekday => 1, |
54 |
day => undef, |
55 |
month => undef, |
56 |
title => "Monday", |
57 |
description => "Closed day" |
58 |
} |
59 |
)->store; |
60 |
|
61 |
like( $new_holiday_1->id, qr|^\d+$|, 'Adding a new holiday should have set the id' ); |
62 |
is( Koha::Holidays::RepeatingHolidays->search->count, $nb_of_holidays + 2, 'The 2 holidays should have been added' ); |
63 |
|
64 |
my $retrieved_holiday_1 = Koha::Holidays::RepeatingHolidays->find( $new_holiday_1->id ); |
65 |
is( $retrieved_holiday_1->title, $new_holiday_1->title, 'Find a holiday by id should return the correct holiday' ); |
66 |
|
67 |
$retrieved_holiday_1->delete; |
68 |
is( Koha::Holidays::RepeatingHolidays->search->count, $nb_of_holidays + 1, 'Delete should have deleted the holiday' ); |
69 |
|
70 |
$schema->storage->txn_rollback; |