From 9b57dd2557bb318e2c27758ee9236d275ccaabb9 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Fri, 21 Oct 2016 17:26:24 +0300 Subject: [PATCH] Bug 17499: Add Koha-objects for messaging preferences This patch adds Koha-objects for messaging preferences. This patch does not add any extra logic into these objects. Includes test coverage for basic usage. To test: 1. Run t/db_dependent/Koha/Patron/Message/Preferences.t --- Koha/Patron/Message/Attribute.pm | 50 +++++++++ Koha/Patron/Message/Attributes.pm | 55 ++++++++++ Koha/Patron/Message/Preference.pm | 50 +++++++++ Koha/Patron/Message/Preferences.pm | 55 ++++++++++ Koha/Patron/Message/Transport.pm | 50 +++++++++ Koha/Patron/Message/Transport/Preference.pm | 51 +++++++++ Koha/Patron/Message/Transport/Preferences.pm | 56 ++++++++++ Koha/Patron/Message/Transport/Type.pm | 51 +++++++++ Koha/Patron/Message/Transport/Types.pm | 56 ++++++++++ Koha/Patron/Message/Transports.pm | 55 ++++++++++ t/db_dependent/Koha/Patron/Message/Preferences.t | 125 +++++++++++++++++++++++ 11 files changed, 654 insertions(+) create mode 100644 Koha/Patron/Message/Attribute.pm create mode 100644 Koha/Patron/Message/Attributes.pm create mode 100644 Koha/Patron/Message/Preference.pm create mode 100644 Koha/Patron/Message/Preferences.pm create mode 100644 Koha/Patron/Message/Transport.pm create mode 100644 Koha/Patron/Message/Transport/Preference.pm create mode 100644 Koha/Patron/Message/Transport/Preferences.pm create mode 100644 Koha/Patron/Message/Transport/Type.pm create mode 100644 Koha/Patron/Message/Transport/Types.pm create mode 100644 Koha/Patron/Message/Transports.pm create mode 100644 t/db_dependent/Koha/Patron/Message/Preferences.t diff --git a/Koha/Patron/Message/Attribute.pm b/Koha/Patron/Message/Attribute.pm new file mode 100644 index 0000000..9d9004c --- /dev/null +++ b/Koha/Patron/Message/Attribute.pm @@ -0,0 +1,50 @@ +package Koha::Patron::Message::Attribute; + +# Copyright Koha-Suomi Oy 2016 +# +# 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.a +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Patron::Message::Attribute - Koha Patron Message Attribute object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'MessageAttribute'; +} + +=head1 AUTHOR + +Lari Taskula + +=cut + +1; diff --git a/Koha/Patron/Message/Attributes.pm b/Koha/Patron/Message/Attributes.pm new file mode 100644 index 0000000..a2df4e6 --- /dev/null +++ b/Koha/Patron/Message/Attributes.pm @@ -0,0 +1,55 @@ +package Koha::Patron::Message::Attributes; + +# Copyright Koha-Suomi Oy 2016 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; +use Koha::Patron::Message::Attribute; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Patron::Message::Attributes - Koha Patron Message Attributes object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'MessageAttribute'; +} + +sub object_class { + return 'Koha::Patron::Message::Attribute'; +} + +=head1 AUTHOR + +Lari Taskula + +=cut + +1; diff --git a/Koha/Patron/Message/Preference.pm b/Koha/Patron/Message/Preference.pm new file mode 100644 index 0000000..daeae5c --- /dev/null +++ b/Koha/Patron/Message/Preference.pm @@ -0,0 +1,50 @@ +package Koha::Patron::Message::Preference; + +# Copyright Koha-Suomi Oy 2016 +# +# 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.a +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Patron::Message::Preference - Koha Patron Message Preference object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'BorrowerMessagePreference'; +} + +=head1 AUTHOR + +Lari Taskula + +=cut + +1; diff --git a/Koha/Patron/Message/Preferences.pm b/Koha/Patron/Message/Preferences.pm new file mode 100644 index 0000000..4639a6b --- /dev/null +++ b/Koha/Patron/Message/Preferences.pm @@ -0,0 +1,55 @@ +package Koha::Patron::Message::Preferences; + +# Copyright Koha-Suomi Oy 2016 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; +use Koha::Patron::Message::Preference; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Patron::Message::Preferences - Koha Patron Message Preferences object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'BorrowerMessagePreference'; +} + +sub object_class { + return 'Koha::Patron::Message::Preference'; +} + +=head1 AUTHOR + +Lari Taskula + +=cut + +1; diff --git a/Koha/Patron/Message/Transport.pm b/Koha/Patron/Message/Transport.pm new file mode 100644 index 0000000..ca0906e --- /dev/null +++ b/Koha/Patron/Message/Transport.pm @@ -0,0 +1,50 @@ +package Koha::Patron::Message::Transport; + +# Copyright Koha-Suomi Oy 2016 +# +# 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.a +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Patron::Message::Transport - Koha Patron Message Transport object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'MessageTransport'; +} + +=head1 AUTHOR + +Lari Taskula + +=cut + +1; diff --git a/Koha/Patron/Message/Transport/Preference.pm b/Koha/Patron/Message/Transport/Preference.pm new file mode 100644 index 0000000..fe0ddeb --- /dev/null +++ b/Koha/Patron/Message/Transport/Preference.pm @@ -0,0 +1,51 @@ +package Koha::Patron::Message::Transport::Preference; + +# Copyright Koha-Suomi Oy 2016 +# +# 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.a +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Patron::Message::Transport::Preference - Koha Patron Message Transport +Preference object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'BorrowerMessageTransportPreference'; +} + +=head1 AUTHOR + +Lari Taskula + +=cut + +1; diff --git a/Koha/Patron/Message/Transport/Preferences.pm b/Koha/Patron/Message/Transport/Preferences.pm new file mode 100644 index 0000000..aabd851 --- /dev/null +++ b/Koha/Patron/Message/Transport/Preferences.pm @@ -0,0 +1,56 @@ +package Koha::Patron::Message::Transport::Preferences; + +# Copyright Koha-Suomi Oy 2016 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; +use Koha::Patron::Message::Transport::Preference; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Patron::Message::Transport::Preferences - Koha Patron Message Transport +Preferences object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'BorrowerMessageTransportPreference'; +} + +sub object_class { + return 'Koha::Patron::Message::Transport::Preference'; +} + +=head1 AUTHOR + +Lari Taskula + +=cut + +1; diff --git a/Koha/Patron/Message/Transport/Type.pm b/Koha/Patron/Message/Transport/Type.pm new file mode 100644 index 0000000..4a52a10 --- /dev/null +++ b/Koha/Patron/Message/Transport/Type.pm @@ -0,0 +1,51 @@ +package Koha::Patron::Message::Transport::Type; + +# Copyright Koha-Suomi Oy 2016 +# +# 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.a +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Patron::Message::Transport::Type - Koha Patron Message Transport Type +object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'MessageTransportType'; +} + +=head1 AUTHOR + +Lari Taskula + +=cut + +1; diff --git a/Koha/Patron/Message/Transport/Types.pm b/Koha/Patron/Message/Transport/Types.pm new file mode 100644 index 0000000..2633ea3 --- /dev/null +++ b/Koha/Patron/Message/Transport/Types.pm @@ -0,0 +1,56 @@ +package Koha::Patron::Message::Transport::Types; + +# Copyright Koha-Suomi Oy 2016 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; +use Koha::Patron::Message::Transport::Type; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Patron::Message::Transport::Types - Koha Patron Message Transport Types +object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'MessageTransportType'; +} + +sub object_class { + return 'Koha::Patron::Message::Transport::Type'; +} + +=head1 AUTHOR + +Lari Taskula + +=cut + +1; diff --git a/Koha/Patron/Message/Transports.pm b/Koha/Patron/Message/Transports.pm new file mode 100644 index 0000000..b6aee32 --- /dev/null +++ b/Koha/Patron/Message/Transports.pm @@ -0,0 +1,55 @@ +package Koha::Patron::Message::Transports; + +# Copyright Koha-Suomi Oy 2016 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::Database; +use Koha::Patron::Message::Transport; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Patron::Message::Transports - Koha Patron Message Transports object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'MessageTransport'; +} + +sub object_class { + return 'Koha::Patron::Message::Transport'; +} + +=head1 AUTHOR + +Lari Taskula + +=cut + +1; diff --git a/t/db_dependent/Koha/Patron/Message/Preferences.t b/t/db_dependent/Koha/Patron/Message/Preferences.t new file mode 100644 index 0000000..3d87943 --- /dev/null +++ b/t/db_dependent/Koha/Patron/Message/Preferences.t @@ -0,0 +1,125 @@ +#!/usr/bin/perl + +# Copyright 2016 Koha-Suomi Oy +# +# 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 => 15; + +use t::lib::Mocks; +use t::lib::TestBuilder; + +use Koha::Patrons; + +use_ok("Koha::Patron::Message::Attribute"); +use_ok("Koha::Patron::Message::Attributes"); +use_ok("Koha::Patron::Message::Preference"); +use_ok("Koha::Patron::Message::Preferences"); +use_ok("Koha::Patron::Message::Transport"); +use_ok("Koha::Patron::Message::Transport::Preference"); +use_ok("Koha::Patron::Message::Transport::Preferences"); +use_ok("Koha::Patron::Message::Transport::Type"); +use_ok("Koha::Patron::Message::Transport::Types"); +use_ok("Koha::Patron::Message::Transports"); + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; +my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode(); +my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode(); + +my $patron = $builder->build({ source => 'Borrower', + value => { + branchcode => $branchcode, + categorycode => $categorycode, + } +}); + +my $attribute; +my $preference; +my $transport_preference; +my $transport_type; + +subtest 'Add a test messaging transport type' => sub { + plan tests => 2; + + ok($transport_type = Koha::Patron::Message::Transport::Type->new({ + message_transport_type => "test" + })->store, "Added a new messaging transport type."); + is(Koha::Patron::Message::Transport::Types->find({ + message_transport_type => "test" })->message_transport_type, + "test" , "Found test messaging transport type from database."); +}; + +subtest 'Add a test messaging attribute' => sub { + plan tests => 2; + + ok($attribute = Koha::Patron::Message::Attribute->new({ + message_name => "Test_Attribute" + })->store, "Added a new messaging attribute."); + is(Koha::Patron::Message::Attributes->find({ + message_name => "Test_Attribute"})->message_name, + "Test_Attribute", "Found test attribute from database."); +}; + +subtest 'Add a test messaging transport' => sub { + plan tests => 2; + + ok(Koha::Patron::Message::Transport->new({ + message_attribute_id => $attribute->message_attribute_id, + message_transport_type => $transport_type->message_transport_type, + is_digest => 0, + letter_module => "circulation", + letter_code => "CHECKIN", + })->store, "Added a new messaging transport type."); + is(Koha::Patron::Message::Transports->find({ + message_transport_type => "test" })->message_attribute_id, + $attribute->message_attribute_id , "Found test messaging transport from database."); +}; + +subtest 'Add a messaging preference to patron' => sub { + plan tests => 2; + + ok($preference = Koha::Patron::Message::Preference->new({ + borrowernumber => $patron->{'borrowernumber'}, + message_attribute_id => $attribute->message_attribute_id, + wants_digest => 0, + days_in_advance => 1, + })->store, "Added a new messaging preference for patron."); + is(Koha::Patron::Message::Preferences->find({ + borrowernumber => $patron->{'borrowernumber'} })->message_attribute_id, + $preference->message_attribute_id, "Found test messaging preference from database."); +}; + +subtest 'Add a messaging transport preference to patron' => sub { + plan tests => 2; + + ok($transport_preference = Koha::Patron::Message::Transport::Preference->new({ + borrower_message_preference_id => $preference->borrower_message_preference_id, + message_transport_type => $transport_type->message_transport_type, + })->store, "Added a new messaging transport preference for patron."); + is(Koha::Patron::Message::Transport::Preferences->find({ + message_transport_type => $transport_type->message_transport_type + })->borrower_message_preference_id, $transport_preference->borrower_message_preference_id, + "Found test messaging transport preference from database."); +}; + +$schema->storage->txn_rollback; + +1; -- 2.7.4