From a0841bdce1faf0eacb11e6e190a9d662474a2068 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 12 Nov 2018 15:03:34 -0300 Subject: [PATCH] Bug 21749: (QA follow-up) Add more tests for ImportFramework Signed-off-by: Tomas Cohen Arazi https://bugs.koha-community.org/show_bug.cgi?id=21740 --- t/db_dependent/ImportExportFramework.t | 77 +++++++++++++++---- .../data/biblio_framework_smaller.csv | 18 +++++ 2 files changed, 78 insertions(+), 17 deletions(-) create mode 100644 t/db_dependent/data/biblio_framework_smaller.csv diff --git a/t/db_dependent/ImportExportFramework.t b/t/db_dependent/ImportExportFramework.t index de096cc2a6..28c79b0882 100644 --- a/t/db_dependent/ImportExportFramework.t +++ b/t/db_dependent/ImportExportFramework.t @@ -1,34 +1,77 @@ #!/usr/bin/perl +# 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 Test::More tests => 1; + +use t::lib::TestBuilder; + 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 $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; -my $data_filepath = dirname(__FILE__) . '/data/biblio_framework.csv'; +subtest 'ImportFramework() tests' => sub { + + plan tests => 9; + + $schema->storage->txn_begin; + + my $data_filepath = dirname(__FILE__) . '/data/biblio_framework.csv'; + my $fw_1 = $builder->build_object({ class => 'Koha::BiblioFrameworks' }); + + my $result = C4::ImportExportFramework::ImportFramework( $data_filepath, $fw_1->id ); + is( $result, 0, 'Import successful, no tags removed' ); + + my $nb_tags = $schema->resultset('MarcTagStructure')->search({ frameworkcode => $fw_1->id })->count; + is( $nb_tags, 4, "4 tags should have been imported" ); + + my $nb_subfields = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw_1->id })->count; + is( $nb_subfields, 12, "12 subfields should have been imported" ); + + # bad file tests + my $fw_2 = $builder->build_object({ class => 'Koha::BiblioFrameworks' }); + $result = C4::ImportExportFramework::ImportFramework( '', $fw_2->id ); + + is( $result, -1, 'Bad file makes it return -1' ); + + $nb_tags = $schema->resultset('MarcTagStructure')->search({ frameworkcode => $fw_2->id })->count; + is( $nb_tags, 0, "0 tags should have been imported" ); + + $nb_subfields = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw_2->id })->count; + is( $nb_subfields, 0, "0 subfields should have been imported" ); -my $frameworkcode = '4T'; -C4::ImportExportFramework::ImportFramework($data_filepath, $frameworkcode); + # framework overwrite + $data_filepath = dirname(__FILE__) . '/data/biblio_framework_smaller.csv'; -my $dbh = C4::Context->dbh; + $result = C4::ImportExportFramework::ImportFramework( $data_filepath, $fw_1->id ); + is( $result, 5, 'Smaller fw import successful, 4 tags removed' ); -# FIXME Import does not create the biblio framework -#my $biblio_framework = Koha::BiblioFrameworks->find($frameworkcode); -#ok( $biblio_framework ); + $nb_tags = $schema->resultset('MarcTagStructure')->search({ frameworkcode => $fw_1->id })->count; + is( $nb_tags, 2, "2 tags should have been imported" ); -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" ); + $nb_subfields = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw_1->id })->count; + is( $nb_subfields, 9, "9 subfields should have been imported" ); -my $nb_subfields = - Koha::MarcSubfieldStructures->search( { frameworkcode => $frameworkcode } ) - ->count; -is( $nb_subfields, 12, "12 subfields should have been imported" ); + $schema->storage->txn_rollback; +}; diff --git a/t/db_dependent/data/biblio_framework_smaller.csv b/t/db_dependent/data/biblio_framework_smaller.csv new file mode 100644 index 0000000000..ce7248e9cd --- /dev/null +++ b/t/db_dependent/data/biblio_framework_smaller.csv @@ -0,0 +1,18 @@ +"tagfield","liblibrarian","libopac","repeatable","mandatory","authorised_value","frameworkcode" +"000","LEADER","LEADER","0","1","","" +"001","CONTROL NUMBER","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" +"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" +"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" + +"#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#" -- 2.19.1