Bug 20819: Add Koha object classes for patron consents
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Mon, 28 May 2018 11:05:53 +0000 (13:05 +0200)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 20 Sep 2018 13:45:25 +0000 (13:45 +0000)
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 <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/Patron/Consent.pm [new file with mode: 0644]
Koha/Patron/Consents.pm [new file with mode: 0644]
t/db_dependent/Koha/Patron/Consents.t [new file with mode: 0644]

diff --git a/Koha/Patron/Consent.pm b/Koha/Patron/Consent.pm
new file mode 100644 (file)
index 0000000..fb731bd
--- /dev/null
@@ -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 (file)
index 0000000..e169177
--- /dev/null
@@ -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 (file)
index 0000000..ab9ed66
--- /dev/null
@@ -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 <http://www.gnu.org/licenses>.
+
+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;
+};