View | Details | Raw Unified | Return to bug 21749
Collapse All | Expand All

(-)a/t/db_dependent/ImportExportFramework.t (-17 / +60 lines)
Lines 1-34 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
3
use Modern::Perl;
18
use Modern::Perl;
4
use Test::More tests => 3;
19
20
use Test::More tests => 1;
21
22
use t::lib::TestBuilder;
23
5
use File::Basename qw( dirname );
24
use File::Basename qw( dirname );
6
25
7
use Koha::Database;
26
use Koha::Database;
8
use Koha::BiblioFrameworks;
27
use Koha::BiblioFrameworks;
9
use Koha::MarcSubfieldStructures;
28
use Koha::MarcSubfieldStructures;
10
use t::lib::TestBuilder;
11
use C4::ImportExportFramework;
29
use C4::ImportExportFramework;
12
30
13
my $schema = Koha::Database->new->schema;
31
my $schema  = Koha::Database->new->schema;
14
$schema->storage->txn_begin;
15
my $builder = t::lib::TestBuilder->new;
32
my $builder = t::lib::TestBuilder->new;
16
33
17
my $data_filepath = dirname(__FILE__) . '/data/biblio_framework.csv';
34
subtest 'ImportFramework() tests' => sub {
35
36
    plan tests => 9;
37
38
    $schema->storage->txn_begin;
39
40
    my $data_filepath = dirname(__FILE__) . '/data/biblio_framework.csv';
41
    my $fw_1 = $builder->build_object({ class => 'Koha::BiblioFrameworks' });
42
43
    my $result = C4::ImportExportFramework::ImportFramework( $data_filepath, $fw_1->id );
44
    is( $result, 0, 'Import successful, no tags removed' );
45
46
    my $nb_tags = $schema->resultset('MarcTagStructure')->search({ frameworkcode => $fw_1->id })->count;
47
    is( $nb_tags, 4, "4 tags should have been imported" );
48
49
    my $nb_subfields = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw_1->id })->count;
50
    is( $nb_subfields, 12, "12 subfields should have been imported" );
51
52
    # bad file tests
53
    my $fw_2 = $builder->build_object({ class => 'Koha::BiblioFrameworks' });
54
    $result = C4::ImportExportFramework::ImportFramework( '', $fw_2->id );
55
56
    is( $result, -1, 'Bad file makes it return -1' );
57
58
    $nb_tags = $schema->resultset('MarcTagStructure')->search({ frameworkcode => $fw_2->id })->count;
59
    is( $nb_tags, 0, "0 tags should have been imported" );
60
61
    $nb_subfields = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw_2->id })->count;
62
    is( $nb_subfields, 0, "0 subfields should have been imported" );
18
63
19
my $frameworkcode = '4T';
64
    # framework overwrite
20
C4::ImportExportFramework::ImportFramework($data_filepath, $frameworkcode);
65
    $data_filepath = dirname(__FILE__) . '/data/biblio_framework_smaller.csv';
21
66
22
my $dbh = C4::Context->dbh;
67
    $result = C4::ImportExportFramework::ImportFramework( $data_filepath, $fw_1->id );
68
    is( $result, 5, 'Smaller fw import successful, 4 tags removed' );
23
69
24
# FIXME Import does not create the biblio framework
70
    $nb_tags = $schema->resultset('MarcTagStructure')->search({ frameworkcode => $fw_1->id })->count;
25
#my $biblio_framework = Koha::BiblioFrameworks->find($frameworkcode);
71
    is( $nb_tags, 2, "2 tags should have been imported" );
26
#ok( $biblio_framework );
27
72
28
my $nb_tags = $dbh->selectrow_array(q|SELECT COUNT(*) FROM marc_tag_structure WHERE frameworkcode="4T"|);
73
    $nb_subfields = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw_1->id })->count;
29
is( $nb_tags, 4, "4 tags should have been imported" );
74
    is( $nb_subfields, 9, "9 subfields should have been imported" );
30
75
31
my $nb_subfields =
76
    $schema->storage->txn_rollback;
32
  Koha::MarcSubfieldStructures->search( { frameworkcode => $frameworkcode } )
77
};
33
  ->count;
34
is( $nb_subfields, 12, "12 subfields should have been imported" );
(-)a/t/db_dependent/data/biblio_framework_smaller.csv (-1 / +18 lines)
Line 0 Link Here
0
- 
1
"tagfield","liblibrarian","libopac","repeatable","mandatory","authorised_value","frameworkcode"
2
"000","LEADER","LEADER","0","1","",""
3
"001","CONTROL NUMBER","CONTROL NUMBER","0","0","",""
4
5
"#-#","#-#","#-#","#-#","#-#","#-#","#-#"
6
7
"tagfield","tagsubfield","liblibrarian","libopac","repeatable","mandatory","kohafield","tab","authorised_value","authtypecode","value_builder","isurl","hidden","frameworkcode","seealso","link","defaultvalue","maxlength"
8
"000","@","fixed length control field","fixed length control field","0","1","","0","","","marc21_leader.pl","0","0","","","","","24"
9
"001","@","control field","control field","0","0","","0","","","","0","0","","","","","9999"
10
"003","@","control field","control field","0","1","","0","","","marc21_orgcode.pl","0","0","","","","","9999"
11
"005","@","control field","control field","0","1","","0","","","marc21_field_005.pl","0","0","","","","","9999"
12
"007","@","fixed length control field","fixed length control field","0","0","","0","","","marc21_field_007.pl","0","0","","","","","9999"
13
"008","@","fixed length control field","fixed length control field","0","1","","0","","","marc21_field_008.pl","0","0","","","","","40"
14
"010","a","LC control number","LC control number","0","0","biblioitems.lccn","0","","","","0","0","","","","","9999"
15
"010","b","NUCMC control number","NUCMC control number","1","0","","0","","","","0","-1","","","","","9999"
16
"010","z","Canceled/invalid LC control number","Canceled/invalid LC control number","1","0","","0","","","","0","-1","","","","","9999"
17
18
"#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#","#-#"

Return to bug 21749