From 02c36ab7ba6d858732ac7fd31cf5732b8e9e9739 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 28 May 2018 13:05:53 +0200 Subject: [PATCH] Bug 20819: Add Koha object classes for patron consents Content-Type: text/plain; charset=utf-8 Introduces Koha::Patron::Consent[s] for new table. Adds basic CRUD test. Test plan: Run t/db_dependent/Koha/Patron/Consents.t Signed-off-by: Marcel de Rooy --- Koha/Patron/Consent.pm | 44 ++++++++++++++++++++++++++++ Koha/Patron/Consents.pm | 55 +++++++++++++++++++++++++++++++++++ t/db_dependent/Koha/Patron/Consents.t | 48 ++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 Koha/Patron/Consent.pm create mode 100644 Koha/Patron/Consents.pm create mode 100644 t/db_dependent/Koha/Patron/Consents.t diff --git a/Koha/Patron/Consent.pm b/Koha/Patron/Consent.pm new file mode 100644 index 0000000..fb731bd --- /dev/null +++ b/Koha/Patron/Consent.pm @@ -0,0 +1,44 @@ +package Koha::Patron::Consent; + +# Copyright 2018 Rijksmuseum +# +# 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 base qw(Koha::Object); + +=head1 NAME + +Koha::Patron::Consent + +=head1 DESCRIPTION + +Koha::Object class for handling patron consents + +=head1 API + +=head2 Class Methods + +=head3 _type + +=cut + +sub _type { + return 'PatronConsent'; +} + +1; diff --git a/Koha/Patron/Consents.pm b/Koha/Patron/Consents.pm new file mode 100644 index 0000000..e169177 --- /dev/null +++ b/Koha/Patron/Consents.pm @@ -0,0 +1,55 @@ +package Koha::Patron::Consents; + +# Copyright 2018 Rijksmuseum +# +# 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 base qw(Koha::Objects); +use Koha::Patron::Consent; + +=head1 NAME + +Koha::Patron::Consents + +=head1 DESCRIPTION + +Koha::Objects class for handling patron consents + +=head1 API + +=head2 Class Methods + +=cut + +=head3 _type + +=cut + +sub _type { + return 'PatronConsent'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Patron::Consent'; +} + +1; diff --git a/t/db_dependent/Koha/Patron/Consents.t b/t/db_dependent/Koha/Patron/Consents.t new file mode 100644 index 0000000..ab9ed66 --- /dev/null +++ b/t/db_dependent/Koha/Patron/Consents.t @@ -0,0 +1,48 @@ +#!/usr/bin/perl + +# Copyright 2018 Rijksmuseum +# +# 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 => 1; + +use t::lib::TestBuilder; + +use Koha::Database; +use Koha::DateUtils qw/dt_from_string/; +use Koha::Patron::Consents; + +our $builder = t::lib::TestBuilder->new; +our $schema = Koha::Database->new->schema; + +subtest 'Basic tests for Koha::Patron::Consent' => sub { + plan tests => 2; + $schema->storage->txn_begin; + + my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); + my $consent1 = Koha::Patron::Consent->new({ + borrowernumber => $patron1->borrowernumber, + type => 'GDPR_PROCESSING', + given_on => dt_from_string, + })->store; + is( Koha::Patron::Consents->search({ borrowernumber => $patron1->borrowernumber })->count, 1, 'One consent for new borrower' ); + $consent1->delete; + is( Koha::Patron::Consents->search({ borrowernumber => $patron1->borrowernumber })->count, 0, 'No consents left for new borrower' ); + + $schema->storage->txn_rollback; +}; -- 2.1.4