Bug 13952: (follow-up) Tests

Run:
prove -v t/db_dependent/ImportExportFramework.t and confirm all tests
pass.

I've also added a fix to remove the warns when exporting in ODS format.

Signed-off-by: Michal Denar <black23@gmail.com>

Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Mazen Khallaf <mazen.i.khallaf@gamil.com>

Signed-off-by: Michal Denar <black23@gmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Aleisha Amohia 2019-02-14 03:18:43 +00:00 committed by Fridolin Somers
parent 1b856c681e
commit 3880159360
7 changed files with 169 additions and 11 deletions

View File

@ -27,47 +27,69 @@ use Koha::Database;
use Koha::BiblioFrameworks;
use Koha::MarcSubfieldStructures;
use C4::ImportExportFramework qw( ImportFramework ExportFramework );
use Koha::Authority::Types;
use Koha::Authority::Subfields;
my $schema = Koha::Database->new->schema;
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 => 15;
run_tests('csv');
run_biblio_tests('csv');
run_csv_no_quoted();
};
subtest 'ODS tests' => sub {
subtest 'ODS tests for biblio frameworks' => sub {
plan tests => 15;
run_tests('ods');
run_biblio_tests('ods');
run_ods_new();
};
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;
@ -78,7 +100,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' );
@ -91,7 +113,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;
@ -165,5 +187,51 @@ sub run_ods_new {
is( $nb_subfields, 0, "0 subfields should have been imported" );
$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;
};

View File

@ -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","","",""
"#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#"
Can't render this file because it has a wrong number of fields in line 11.

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -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","","",""
"#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#"
Can't render this file because it has a wrong number of fields in line 8.

Binary file not shown.

File diff suppressed because one or more lines are too long