From 895c60b8d309e4afdd71a7a3eb75ccd69a3577bf Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 15 Dec 2015 11:41:24 +0000 Subject: [PATCH] Bug 15380: Introduce Koha::Authorit[y|ies] and Koha::Authority::Type[s] MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Based on Koha::Objects. Signed-off-by: Marc Véron Signed-off-by: Martin Renvoize Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- Koha/Authorities.pm | 56 +++++++++++++++++++++++++++++++ Koha/Authority.pm | 46 +++++++++++++++++++++++++ Koha/Authority/Type.pm | 49 +++++++++++++++++++++++++++ Koha/Authority/Types.pm | 50 +++++++++++++++++++++++++++ t/db_dependent/Koha/Authorities.t | 55 ++++++++++++++++++++++++++++++ 5 files changed, 256 insertions(+) create mode 100644 Koha/Authorities.pm create mode 100644 Koha/Authority.pm create mode 100644 Koha/Authority/Type.pm create mode 100644 Koha/Authority/Types.pm create mode 100644 t/db_dependent/Koha/Authorities.t diff --git a/Koha/Authorities.pm b/Koha/Authorities.pm new file mode 100644 index 0000000000..c2a75b9dcd --- /dev/null +++ b/Koha/Authorities.pm @@ -0,0 +1,56 @@ +package Koha::Authorities; + +# 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, 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::Authority; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Authorities - Koha Authority object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'AuthHeader'; +} + +=head3 object_class + +=cut + +sub object_class { + return 'Koha::Authority'; +} + +1; diff --git a/Koha/Authority.pm b/Koha/Authority.pm new file mode 100644 index 0000000000..c46ab9e0a8 --- /dev/null +++ b/Koha/Authority.pm @@ -0,0 +1,46 @@ +package Koha::Authority; + +# 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, 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::Authority - Koha Authority Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'AuthHeader'; +} + +1; diff --git a/Koha/Authority/Type.pm b/Koha/Authority/Type.pm new file mode 100644 index 0000000000..73045fc9f5 --- /dev/null +++ b/Koha/Authority/Type.pm @@ -0,0 +1,49 @@ +package Koha::Authority::Type; + +# 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::Authority::Type - Koha Authority Type Object class + +=head1 API + +=head2 Class Methods + +=cut + +sub auth_tag_structures { + my ( $self ) = @_; + return $self->_result->auth_tag_structures; +} + +=head3 type + +=cut + +sub type { + return 'AuthType'; +} + +1; diff --git a/Koha/Authority/Types.pm b/Koha/Authority/Types.pm new file mode 100644 index 0000000000..2df7d240d0 --- /dev/null +++ b/Koha/Authority/Types.pm @@ -0,0 +1,50 @@ +package Koha::Authority::Types; + +# 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::Authority::Type; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Authority::Types - Koha Authority Type Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'AuthType'; +} + +sub object_class { + return 'Koha::Authority::Type'; +} + +1; diff --git a/t/db_dependent/Koha/Authorities.t b/t/db_dependent/Koha/Authorities.t new file mode 100644 index 0000000000..7210713f63 --- /dev/null +++ b/t/db_dependent/Koha/Authorities.t @@ -0,0 +1,55 @@ +#!/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 => 3; + +use Koha::Authority; +use Koha::Authorities; +use Koha::Authority::Type; +use Koha::Authority::Types; +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_authorities = Koha::Authorities->search->count; +my $nb_of_authority_types = Koha::Authority::Types->search->count; +my $new_authority_type_1 = Koha::Authority::Type->new( + { authtypecode => 'my_ac_1', + authtypetext => 'my authority type text 1', + auth_tag_to_report => '100', + summary => 'my summary for authority 1', + } +)->store; +my $new_authority_1 = Koha::Authority->new( { authtypecode => $new_authority_type_1->authtypecode, } )->store; +my $new_authority_2 = Koha::Authority->new( { authtypecode => $new_authority_type_1->authtypecode, } )->store; + +is( Koha::Authority::Types->search->count, $nb_of_authority_types + 1, 'The authority type should have been added' ); +is( Koha::Authorities->search->count, $nb_of_authorities + 2, 'The 2 authorities should have been added' ); + +$new_authority_1->delete; +is( Koha::Authorities->search->count, $nb_of_authorities + 1, 'Delete should have deleted the library' ); + +$schema->storage->txn_rollback; +1; -- 2.39.5