From 9deb1ace53a16d245a7dfbefd8df016822dae850 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 31 Dec 2015 10:22:47 +0000 Subject: [PATCH] Bug 15451: Add the 2 new modules Koha::CsvProfile[s] There are based on Koha::Objets. Tests provided. Signed-off-by: Bernardo Gonzalez Kriegel Test pass, no errors. Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall --- Koha/CsvProfile.pm | 44 ++++++++++++++++++++++++ Koha/CsvProfiles.pm | 50 +++++++++++++++++++++++++++ t/db_dependent/Koha/CsvProfiles.t | 57 +++++++++++++++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 Koha/CsvProfile.pm create mode 100644 Koha/CsvProfiles.pm create mode 100644 t/db_dependent/Koha/CsvProfiles.t diff --git a/Koha/CsvProfile.pm b/Koha/CsvProfile.pm new file mode 100644 index 0000000000..737aa32dac --- /dev/null +++ b/Koha/CsvProfile.pm @@ -0,0 +1,44 @@ +package Koha::CsvProfile; + +# 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::CsvProfile - Koha Csv Profile Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 _type + +=cut + +sub _type { + return 'ExportFormat'; +} + +1; diff --git a/Koha/CsvProfiles.pm b/Koha/CsvProfiles.pm new file mode 100644 index 0000000000..f55be00c04 --- /dev/null +++ b/Koha/CsvProfiles.pm @@ -0,0 +1,50 @@ +package Koha::CsvProfiles; + +# 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::CsvProfile; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::CsvProfiles - Koha Csv Profile Object set class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 _type + +=cut + +sub _type { + return 'ExportFormat'; +} + +sub object_class { + return 'Koha::CsvProfile'; +} + +1; diff --git a/t/db_dependent/Koha/CsvProfiles.t b/t/db_dependent/Koha/CsvProfiles.t new file mode 100644 index 0000000000..70c22014b6 --- /dev/null +++ b/t/db_dependent/Koha/CsvProfiles.t @@ -0,0 +1,57 @@ +#!/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::CsvProfile; +use Koha::CsvProfiles; +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_csv_profiles = Koha::CsvProfiles->search->count; +my $new_csv_profile_1 = Koha::CsvProfile->new({ + profile => 'my_csv_profile_name_for_test_1', + description => 'my_csv_profile_description_for_test_1', + type => 'sql' +})->store; +my $new_csv_profile_2 = Koha::CsvProfile->new({ + profile => 'my_csv_profile_name_for_test_2', + description => 'my_csv_profile_description_for_test_2', + type => 'marc', +})->store; + +like( $new_csv_profile_1->export_format_id, qr|^\d+$|, 'Adding a new csv_profile should have set the export_format_id'); +is( Koha::CsvProfiles->search->count, $nb_of_csv_profiles + 2, 'The 2 csv profiles should have been added' ); + +my $retrieved_csv_profile_1 = Koha::CsvProfiles->find( $new_csv_profile_1->export_format_id ); +is( $retrieved_csv_profile_1->profile, $new_csv_profile_1->profile, 'Find a csv_profile by id should return the correct csv_profile' ); + +$retrieved_csv_profile_1->delete; +is( Koha::CsvProfiles->search->count, $nb_of_csv_profiles + 1, 'Delete should have deleted the csv_profile' ); + +$schema->storage->txn_rollback; + +1; -- 2.39.5