@@ -, +, @@
---
t/db_dependent/ImportExportFramework.t | 90 ++++++++++++++++++---
t/db_dependent/data/frameworks/auth_type.csv | 21 +++++
t/db_dependent/data/frameworks/auth_type.ods | Bin 0 -> 5125 bytes
t/db_dependent/data/frameworks/auth_type.xml | 28 +++++++
.../data/frameworks/auth_type_smaller.csv | 13 +++
.../data/frameworks/auth_type_smaller.ods | Bin 0 -> 4790 bytes
.../data/frameworks/auth_type_smaller.xml | 28 +++++++
7 files changed, 169 insertions(+), 11 deletions(-)
create mode 100644 t/db_dependent/data/frameworks/auth_type.csv
create mode 100644 t/db_dependent/data/frameworks/auth_type.ods
create mode 100644 t/db_dependent/data/frameworks/auth_type.xml
create mode 100644 t/db_dependent/data/frameworks/auth_type_smaller.csv
create mode 100644 t/db_dependent/data/frameworks/auth_type_smaller.ods
create mode 100644 t/db_dependent/data/frameworks/auth_type_smaller.xml
--- a/t/db_dependent/ImportExportFramework.t
+++ a/t/db_dependent/ImportExportFramework.t
@@ -26,6 +26,8 @@ use File::Basename qw( dirname );
use Koha::Database;
use Koha::BiblioFrameworks;
use Koha::MarcSubfieldStructures;
+use Koha::Authority::Types;
+use Koha::Authority::Subfields;
use C4::ImportExportFramework;
my $schema = Koha::Database->new->schema;
@@ -33,37 +35,57 @@ my $builder = t::lib::TestBuilder->new;
subtest 'ImportFramework() tests' => sub {
- plan tests => 3;
+ plan tests => 6;
- subtest 'CSV tests' => sub {
+ subtest 'CSV tests for biblio frameworks' => sub {
plan tests => 9;
- run_tests('csv');
+ run_biblio_tests('csv');
};
- subtest 'ODS tests' => sub {
+ subtest 'ODS tests for biblio frameworks' => sub {
plan tests => 9;
- run_tests('ods');
+ run_biblio_tests('ods');
};
- subtest 'XML tests' => sub {
+ subtest 'XML tests for biblio frameworks' => sub {
plan tests => 9;
- run_tests('xml');
+ run_biblio_tests('xml');
};
+
+ subtest 'CSV tests for auth frameworks' => sub {
+ plan tests => 9;
+
+ run_auth_tests('csv');
+ };
+
+ subtest 'ODS tests for auth frameworks' => sub {
+ plan tests => 9;
+
+ run_auth_tests('ods');
+ };
+
+ subtest 'XML tests for auth frameworks' => sub {
+ plan tests => 9;
+
+ run_auth_tests('xml');
+ };
+
};
-sub run_tests {
+sub run_biblio_tests {
my ($format) = @_;
+ my $type = "biblio";
$schema->storage->txn_begin;
my $data_filepath = dirname(__FILE__) . "/data/frameworks/biblio_framework.$format";
my $fw_1 = $builder->build_object({ class => 'Koha::BiblioFrameworks' });
- my $result = C4::ImportExportFramework::ImportFramework( $data_filepath, $fw_1->id );
+ my $result = C4::ImportExportFramework::ImportFramework( $data_filepath, $fw_1->id, 0, $type );
is( $result, 0, 'Import successful, no tags removed' );
my $nb_tags = $schema->resultset('MarcTagStructure')->search({ frameworkcode => $fw_1->id })->count;
@@ -74,7 +96,7 @@ sub run_tests {
# bad file tests
my $fw_2 = $builder->build_object({ class => 'Koha::BiblioFrameworks' });
- $result = C4::ImportExportFramework::ImportFramework( '', $fw_2->id );
+ $result = C4::ImportExportFramework::ImportFramework( '', $fw_2->id, 0, $type );
is( $result, -1, 'Bad file makes it return -1' );
@@ -87,7 +109,7 @@ sub run_tests {
# framework overwrite
$data_filepath = dirname(__FILE__) . "/data/frameworks/biblio_framework_smaller.$format";
- $result = C4::ImportExportFramework::ImportFramework( $data_filepath, $fw_1->id );
+ $result = C4::ImportExportFramework::ImportFramework( $data_filepath, $fw_1->id, 0, $type );
is( $result, 5, 'Smaller fw import successful, 4 tags removed' );
$nb_tags = $schema->resultset('MarcTagStructure')->search({ frameworkcode => $fw_1->id })->count;
@@ -98,3 +120,49 @@ sub run_tests {
$schema->storage->txn_rollback;
}
+
+sub run_auth_tests {
+
+ my ($format) = @_;
+ my $type = "authority";
+
+ $schema->storage->txn_begin;
+
+ my $data_filepath = dirname(__FILE__) . "/data/frameworks/auth_type.$format";
+ my $fw_1 = $builder->build_object({ class => 'Koha::Authority::Types' });
+
+ my $result = C4::ImportExportFramework::ImportFramework( $data_filepath, $fw_1->id, '', $type );
+ is( $result, 0, 'Import successful, no tags removed' );
+
+ my $nb_tags = $schema->resultset('AuthTagStructure')->search({ authtypecode => $fw_1->id })->count;
+ is( $nb_tags, 6, "6 tags should have been imported" );
+
+ my $nb_subfields = Koha::Authority::Subfields->search({ authtypecode => $fw_1->id })->count;
+ is( $nb_subfields, 8, "8 subfields should have been imported" );
+
+ # bad file tests
+ my $fw_2 = $builder->build_object({ class => 'Koha::Authority::Types' });
+ $result = C4::ImportExportFramework::ImportFramework( '', $fw_2->id, '', $type );
+
+ is( $result, -1, 'Bad file makes it return -1' );
+
+ $nb_tags = $schema->resultset('AuthTagStructure')->search({ authtypecode => $fw_2->id })->count;
+ is( $nb_tags, 0, "0 tags should have been imported" );
+
+ $nb_subfields = Koha::Authority::Subfields->search({ authtypecode => $fw_2->id })->count;
+ is( $nb_subfields, 0, "0 subfields should have been imported" );
+
+ # framework overwrite
+ $data_filepath = dirname(__FILE__) . "/data/frameworks/auth_type_smaller.$format";
+
+ $result = C4::ImportExportFramework::ImportFramework( $data_filepath, $fw_1->id, '', $type );
+ is( $result, 8, 'Smaller fw import successful, 6 tags removed' );
+
+ $nb_tags = $schema->resultset('AuthTagStructure')->search({ authtypecode => $fw_1->id })->count;
+ is( $nb_tags, 3, "3 tags should have been imported" );
+
+ $nb_subfields = Koha::Authority::Subfields->search({ authtypecode => $fw_1->id })->count;
+ is( $nb_subfields, 3, "3 subfields should have been imported" );
+
+ $schema->storage->txn_rollback;
+}
--- a/t/db_dependent/data/frameworks/auth_type.csv
+++ a/t/db_dependent/data/frameworks/auth_type.csv
@@ -0,0 +1,21 @@
+"authtypecode","tagfield","liblibrarian","libopac","repeatable","mandatory","authorised_value"
+"TEST","000","LEADER","LEADER","0","1",""
+"TEST","001","CONTROL NUMBER","CONTROL NUMBER","0","1",""
+"TEST","003","CONTROL NUMBER IDENTIFIER","CONTROL NUMBER IDENTIFIER","0","1",""
+"TEST","005","DATE AND TIME OF LATEST TRANSACTION","DATE AND TIME OF LATEST TRANSACTION","0","1",""
+"TEST","008","FIXED-LENGTH DATA ELEMENTS","FIXED-LENGTH DATA ELEMENTS","0","1",""
+"TEST","010","LIBRARY OF CONGRESS CONTROL NUMBER","LIBRARY OF CONGRESS CONTROL NUMBER","0","0",""
+
+"#-#","#-#","#-#","#-#","#-#","#-#","#-#"
+
+"authtypecode","tagfield","tagsubfield","liblibrarian","libopac","repeatable","mandatory","tab","authorised_value","value_builder","seealso","isurl","hidden","linkid","kohafield","frameworkcode","defaultvalue"
+"TEST","000","@","fixed length control field","fixed length control field","0","1","0","","marc21_leader_authorities.pl","","0","0","0","","",""
+"TEST","001","@","control field","control field","0","0","0","","","","0","0","0","auth_header.authid","",""
+"TEST","003","@","control field","control field","0","1","0","","marc21_orgcode.pl","","0","0","0","","",""
+"TEST","005","@","control field","control field","0","1","0","","marc21_field_005.pl","","0","0","0","","",""
+"TEST","008","@","fixed length control field","fixed length control field","0","1","0","","marc21_field_008_authorities.pl","","0","0","0","","",""
+"TEST","010","8","Field link and sequence number","Field link and sequence number","1","0","0","","","","0","0","0","","",""
+"TEST","010","a","LC control number","LC control number","0","0","0","","","","0","0","0","","",""
+"TEST","010","z","Canceled/invalid LC control number","Canceled/invalid LC control number","1","0","0","","","","0","0","0","","",""
+
+"#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#"
--- a/t/db_dependent/data/frameworks/auth_type.xml
+++ a/t/db_dependent/data/frameworks/auth_type.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+authtypecodetagfieldliblibrarianlibopacrepeatablemandatoryauthorised_valueTEST000LEADERLEADER01#TEST001CONTROL NUMBERCONTROL NUMBER01#TEST003CONTROL NUMBER IDENTIFIERCONTROL NUMBER IDENTIFIER01#TEST005DATE AND TIME OF LATEST TRANSACTIONDATE AND TIME OF LATEST TRANSACTION01#TEST008FIXED-LENGTH DATA ELEMENTSFIXED-LENGTH DATA ELEMENTS01#TEST010LIBRARY OF CONGRESS CONTROL NUMBERLIBRARY OF CONGRESS CONTROL NUMBER00#authtypecodetagfieldtagsubfieldliblibrarianlibopacrepeatablemandatorytabauthorised_valuevalue_builderseealsoisurlhiddenlinkidkohafieldframeworkcodedefaultvalueTEST000@fixed length control fieldfixed length control field010#marc21_leader_authorities.pl#000###TEST001@control fieldcontrol field000###000auth_header.authid##TEST003@control fieldcontrol field010#marc21_orgcode.pl#000###TEST005@control fieldcontrol field010#marc21_field_005.pl#000###TEST008@fixed length control fieldfixed length control field010#marc21_field_008_authorities.pl#000###TEST0108Field link and sequence numberField link and sequence number100###000###TEST010aLC control numberLC control number000###000###TEST010zCanceled/invalid LC control numberCanceled/invalid LC control number100###000###
--- a/t/db_dependent/data/frameworks/auth_type_smaller.csv
+++ a/t/db_dependent/data/frameworks/auth_type_smaller.csv
@@ -0,0 +1,13 @@
+"authtypecode","tagfield","liblibrarian","libopac","repeatable","mandatory","authorised_value"
+"","000","LEADER","LEADER","0","1",""
+"","001","CONTROL NUMBER","CONTROL NUMBER","0","1",""
+"","003","CONTROL NUMBER IDENTIFIER","CONTROL NUMBER IDENTIFIER","0","1",""
+
+"#-#","#-#","#-#","#-#","#-#","#-#","#-#"
+
+"authtypecode","tagfield","tagsubfield","liblibrarian","libopac","repeatable","mandatory","tab","authorised_value","value_builder","seealso","isurl","hidden","linkid","kohafield","frameworkcode","defaultvalue"
+"","000","@","fixed length control field","fixed length control field","0","1","0","","marc21_leader_authorities.pl","","0","0","0","","",""
+"","001","@","control field","control field","0","0","0","","","","0","0","0","auth_header.authid","",""
+"","003","@","control field","control field","0","1","0","","marc21_orgcode.pl","","0","0","0","","",""
+
+"#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#"
--- a/t/db_dependent/data/frameworks/auth_type_smaller.xml
+++ a/t/db_dependent/data/frameworks/auth_type_smaller.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+authtypecodetagfieldliblibrarianlibopacrepeatablemandatoryauthorised_valueT_SMALL000LEADERLEADER01#T_SMALL001CONTROL NUMBERCONTROL NUMBER01#T_SMALL003CONTROL NUMBER IDENTIFIERCONTROL NUMBER IDENTIFIER01#authtypecodetagfieldtagsubfieldliblibrarianlibopacrepeatablemandatorytabauthorised_valuevalue_builderseealsoisurlhiddenlinkidkohafieldframeworkcodedefaultvalueT_SMALL000@fixed length control fieldfixed length control field010#marc21_leader_authorities.pl#000###T_SMALL001@control fieldcontrol field000###000auth_header.authid##T_SMALL003@control fieldcontrol field010#marc21_orgcode.pl#000###
--