Bug 21749: Add tests for ImportFramework
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 12 Nov 2018 16:11:42 +0000 (13:11 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 15 Nov 2018 12:47:35 +0000 (12:47 +0000)
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

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

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

t/db_dependent/ImportExportFramework.t [new file with mode: 0644]
t/db_dependent/data/frameworks/biblio_framework.csv [new file with mode: 0644]

diff --git a/t/db_dependent/ImportExportFramework.t b/t/db_dependent/ImportExportFramework.t
new file mode 100644 (file)
index 0000000..de096cc
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+use Modern::Perl;
+use Test::More tests => 3;
+use File::Basename qw( dirname );
+
+use Koha::Database;
+use Koha::BiblioFrameworks;
+use Koha::MarcSubfieldStructures;
+use t::lib::TestBuilder;
+use C4::ImportExportFramework;
+
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
+my $builder = t::lib::TestBuilder->new;
+
+my $data_filepath = dirname(__FILE__) . '/data/biblio_framework.csv';
+
+my $frameworkcode = '4T';
+C4::ImportExportFramework::ImportFramework($data_filepath, $frameworkcode);
+
+my $dbh = C4::Context->dbh;
+
+# FIXME Import does not create the biblio framework
+#my $biblio_framework = Koha::BiblioFrameworks->find($frameworkcode);
+#ok( $biblio_framework );
+
+my $nb_tags = $dbh->selectrow_array(q|SELECT COUNT(*) FROM marc_tag_structure WHERE frameworkcode="4T"|);
+is( $nb_tags, 4, "4 tags should have been imported" );
+
+my $nb_subfields =
+  Koha::MarcSubfieldStructures->search( { frameworkcode => $frameworkcode } )
+  ->count;
+is( $nb_subfields, 12, "12 subfields should have been imported" );
diff --git a/t/db_dependent/data/frameworks/biblio_framework.csv b/t/db_dependent/data/frameworks/biblio_framework.csv
new file mode 100644 (file)
index 0000000..20ae097
--- /dev/null
@@ -0,0 +1,23 @@
+"tagfield","liblibrarian","libopac","repeatable","mandatory","authorised_value","frameworkcode"
+"000","LEADER","LEADER","0","1","",""
+"001","CONTROL NUMBER","CONTROL NUMBER","0","0","",""
+"003","CONTROL NUMBER IDENTIFIER","CONTROL NUMBER IDENTIFIER","0","1","",""
+"010","LIBRARY OF CONGRESS CONTROL NUMBER","LIBRARY OF CONGRESS CONTROL NUMBER","0","0","",""
+
+"#-#","#-#","#-#","#-#","#-#","#-#","#-#"
+
+"tagfield","tagsubfield","liblibrarian","libopac","repeatable","mandatory","kohafield","tab","authorised_value","authtypecode","value_builder","isurl","hidden","frameworkcode","seealso","link","defaultvalue","maxlength"
+"000","@","fixed length control field","fixed length control field","0","1","","0","","","marc21_leader.pl","0","0","","","","","24"
+"001","@","control field","control field","0","0","","0","","","","0","0","","","","","9999"
+"003","@","control field","control field","0","1","","0","","","marc21_orgcode.pl","0","0","","","","","9999"
+"005","@","control field","control field","0","1","","0","","","marc21_field_005.pl","0","0","","","","","9999"
+"006","@","fixed length control field","fixed length control field","0","0","","0","","","marc21_field_006.pl","0","-1","","","","","9999"
+"007","@","fixed length control field","fixed length control field","0","0","","0","","","marc21_field_007.pl","0","0","","","","","9999"
+"008","@","fixed length control field","fixed length control field","0","1","","0","","","marc21_field_008.pl","0","0","","","","","40"
+"009","@","fixed length control field","fixed length control field","0","0","","0","","","","0","-6","","","","","9999"
+"010","8","Field link and sequence number","Field link and sequence number","1","0","","0","","","","0","-6","","","","","9999"
+"010","a","LC control number","LC control number","0","0","biblioitems.lccn","0","","","","0","0","","","","","9999"
+"010","b","NUCMC control number","NUCMC control number","1","0","","0","","","","0","-1","","","","","9999"
+"010","z","Canceled/invalid LC control number","Canceled/invalid LC control number","1","0","","0","","","","0","-1","","","","","9999"
+
+"#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#"