Bug 15451: Add the 2 new modules Koha::CsvProfile[s]
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 31 Dec 2015 10:22:47 +0000 (10:22 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 22 Jul 2016 17:18:34 +0000 (17:18 +0000)
There are based on Koha::Objets. Tests provided.

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Test pass, no errors.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Koha/CsvProfile.pm [new file with mode: 0644]
Koha/CsvProfiles.pm [new file with mode: 0644]
t/db_dependent/Koha/CsvProfiles.t [new file with mode: 0644]

diff --git a/Koha/CsvProfile.pm b/Koha/CsvProfile.pm
new file mode 100644 (file)
index 0000000..737aa32
--- /dev/null
@@ -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 (file)
index 0000000..f55be00
--- /dev/null
@@ -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 (file)
index 0000000..70c2201
--- /dev/null
@@ -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 <http://www.gnu.org/licenses>.
+
+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;