From d7d49368c0ecbb254353857d57592feca6a589a7 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 17 Mar 2021 20:29:32 +0000 Subject: [PATCH] Bug 18138: (follow-up) Add Objects for MarcModificationTemplates --- Koha/MarcModificationTemplate.pm | 46 ++++++++++++++++ Koha/MarcModificationTemplates.pm | 54 +++++++++++++++++++ .../Koha/MarcModificationTemplates.t | 51 ++++++++++++++++++ ...BiblioMarcModificationTemplatePreference.t | 0 4 files changed, 151 insertions(+) create mode 100644 Koha/MarcModificationTemplate.pm create mode 100644 Koha/MarcModificationTemplates.pm create mode 100755 t/db_dependent/Koha/MarcModificationTemplates.t mode change 100644 => 100755 t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t diff --git a/Koha/MarcModificationTemplate.pm b/Koha/MarcModificationTemplate.pm new file mode 100644 index 0000000000..049f2c2d85 --- /dev/null +++ b/Koha/MarcModificationTemplate.pm @@ -0,0 +1,46 @@ +package Koha::MarcModificationTemplate; + +# 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 Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::MarcModificationTemplate - Koha Marc Modification Templat Object class + +=head1 API + +=head2 Class methods + +=cut + +=head2 Internal methods + +=head3 _type + +=cut + +sub _type { + return 'MarcModificationTemplate'; +} + +1; diff --git a/Koha/MarcModificationTemplates.pm b/Koha/MarcModificationTemplates.pm new file mode 100644 index 0000000000..09ed632845 --- /dev/null +++ b/Koha/MarcModificationTemplates.pm @@ -0,0 +1,54 @@ +package Koha::MarcModificationTemplates; + +# 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 Carp; + +use Koha::Database; + +use Koha::MarcModificationTemplate; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::MarcModificationTemplates - Koha Marc Modification Templates Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'MarcModificationTemplate'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::MarcModificationTemplate'; +} + +1; diff --git a/t/db_dependent/Koha/MarcModificationTemplates.t b/t/db_dependent/Koha/MarcModificationTemplates.t new file mode 100755 index 0000000000..8b1a17644a --- /dev/null +++ b/t/db_dependent/Koha/MarcModificationTemplates.t @@ -0,0 +1,51 @@ +#!/usr/bin/perl + +# Copyright 2015 Koha Development team +# +# 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::MarcModificationTemplate; +use Koha::MarcModificationTemplates; +use Koha::Database; + +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; +my $nb_of_mmts = Koha::MarcModificationTemplates->search->count; +my $new_mmt_1 = Koha::MarcModificationTemplate->new({ + name => 'my_mmt_name_for_test_1', +})->store; +my $new_mmt_2 = Koha::MarcModificationTemplate->new({ + name => 'my_mmt_name_for_test_2', +})->store; + +like( $new_mmt_1->template_id, qr|^\d+$|, 'Adding a new mmt should have set the id'); +is( Koha::MarcModificationTemplates->search->count, $nb_of_mmts + 2, 'The 2 templates should have been added' ); + +my $retrieved_mmt_1 = Koha::MarcModificationTemplates->find( $new_mmt_1->template_id ); +is( $retrieved_mmt_1->name, $new_mmt_1->name, 'Find a mmt by id should return the correct mmt' ); + +$retrieved_mmt_1->delete; +is( Koha::MarcModificationTemplates->search->count, $nb_of_mmts + 1, 'Delete should have deleted the mmt' ); + +$schema->storage->txn_rollback; diff --git a/t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t b/t/db_dependent/www/EditBiblioMarcModificationTemplatePreference.t old mode 100644 new mode 100755 -- 2.20.1