From 99e7f928b1bdd7ca997c6ae403a691f90866eeb4 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 10 Aug 2016 09:07:26 +0100 Subject: [PATCH] Bug 17249: Remove GetKohaAuthorisedValuesFromField - Add classes MarcSubfieldStructure[s] This patch adds the 2 Koha::Object based classes for the marc_subfield_structure table Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Mason James --- Koha/MarcSubfieldStructure.pm | 44 +++++++++++++++ Koha/MarcSubfieldStructures.pm | 50 +++++++++++++++++ t/db_dependent/Koha/MarcSubfieldStructures.t | 57 ++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 Koha/MarcSubfieldStructure.pm create mode 100644 Koha/MarcSubfieldStructures.pm create mode 100644 t/db_dependent/Koha/MarcSubfieldStructures.t diff --git a/Koha/MarcSubfieldStructure.pm b/Koha/MarcSubfieldStructure.pm new file mode 100644 index 0000000000..f55da048e8 --- /dev/null +++ b/Koha/MarcSubfieldStructure.pm @@ -0,0 +1,44 @@ +package Koha::MarcSubfieldStructure; + +# 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 Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::MarcSubfieldStructure - Koha MarcSubfieldStructure Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'MarcSubfieldStructure'; +} + +1; diff --git a/Koha/MarcSubfieldStructures.pm b/Koha/MarcSubfieldStructures.pm new file mode 100644 index 0000000000..c2f565630e --- /dev/null +++ b/Koha/MarcSubfieldStructures.pm @@ -0,0 +1,50 @@ +package Koha::MarcSubfieldStructures; + +# 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 Carp; + +use Koha::Database; + +use Koha::MarcSubfieldStructure; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::MarcSubfieldStructures - Koha MarcSubfieldStructure Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub _type { + return 'MarcSubfieldStructure'; +} + +sub object_class { + return 'Koha::MarcSubfieldStructure'; +} + +1; diff --git a/t/db_dependent/Koha/MarcSubfieldStructures.t b/t/db_dependent/Koha/MarcSubfieldStructures.t new file mode 100644 index 0000000000..b61837a615 --- /dev/null +++ b/t/db_dependent/Koha/MarcSubfieldStructures.t @@ -0,0 +1,57 @@ +#!/usr/bin/perl + +# Copyright 2016 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 => 3; + +use Koha::MarcSubfieldStructure; +use Koha::MarcSubfieldStructures; +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_fields = Koha::MarcSubfieldStructures->search->count; +my $framework = $builder->build({ source => 'BiblioFramework' }); +my $new_field_1 = Koha::MarcSubfieldStructure->new({ + frameworkcode => $framework->{frameworkcode}, + tagfield => 200, + tagsubfield => 'a', +})->store; +my $new_field_2 = Koha::MarcSubfieldStructure->new({ + frameworkcode => $framework->{frameworkcode}, + tagfield => 245, + tagsubfield => 'a', +})->store; + +is( Koha::MarcSubfieldStructures->search->count, $nb_of_fields + 2, 'The 2 fields should have been added' ); + +my $retrieved_fields = Koha::MarcSubfieldStructures->search({ frameworkcode => $framework->{frameworkcode}, tagfield => 200, tagsubfield => 'a' }); +is( $retrieved_fields->count, 1, 'Search for a field by frameworkcode, tagfield and tagsubfield should return the field' ); + +$retrieved_fields->next->delete; +is( Koha::MarcSubfieldStructures->search->count, $nb_of_fields + 1, 'Delete should have deleted the field' ); + +$schema->storage->txn_rollback; + +1; -- 2.39.5