From a0d75d5b088e3c4ae991b9503fc6a52d97e12979 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Sat, 24 Aug 2024 13:37:48 +0000 Subject: [PATCH] Bug 37722: Add KOha Objects for Koha Holidays These patches add objects for special and repeating holidays To test: prove -v t/db_dependent/Koha/Holidays/ --- Koha/Holidays/RepeatingHoliday.pm | 62 ++++++++++++++++ Koha/Holidays/RepeatingHolidays.pm | 53 ++++++++++++++ Koha/Holidays/SpecialHoliday.pm | 63 ++++++++++++++++ Koha/Holidays/SpecialHolidays.pm | 53 ++++++++++++++ Koha/Schema/Result/RepeatableHoliday.pm | 7 +- Koha/Schema/Result/SpecialHoliday.pm | 7 +- .../Koha/Holidays/RepeatingHolidays.t | 70 ++++++++++++++++++ .../Koha/Holidays/SpecialHolidays.t | 72 +++++++++++++++++++ 8 files changed, 385 insertions(+), 2 deletions(-) create mode 100644 Koha/Holidays/RepeatingHoliday.pm create mode 100644 Koha/Holidays/RepeatingHolidays.pm create mode 100644 Koha/Holidays/SpecialHoliday.pm create mode 100644 Koha/Holidays/SpecialHolidays.pm create mode 100755 t/db_dependent/Koha/Holidays/RepeatingHolidays.t create mode 100755 t/db_dependent/Koha/Holidays/SpecialHolidays.t diff --git a/Koha/Holidays/RepeatingHoliday.pm b/Koha/Holidays/RepeatingHoliday.pm new file mode 100644 index 00000000000..9a1dcbfc23b --- /dev/null +++ b/Koha/Holidays/RepeatingHoliday.pm @@ -0,0 +1,62 @@ +package Koha::Holidays::RepeatingHoliday; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Holidays::RepeatingHoliday - Koha Repeating Holiday Object class + +=head1 API + +=head2 Class methods + +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::RepeatingHoliday object +on the API. + +=cut + +sub to_api_mapping { + return { + id => 'holiday_id', + branchcode => 'library_id', + weekday => 'weekday', + day => 'day', + month => 'month', + title => 'title', + description => 'description', + }; +} + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'RepeatableHoliday'; +} + +1; diff --git a/Koha/Holidays/RepeatingHolidays.pm b/Koha/Holidays/RepeatingHolidays.pm new file mode 100644 index 00000000000..095e8257c76 --- /dev/null +++ b/Koha/Holidays/RepeatingHolidays.pm @@ -0,0 +1,53 @@ +package Koha::Holidays::RepeatingHolidays; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + + +use Koha::Database; + +use Koha::Holidays::RepeatingHoliday; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Holidays::RepeatingHolidays - Koha Repeating Holiday Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'RepeatableHoliday'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Holidays::RepeatingHoliday'; +} + +1; diff --git a/Koha/Holidays/SpecialHoliday.pm b/Koha/Holidays/SpecialHoliday.pm new file mode 100644 index 00000000000..e7c21d1a19a --- /dev/null +++ b/Koha/Holidays/SpecialHoliday.pm @@ -0,0 +1,63 @@ +package Koha::Holidays::SpecialHoliday; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Holidays::SpecialHoliday - Koha Special Holiday Object class + +=head1 API + +=head2 Class methods + +=head3 to_api_mapping + +This method returns the mapping for representing a Koha::SpecialHoliday object +on the API. + +=cut + +sub to_api_mapping { + return { + id => 'holiday_id', + branchcode => 'library_id', + day => 'day', + month => 'month', + year => 'year', + isexception => 'is_exception', + title => 'title', + description => 'description', + }; +} + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'SpecialHoliday'; +} + +1; diff --git a/Koha/Holidays/SpecialHolidays.pm b/Koha/Holidays/SpecialHolidays.pm new file mode 100644 index 00000000000..68a0f29728a --- /dev/null +++ b/Koha/Holidays/SpecialHolidays.pm @@ -0,0 +1,53 @@ +package Koha::Holidays::SpecialHolidays; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + + +use Koha::Database; + +use Koha::Holidays::SpecialHoliday; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Holidays::SpecialHolidays - Koha Special Holiday Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'SpecialHoliday'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Holidays::SpecialHoliday'; +} + +1; diff --git a/Koha/Schema/Result/RepeatableHoliday.pm b/Koha/Schema/Result/RepeatableHoliday.pm index 882f063bc19..c94ef1b0bcc 100644 --- a/Koha/Schema/Result/RepeatableHoliday.pm +++ b/Koha/Schema/Result/RepeatableHoliday.pm @@ -129,6 +129,11 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:OZykv+F1kgqeLvezCyhvZA +sub koha_object_class { + 'Koha::Holidays::RepeatingHoliday'; +} +sub koha_objects_class { + 'Koha::Holidays::RepeatingHolidays'; +} -# You can replace this text with custom content, and it will be preserved on regeneration 1; diff --git a/Koha/Schema/Result/SpecialHoliday.pm b/Koha/Schema/Result/SpecialHoliday.pm index a52248f53a5..49919df4fc1 100644 --- a/Koha/Schema/Result/SpecialHoliday.pm +++ b/Koha/Schema/Result/SpecialHoliday.pm @@ -142,6 +142,11 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:H3PUa5HiJKKfdndKXbmJ6A +sub koha_object_class { + 'Koha::Holidays::SpecialHoliday'; +} +sub koha_objects_class { + 'Koha::Holidays::SpecialHolidays'; +} -# You can replace this text with custom content, and it will be preserved on regeneration 1; diff --git a/t/db_dependent/Koha/Holidays/RepeatingHolidays.t b/t/db_dependent/Koha/Holidays/RepeatingHolidays.t new file mode 100755 index 00000000000..640ee932b00 --- /dev/null +++ b/t/db_dependent/Koha/Holidays/RepeatingHolidays.t @@ -0,0 +1,70 @@ +#!/usr/bin/perl + +# Copyright 2015 Koha Development team +# Copyright 2020 BULAC +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 4; + +use Koha::Holidays::RepeatingHolidays; +use Koha::Database; +use Koha::Libraries; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; + +my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + +my $nb_of_holidays = Koha::Holidays::RepeatingHolidays->search->count; +my $new_holiday_1 = Koha::Holidays::RepeatingHoliday->new( + { + branchcode => $library->branchcode, + weekday => undef, + day => 25, + month => 12, + title => "Christmas", + description => "Holiday" + } +)->store; + +my $new_holiday_2 = Koha::Holidays::RepeatingHoliday->new( + { + branchcode => $library->branchcode, + weekday => 1, + day => undef, + month => undef, + title => "Monday", + description => "Closed day" + } +)->store; + +like( $new_holiday_1->id, qr|^\d+$|, 'Adding a new holiday should have set the id' ); +is( Koha::Holidays::RepeatingHolidays->search->count, $nb_of_holidays + 2, 'The 2 holidays should have been added' ); + +my $retrieved_holiday_1 = Koha::Holidays::RepeatingHolidays->find( $new_holiday_1->id ); +is( $retrieved_holiday_1->title, $new_holiday_1->title, 'Find a holiday by id should return the correct holiday' ); + +$retrieved_holiday_1->delete; +is( Koha::Holidays::RepeatingHolidays->search->count, $nb_of_holidays + 1, 'Delete should have deleted the holiday' ); + +$schema->storage->txn_rollback; diff --git a/t/db_dependent/Koha/Holidays/SpecialHolidays.t b/t/db_dependent/Koha/Holidays/SpecialHolidays.t new file mode 100755 index 00000000000..a0a176ade8f --- /dev/null +++ b/t/db_dependent/Koha/Holidays/SpecialHolidays.t @@ -0,0 +1,72 @@ +#!/usr/bin/perl + +# Copyright 2015 Koha Development team +# Copyright 2020 BULAC +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 4; + +use Koha::Holidays::SpecialHolidays; +use Koha::Database; +use Koha::Libraries; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; + +my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + +my $nb_of_holidays = Koha::Holidays::SpecialHolidays->search->count; +my $new_holiday_1 = Koha::Holidays::SpecialHoliday->new( + { + branchcode => $library->branchcode, + day => 25, + month => 12, + year => 2020, + isexception => 0, + title => "Christmas", + description => "Holiday" + } +)->store; + +my $new_holiday_2 = Koha::Holidays::SpecialHoliday->new( + { + branchcode => $library->branchcode, + day => 1, + month => 1, + year => 2020, + isexception => 0, + title => "New Year", + description => "Holiday" + } +)->store; + +like( $new_holiday_1->id, qr|^\d+$|, 'Adding a new holiday should have set the id' ); +is( Koha::Holidays::SpecialHolidays->search->count, $nb_of_holidays + 2, 'The 2 holidays should have been added' ); + +my $retrieved_holiday_1 = Koha::Holidays::SpecialHolidays->find( $new_holiday_1->id ); +is( $retrieved_holiday_1->title, $new_holiday_1->title, 'Find a holiday by id should return the correct holiday' ); + +$retrieved_holiday_1->delete; +is( Koha::Holidays::SpecialHolidays->search->count, $nb_of_holidays + 1, 'Delete should have deleted the holiday' ); + +$schema->storage->txn_rollback; -- 2.39.2