From 7c11f056268195bac6c660182db97d4f2684b50a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 1 Feb 2021 14:54:15 +0100 Subject: [PATCH] Bug 27569: Add tests Signed-off-by: Ron Houk Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- t/db_dependent/ImportExportFramework.t | 37 ++++++++++++++++++- .../frameworks/biblio_framework_no_quoted.csv | 23 ++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 t/db_dependent/data/frameworks/biblio_framework_no_quoted.csv diff --git a/t/db_dependent/ImportExportFramework.t b/t/db_dependent/ImportExportFramework.t index 8189183fc4..772fb23886 100755 --- a/t/db_dependent/ImportExportFramework.t +++ b/t/db_dependent/ImportExportFramework.t @@ -36,9 +36,11 @@ subtest 'ImportFramework() tests' => sub { plan tests => 3; subtest 'CSV tests' => sub { - plan tests => 9; + plan tests => 15; run_tests('csv'); + + run_csv_no_quoted(); }; subtest 'ODS tests' => sub { @@ -97,4 +99,35 @@ sub run_tests { is( $nb_subfields, 8, "8 subfields should have been imported" ); $schema->storage->txn_rollback; -} +}; + +sub run_csv_no_quoted { + + $schema->storage->txn_begin; + + my $data_filepath = dirname(__FILE__) . "/data/frameworks/biblio_framework_no_quoted.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" ); + + $schema->storage->txn_rollback; +}; diff --git a/t/db_dependent/data/frameworks/biblio_framework_no_quoted.csv b/t/db_dependent/data/frameworks/biblio_framework_no_quoted.csv new file mode 100644 index 0000000000..0f511df296 --- /dev/null +++ b/t/db_dependent/data/frameworks/biblio_framework_no_quoted.csv @@ -0,0 +1,23 @@ +"tagfield","liblibrarian","libopac","repeatable","mandatory","important","authorised_value","ind1_defaultvalue","ind2_defaultvalue","frameworkcode",,,,,,,,, +"000","LEADER","LEADER","0","1","0",,,,,,,,,,,,, +"001","CONTROL NUMBER","CONTROL NUMBER","0","0","0",,,,,,,,,,,,, +"003","CONTROL NUMBER IDENTIFIER","CONTROL NUMBER IDENTIFIER","0","1","0",,,,,,,,,,,,, +"010","LIBRARY OF CONGRESS CONTROL NUMBER","LIBRARY OF CONGRESS CONTROL NUMBER","0","0","0",,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,, +"#-#","#-#","#-#","#-#","#-#","#-#","#-#" +,,,,,,,,,,,,,,,,,, +"tagfield","tagsubfield","liblibrarian","libopac","repeatable","mandatory","important","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",,"0",,,"marc21_leader.pl","0","0",,,,,"24" +"001","@","control field","control field","0","0","0",,"0",,,,"0","0",,,,,"9999" +"003","@","control field","control field","0","1","0",,"0",,,"marc21_orgcode.pl","0","0",,,,,"9999" +"005","@","control field","control field","0","1","0",,"0",,,"marc21_field_005.pl","0","0",,,,,"9999" +"006","@","fixed length control field","fixed length control field","0","0","0",,"0",,,"marc21_field_006.pl","0","-1",,,,,"9999" +"007","@","fixed length control field","fixed length control field","0","0","0",,"0",,,"marc21_field_007.pl","0","0",,,,,"9999" +"008","@","fixed length control field","fixed length control field","0","1","0",,"0",,,"marc21_field_008.pl","0","0",,,,,"40" +"009","@","fixed length control field","fixed length control field","0","0","0",,"0",,,,"0","-6",,,,,"9999" +"010","8","Field link and sequence number","Field link and sequence number","1","0","0",,"0",,,,"0","-6",,,,,"9999" +"010","a","LC control number","LC control number","0","0","0","biblioitems.lccn","0",,,,"0","0",,,,,"9999" +"010","b","NUCMC control number","NUCMC control number","1","0","0",,"0",,,,"0","-1",,,,,"9999" +"010","z","Canceled/invalid LC control number","Canceled/invalid LC control number","1","0","0",,"0",,,,"0","-1",,,,,"9999" +,,,,,,,,,,,,,,,,,, +"#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#" -- 2.39.5