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

(-)a/t/db_dependent/Biblio.t (-13 / +22 lines)
Lines 19-28 use Modern::Perl; Link Here
19
19
20
use Test::More tests => 9;
20
use Test::More tests => 9;
21
use Test::MockModule;
21
use Test::MockModule;
22
23
use List::MoreUtils qw( uniq );
22
use List::MoreUtils qw( uniq );
24
use MARC::Record;
23
use MARC::Record;
24
25
use t::lib::Mocks qw( mock_preference );
25
use t::lib::Mocks qw( mock_preference );
26
use t::lib::TestBuilder;
26
27
27
use Koha::Database;
28
use Koha::Database;
28
use Koha::Caches;
29
use Koha::Caches;
Lines 47-53 subtest 'GetMarcSubfieldStructureFromKohaField' => sub { Link Here
47
    );
48
    );
48
49
49
    # biblio.biblionumber must be mapped so this should return something
50
    # biblio.biblionumber must be mapped so this should return something
50
    my $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('biblio.biblionumber', '');
51
    my $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('biblio.biblionumber');
51
52
52
    ok(defined $marc_subfield_structure, "There is a result");
53
    ok(defined $marc_subfield_structure, "There is a result");
53
    is(ref $marc_subfield_structure, "HASH", "Result is a hashref");
54
    is(ref $marc_subfield_structure, "HASH", "Result is a hashref");
Lines 58-70 subtest 'GetMarcSubfieldStructureFromKohaField' => sub { Link Here
58
    like($marc_subfield_structure->{tagfield}, qr/^\d{3}$/, "tagfield is a valid tagfield");
59
    like($marc_subfield_structure->{tagfield}, qr/^\d{3}$/, "tagfield is a valid tagfield");
59
60
60
    # Add a test for list context (BZ 10306)
61
    # Add a test for list context (BZ 10306)
61
    my @results = GetMarcSubfieldStructureFromKohaField('biblio.biblionumber', '');
62
    my @results = GetMarcSubfieldStructureFromKohaField('biblio.biblionumber');
62
    is( @results, 1, 'We expect only one mapping' );
63
    is( @results, 1, 'We expect only one mapping' );
63
    is_deeply( $results[0], $marc_subfield_structure,
64
    is_deeply( $results[0], $marc_subfield_structure,
64
        'The first entry should be the same hashref as we had before' );
65
        'The first entry should be the same hashref as we had before' );
65
66
66
    # foo.bar does not exist so this should return undef
67
    # foo.bar does not exist so this should return undef
67
    $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('foo.bar', '');
68
    $marc_subfield_structure = GetMarcSubfieldStructureFromKohaField('foo.bar');
68
    is($marc_subfield_structure, undef, "invalid kohafield returns undef");
69
    is($marc_subfield_structure, undef, "invalid kohafield returns undef");
69
70
70
};
71
};
Lines 73-84 subtest "GetMarcSubfieldStructure" => sub { Link Here
73
    plan tests => 5;
74
    plan tests => 5;
74
75
75
    # Add multiple Koha to Marc mappings
76
    # Add multiple Koha to Marc mappings
76
    my $mapping1 = Koha::MarcSubfieldStructures->find('','399','a') // Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '399', tagsubfield => 'a' });
77
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '399', tagsubfield => [ 'a', 'b' ] })->delete;
77
    $mapping1->kohafield( "mytable.nicepages" );
78
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '399', tagsubfield => 'a', kohafield => "mytable.nicepages" })->store;
78
    $mapping1->store;
79
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '399', tagsubfield => 'b', kohafield => "mytable.nicepages" })->store;
79
    my $mapping2 = Koha::MarcSubfieldStructures->find('','399','b') // Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '399', tagsubfield => 'b' });
80
    $mapping2->kohafield( "mytable.nicepages" );
81
    $mapping2->store;
82
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
80
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
83
    my $structure = C4::Biblio::GetMarcSubfieldStructure('');
81
    my $structure = C4::Biblio::GetMarcSubfieldStructure('');
84
82
Lines 95-107 subtest "GetMarcSubfieldStructure" => sub { Link Here
95
};
93
};
96
94
97
subtest "GetMarcFromKohaField" => sub {
95
subtest "GetMarcFromKohaField" => sub {
98
    plan tests => 6;
96
    plan tests => 8;
99
97
100
    #NOTE: We are building on data from the previous subtest
98
    #NOTE: We are building on data from the previous subtest
101
    # With: field 399 / mytable.nicepages
99
    # With: field 399 / mytable.nicepages
102
100
103
    # Check call in list context for multiple mappings
101
    # Check call in list context for multiple mappings
104
    my @retval = C4::Biblio::GetMarcFromKohaField('mytable.nicepages', '');
102
    my @retval = C4::Biblio::GetMarcFromKohaField('mytable.nicepages');
105
    is( @retval, 4, 'Should return two tags and subfields' );
103
    is( @retval, 4, 'Should return two tags and subfields' );
106
    is( $retval[0], '399', 'Check first tag' );
104
    is( $retval[0], '399', 'Check first tag' );
107
    is( $retval[1], 'a', 'Check first subfield' );
105
    is( $retval[1], 'a', 'Check first subfield' );
Lines 109-116 subtest "GetMarcFromKohaField" => sub { Link Here
109
    is( $retval[3], 'b', 'Check second subfield' );
107
    is( $retval[3], 'b', 'Check second subfield' );
110
108
111
    # Check same call in scalar context
109
    # Check same call in scalar context
112
    is( C4::Biblio::GetMarcFromKohaField('mytable.nicepages', ''), '399',
110
    is( C4::Biblio::GetMarcFromKohaField('mytable.nicepages'), '399',
113
        'GetMarcFromKohaField returns first tag in scalar context' );
111
        'GetMarcFromKohaField returns first tag in scalar context' );
112
113
    # Bug 19096 Default is authoritative
114
    # If we add a new empty framework, we should still get the mappings
115
    # from Default. CAUTION: This test passes intentionally the obsoleted
116
    # framework parameter.
117
    my $new_fw = t::lib::TestBuilder->new->build({source => 'BiblioFramework'});
118
    @retval = C4::Biblio::GetMarcFromKohaField(
119
        'mytable.nicepages', $new_fw->{frameworkcode},
120
    );
121
    is( @retval, 4, 'Still got two pairs of tags/subfields' );
122
    is( $retval[0].$retval[1], '399a', 'Including 399a' );
114
};
123
};
115
124
116
# Mocking variables
125
# Mocking variables
(-)a/t/db_dependent/Biblio/TransformKohaToMarc.t (-36 / +20 lines)
Lines 14-25 my $schema = Koha::Database->new->schema; Link Here
14
$schema->storage->txn_begin;
14
$schema->storage->txn_begin;
15
15
16
# Create/overwrite some Koha to MARC mappings in default framework
16
# Create/overwrite some Koha to MARC mappings in default framework
17
my $mapping1 = Koha::MarcSubfieldStructures->find('','300','a') // Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'a' });
17
Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '300', tagsubfield => 'a' })->delete;
18
$mapping1->kohafield( "mytable.nicepages" );
18
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'a', kohafield => "mytable.nicepages" })->store;
19
$mapping1->store;
19
Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '300', tagsubfield => 'b' })->delete;
20
my $mapping2 = Koha::MarcSubfieldStructures->find('','300','b') // Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'b' });
20
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'b', kohafield => "mytable2.goodillustrations" })->store;
21
$mapping2->kohafield( "mytable2.goodillustrations" );
22
$mapping2->store;
23
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
21
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
24
22
25
my $record = C4::Biblio::TransformKohaToMarc({
23
my $record = C4::Biblio::TransformKohaToMarc({
Lines 44-53 is_deeply( \@subfields, [ Link Here
44
subtest "Multiple Koha to MARC mappings (BZ 10306)" => sub {
42
subtest "Multiple Koha to MARC mappings (BZ 10306)" => sub {
45
    plan tests => 4;
43
    plan tests => 4;
46
44
47
    # 300a and 260d mapped to mytable.nicepages
45
    # Add260d mapping so that 300a and 260d both map to mytable.nicepages
48
    my $mapping3 = Koha::MarcSubfieldStructures->find('','260','d') // Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '260', tagsubfield => 'd' });
46
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '260', tagsubfield => 'd' })->delete;
49
    $mapping3->kohafield( "mytable.nicepages" );
47
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '260', tagsubfield => 'd', kohafield => "mytable.nicepages" })->store;
50
    $mapping3->store;
51
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
48
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
52
49
53
    # Include two values in goodillustrations too: should result in two
50
    # Include two values in goodillustrations too: should result in two
Lines 63-114 subtest "Multiple Koha to MARC mappings (BZ 10306)" => sub { Link Here
63
        "Check second 300b" );
60
        "Check second 300b" );
64
};
61
};
65
62
66
subtest "Working with control fields in another framework" => sub {
63
subtest "Working with control fields" => sub {
67
    plan tests => 2;
64
    plan tests => 1;
68
69
    # Add a new framework
70
    my $fw = t::lib::TestBuilder->new->build_object({
71
        class => 'Koha::BiblioFrameworks'
72
    });
73
65
74
    # Map a controlfield to 'fullcontrol'
66
    # Map a controlfield to 'fullcontrol'
75
    my $mapping = Koha::MarcSubfieldStructure->new({ frameworkcode => $fw->frameworkcode, tagfield => '001', tagsubfield => '@', kohafield => 'fullcontrol' });
67
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '001', tagsubfield => '@' })->delete;
76
    $mapping->store;
68
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '001', tagsubfield => '@', kohafield => "fullcontrol" })->store;
69
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
77
70
78
    # First test in the wrong framework
79
    my @cols = ( notexist => 'i am not here', fullcontrol => 'all' );
71
    my @cols = ( notexist => 'i am not here', fullcontrol => 'all' );
80
    my $record = C4::Biblio::TransformKohaToMarc( { @cols } );
72
    my $record = C4::Biblio::TransformKohaToMarc( { @cols } );
81
    is( $record->field('001'), undef,
73
    is( $record->field('001')->data, 'all', 'Verify field 001' );
82
        'With default framework we should not find a 001 controlfield' );
83
    # Now include the framework parameter and test 001
84
    $record = C4::Biblio::TransformKohaToMarc( { @cols }, $fw->frameworkcode );
85
    is( $record->field('001')->data, "all", "Check controlfield 001 with right frameworkcode" );
86
87
    # Remove from cache
88
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-".$fw->frameworkcode );
89
};
74
};
90
75
91
subtest "Add test for no_split option" => sub {
76
subtest "Add test for no_split option" => sub {
92
    plan tests => 4;
77
    plan tests => 4;
93
78
94
    my $fwc = t::lib::TestBuilder->new->build({ source => 'BiblioFramework' })->{frameworkcode};
79
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'a' })->delete;
95
    Koha::MarcSubfieldStructure->new({ frameworkcode => $fwc, tagfield => '952', tagsubfield => 'a', kohafield => 'items.fld1' })->store;
80
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '952', tagsubfield => 'a', kohafield => 'items.fld1' })->store;
96
    Koha::MarcSubfieldStructure->new({ frameworkcode => $fwc, tagfield => '952', tagsubfield => 'b', kohafield => 'items.fld1' })->store;
81
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'b' })->delete;
97
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-$fwc" );
82
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '952', tagsubfield => 'b', kohafield => 'items.fld1' })->store;
83
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
98
84
99
    # Test single value in fld1
85
    # Test single value in fld1
100
    my @cols = ( 'items.fld1' => '01' );
86
    my @cols = ( 'items.fld1' => '01' );
101
    my $record = C4::Biblio::TransformKohaToMarc( { @cols }, $fwc, { no_split => 1 } );
87
    my $record = C4::Biblio::TransformKohaToMarc( { @cols }, { no_split => 1 } );
102
    is( $record->subfield( '952', 'a' ), '01', 'Check single in 952a' );
88
    is( $record->subfield( '952', 'a' ), '01', 'Check single in 952a' );
103
    is( $record->subfield( '952', 'b' ), '01', 'Check single in 952b' );
89
    is( $record->subfield( '952', 'b' ), '01', 'Check single in 952b' );
104
90
105
    # Test glued (composite) value in fld1
91
    # Test glued (composite) value in fld1
106
    @cols = ( 'items.fld1' => '01 | 02' );
92
    @cols = ( 'items.fld1' => '01 | 02' );
107
    $record = C4::Biblio::TransformKohaToMarc( { @cols }, $fwc, { no_split => 1 } );
93
    $record = C4::Biblio::TransformKohaToMarc( { @cols }, { no_split => 1 } );
108
    is( $record->subfield( '952', 'a' ), '01 | 02', 'Check composite in 952a' );
94
    is( $record->subfield( '952', 'a' ), '01 | 02', 'Check composite in 952a' );
109
    is( $record->subfield( '952', 'b' ), '01 | 02', 'Check composite in 952b' );
95
    is( $record->subfield( '952', 'b' ), '01 | 02', 'Check composite in 952b' );
110
111
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-$fwc" );
112
};
96
};
113
97
114
# Cleanup
98
# Cleanup
(-)a/t/db_dependent/Biblio/TransformMarcToKoha.t (-16 / +25 lines)
Lines 33-47 use C4::Biblio; Link Here
33
my $schema  = Koha::Database->new->schema;
33
my $schema  = Koha::Database->new->schema;
34
$schema->storage->txn_begin;
34
$schema->storage->txn_begin;
35
35
36
# Create a new framework with a few mappings
36
# Create a few mappings
37
# Note: TransformMarcToKoha wants a table name (biblio, biblioitems or items)
37
# Note: TransformMarcToKoha wants a table name (biblio, biblioitems or items)
38
our $fwc = t::lib::TestBuilder->new->build_object({ class => 'Koha::BiblioFrameworks' })->frameworkcode;
38
Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => [ '300', '500' ] })->delete;
39
Koha::MarcSubfieldStructure->new({ frameworkcode => $fwc, tagfield => '300', tagsubfield => 'a', kohafield => 'biblio.field1' })->store;
39
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'a', kohafield => 'biblio.field1' })->store;
40
Koha::MarcSubfieldStructure->new({ frameworkcode => $fwc, tagfield => '300', tagsubfield => 'b', kohafield => 'biblio.field2' })->store;
40
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '300', tagsubfield => 'b', kohafield => 'biblio.field2' })->store;
41
Koha::MarcSubfieldStructure->new({ frameworkcode => $fwc, tagfield => '500', tagsubfield => 'a', kohafield => 'biblio.field3' })->store;
41
Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '500', tagsubfield => 'a', kohafield => 'biblio.field3' })->store;
42
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
42
43
43
subtest 'Test a few mappings' => sub {
44
subtest 'Test a few mappings' => sub {
44
    plan tests => 6;
45
    plan tests => 7;
45
46
46
    my $marc = MARC::Record->new;
47
    my $marc = MARC::Record->new;
47
    $marc->append_fields(
48
    $marc->append_fields(
Lines 49-89 subtest 'Test a few mappings' => sub { Link Here
49
        MARC::Field->new( '300', '', '', a => 'a2', b => 'b2' ),
50
        MARC::Field->new( '300', '', '', a => 'a2', b => 'b2' ),
50
        MARC::Field->new( '500', '', '', a => 'note1', a => 'note2' ),
51
        MARC::Field->new( '500', '', '', a => 'note1', a => 'note2' ),
51
    );
52
    );
52
    my $result = C4::Biblio::TransformMarcToKoha( $marc, $fwc );
53
    my $result = C4::Biblio::TransformMarcToKoha( $marc );
53
        # Note: TransformMarcToKoha stripped the table prefix biblio.
54
        # Note: TransformMarcToKoha stripped the table prefix biblio.
54
    is( keys %{$result}, 3, 'Found all three mappings' );
55
    is( keys %{$result}, 3, 'Found all three mappings' );
55
    is( $result->{field1}, 'a1 | a2', 'Check field1 results' );
56
    is( $result->{field1}, 'a1 | a2', 'Check field1 results' );
56
    is( $result->{field2}, 'b1 | b2', 'Check field2 results' );
57
    is( $result->{field2}, 'b1 | b2', 'Check field2 results' );
57
    is( $result->{field3}, 'note1 | note2', 'Check field3 results' );
58
    is( $result->{field3}, 'note1 | note2', 'Check field3 results' );
58
59
59
    is( C4::Biblio::TransformMarcToKohaOneField( 'biblio.field1', $marc, $fwc ),
60
    is( C4::Biblio::TransformMarcToKohaOneField( 'biblio.field1', $marc ),
60
        $result->{field1}, 'TransformMarcToKohaOneField returns biblio.field1');
61
        $result->{field1}, 'TransformMarcToKohaOneField returns biblio.field1');
61
    is( C4::Biblio::TransformMarcToKohaOneField( 'field4', $marc, $fwc ),
62
    is( C4::Biblio::TransformMarcToKohaOneField( 'field4', $marc ),
62
        undef, 'TransformMarcToKohaOneField returns undef' );
63
        undef, 'TransformMarcToKohaOneField returns undef' );
64
65
    # Bug 19096 Default is authoritative now
66
    # Test passing another framework
67
    # CAUTION: This parameter of TransformMarcToKoha will be removed later
68
    my $new_fw = t::lib::TestBuilder->new->build({source => 'BiblioFramework'});
69
    $result = C4::Biblio::TransformMarcToKoha($marc, $new_fw->{frameworkcode});
70
    is( keys %{$result}, 3, 'Still found all three mappings' );
63
};
71
};
64
72
65
subtest 'Multiple mappings for one kohafield' => sub {
73
subtest 'Multiple mappings for one kohafield' => sub {
66
    plan tests => 4;
74
    plan tests => 4;
67
75
68
    # Add another mapping to field1
76
    # Add another mapping to field1
69
    Koha::MarcSubfieldStructure->new({ frameworkcode => $fwc, tagfield => '510', tagsubfield => 'a', kohafield => 'biblio.field1' })->store;
77
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '510' })->delete;
70
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-$fwc" );
78
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '510', tagsubfield => 'a', kohafield => 'biblio.field1' })->store;
79
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
71
80
72
    my $marc = MARC::Record->new;
81
    my $marc = MARC::Record->new;
73
    $marc->append_fields( MARC::Field->new( '300', '', '', a => '3a' ) );
82
    $marc->append_fields( MARC::Field->new( '300', '', '', a => '3a' ) );
74
    my $result = C4::Biblio::TransformMarcToKoha( $marc, $fwc );
83
    my $result = C4::Biblio::TransformMarcToKoha( $marc );
75
    is_deeply( $result, { field1 => '3a' }, 'Simple start' );
84
    is_deeply( $result, { field1 => '3a' }, 'Simple start' );
76
    $marc->append_fields( MARC::Field->new( '510', '', '', a => '' ) );
85
    $marc->append_fields( MARC::Field->new( '510', '', '', a => '' ) );
77
    $result = C4::Biblio::TransformMarcToKoha( $marc, $fwc );
86
    $result = C4::Biblio::TransformMarcToKoha( $marc );
78
    is_deeply( $result, { field1 => '3a' }, 'An empty 510a makes no difference' );
87
    is_deeply( $result, { field1 => '3a' }, 'An empty 510a makes no difference' );
79
    $marc->append_fields( MARC::Field->new( '510', '', '', a => '51' ) );
88
    $marc->append_fields( MARC::Field->new( '510', '', '', a => '51' ) );
80
    $result = C4::Biblio::TransformMarcToKoha( $marc, $fwc );
89
    $result = C4::Biblio::TransformMarcToKoha( $marc );
81
    is_deeply( $result, { field1 => '3a | 51' }, 'Got 300a and 510a' );
90
    is_deeply( $result, { field1 => '3a | 51' }, 'Got 300a and 510a' );
82
91
83
    is( C4::Biblio::TransformMarcToKohaOneField( 'biblio.field1', $marc, $fwc ),
92
    is( C4::Biblio::TransformMarcToKohaOneField( 'biblio.field1', $marc ),
84
        '3a | 51', 'TransformMarcToKohaOneField returns biblio.field1' );
93
        '3a | 51', 'TransformMarcToKohaOneField returns biblio.field1' );
85
};
94
};
86
95
87
# Cleanup
96
# Cleanup
88
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-$fwc" );
97
Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
89
$schema->storage->txn_rollback;
98
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Items.t (-62 / +23 lines)
Lines 17-22 Link Here
17
#
17
#
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
use Data::Dumper;
20
21
21
use MARC::Record;
22
use MARC::Record;
22
use C4::Biblio;
23
use C4::Biblio;
Lines 26-31 use Koha::Library; Link Here
26
use t::lib::Mocks;
27
use t::lib::Mocks;
27
use t::lib::TestBuilder;
28
use t::lib::TestBuilder;
28
29
30
use Koha::MarcSubfieldStructures;
31
use Koha::Caches;
32
29
use Test::More tests => 11;
33
use Test::More tests => 11;
30
34
31
use Test::Warn;
35
use Test::Warn;
Lines 413-419 subtest 'SearchItems test' => sub { Link Here
413
    my $cache = Koha::Caches->get_instance();
417
    my $cache = Koha::Caches->get_instance();
414
    $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
418
    $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
415
    $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
419
    $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
416
    $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
420
    $cache->clear_from_cache("default_value_for_mod_marc-");
417
    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
421
    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
418
422
419
    my $item3_record = new MARC::Record;
423
    my $item3_record = new MARC::Record;
Lines 444-450 subtest 'SearchItems test' => sub { Link Here
444
    # Clear cache
448
    # Clear cache
445
    $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
449
    $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
446
    $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
450
    $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
447
    $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
451
    $cache->clear_from_cache("default_value_for_mod_marc-");
448
    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
452
    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
449
453
450
    ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber);
454
    ModItemFromMarc($item3_record, $biblionumber, $item3_itemnumber);
Lines 614-670 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
614
    $schema->storage->txn_begin();
618
    $schema->storage->txn_begin();
615
619
616
    my $builder = t::lib::TestBuilder->new;
620
    my $builder = t::lib::TestBuilder->new;
617
    my $framework = $builder->build({
621
    my $framework = $builder->build({ source => 'BiblioFramework' });
618
        source => 'BiblioFramework',
619
    });
620
    # Link biblio.biblionumber and biblioitems.biblioitemnumber to avoid _koha_marc_update_bib_ids to fail with 'no biblio[item]number tag for framework"
621
    $builder->build({
622
        source => 'MarcSubfieldStructure',
623
        value => {
624
            frameworkcode => $framework->{frameworkcode},
625
            kohafield => 'biblio.biblionumber',
626
            tagfield => '999',
627
            tagsubfield => 'c',
628
        }
629
    });
630
    $builder->build({
631
        source => 'MarcSubfieldStructure',
632
        value => {
633
            frameworkcode => $framework->{frameworkcode},
634
            kohafield => 'biblioitems.biblioitemnumber',
635
            tagfield => '999',
636
            tagsubfield => 'd',
637
        }
638
    });
639
    my $mss_itemnumber = $builder->build({
640
        source => 'MarcSubfieldStructure',
641
        value => {
642
            frameworkcode => $framework->{frameworkcode},
643
            kohafield => 'items.itemnumber',
644
            tagfield => '952',
645
            tagsubfield => '9',
646
        }
647
    });
648
622
649
    my $mss_barcode = $builder->build({
623
    # Link biblio.biblionumber and biblioitems.biblioitemnumber to avoid _koha_marc_update_bib_ids to fail with 'no biblio[item]number tag for framework"
650
        source => 'MarcSubfieldStructure',
624
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '999', tagsubfield => [ 'c', 'd' ] })->delete;
651
        value => {
625
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '999', tagsubfield => 'c', kohafield => 'biblio.biblionumber' })->store;
652
            frameworkcode => $framework->{frameworkcode},
626
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '999', tagsubfield => 'd', kohafield => 'biblioitems.biblioitemnumber' })->store;
653
            kohafield => 'items.barcode',
654
            tagfield => '952',
655
            tagsubfield => 'p',
656
        }
657
    });
658
627
659
    my $mss_itemtype = $builder->build({
628
    # Same for item fields: itemnumber, barcode, itype
660
        source => 'MarcSubfieldStructure',
629
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => [ '9', 'p', 'y' ] })->delete;
661
        value => {
630
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '952', tagsubfield => '9', kohafield => 'items.itemnumber' })->store;
662
            frameworkcode => $framework->{frameworkcode},
631
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '952', tagsubfield => 'p', kohafield => 'items.barcode' })->store;
663
            kohafield => 'items.itype',
632
    Koha::MarcSubfieldStructure->new({ frameworkcode => '', tagfield => '952', tagsubfield => 'y', kohafield => 'items.itype' })->store;
664
            tagfield => '952',
633
    Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" );
665
            tagsubfield => 'y',
666
        }
667
    });
668
634
669
    my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
635
    my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
670
636
Lines 701-720 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
701
    $item = GetItem($item_itemnumber);
667
    $item = GetItem($item_itemnumber);
702
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
668
    is( $item->{barcode}, $a_barcode, 'Everything has been set up correctly, the barcode is defined as expected' );
703
669
704
    # Remove the mapping
670
    # Remove the mapping for barcode
705
    my $dbh = C4::Context->dbh;
671
    Koha::MarcSubfieldStructures->search({ frameworkcode => '', tagfield => '952', tagsubfield => 'p' })->delete;
706
    $dbh->do(q|
707
        DELETE FROM marc_subfield_structure
708
        WHERE kohafield = 'items.barcode'
709
        AND frameworkcode = ?
710
    |, undef, $framework->{frameworkcode} );
711
672
712
    # And make sure the caches are cleared
673
    # And make sure the caches are cleared
713
    my $cache = Koha::Caches->get_instance();
674
    my $cache = Koha::Caches->get_instance();
714
    $cache->clear_from_cache("MarcStructure-0-" . $framework->{frameworkcode});
675
    $cache->clear_from_cache("default_value_for_mod_marc-");
715
    $cache->clear_from_cache("MarcStructure-1-" . $framework->{frameworkcode});
676
    $cache->clear_from_cache("MarcSubfieldStructure-");
716
    $cache->clear_from_cache("default_value_for_mod_marc-" . $framework->{frameworkcode});
717
    $cache->clear_from_cache("MarcSubfieldStructure-" . $framework->{frameworkcode});
718
677
719
    # Update the MARC field with another value
678
    # Update the MARC field with another value
720
    $item_record->delete_fields( $barcode_field );
679
    $item_record->delete_fields( $barcode_field );
Lines 729-734 subtest 'C4::Items::_build_default_values_for_mod_marc' => sub { Link Here
729
    $item = GetItem($item_itemnumber);
688
    $item = GetItem($item_itemnumber);
730
    is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
689
    is ( $item->{barcode}, $a_barcode, 'items.barcode is not mapped anymore, so the DB column has not been updated' );
731
690
691
    $cache->clear_from_cache("default_value_for_mod_marc-");
692
    $cache->clear_from_cache( "MarcSubfieldStructure-" );
732
    $schema->storage->txn_rollback;
693
    $schema->storage->txn_rollback;
733
};
694
};
734
695
(-)a/t/db_dependent/Items/AutomaticItemModificationByAge.t (-3 / +3 lines)
Lines 23-29 my $builder = t::lib::TestBuilder->new; Link Here
23
my $library = $builder->build( { source => 'Branch' })->{branchcode};
23
my $library = $builder->build( { source => 'Branch' })->{branchcode};
24
my $library2 = $builder->build( { source => 'Branch' })->{branchcode};
24
my $library2 = $builder->build( { source => 'Branch' })->{branchcode};
25
25
26
my $frameworkcode = ''; # FIXME We do not want to insert the whole mapping, but we should use another frameworkcode
26
my $frameworkcode = ''; # Use Default for Koha to MARC mappings
27
$dbh->do(q|
27
$dbh->do(q|
28
    DELETE FROM marc_subfield_structure
28
    DELETE FROM marc_subfield_structure
29
    WHERE ( kohafield = 'items.new_status' OR kohafield = 'items.stocknumber' )
29
    WHERE ( kohafield = 'items.new_status' OR kohafield = 'items.stocknumber' )
Lines 40-46 $dbh->do(qq| Link Here
40
my $cache = Koha::Caches->get_instance();
40
my $cache = Koha::Caches->get_instance();
41
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
41
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
42
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
42
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
43
$cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
43
$cache->clear_from_cache("default_value_for_mod_marc-");
44
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
44
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
45
45
46
my $record = MARC::Record->new();
46
my $record = MARC::Record->new();
Lines 302-306 is( $modified_item->{new_status}, 'another_new_updated_value', q|ToggleNewStatus Link Here
302
$cache = Koha::Caches->get_instance();
302
$cache = Koha::Caches->get_instance();
303
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
303
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
304
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
304
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
305
$cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
305
$cache->clear_from_cache("default_value_for_mod_marc-");
306
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
306
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
(-)a/t/db_dependent/Reserves.t (-3 / +2 lines)
Lines 59-65 $dbh->do("update marc_subfield_structure set kohafield='biblioitems.agerestricti Link Here
59
my $cache = Koha::Caches->get_instance;
59
my $cache = Koha::Caches->get_instance;
60
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
60
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
61
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
61
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
62
$cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
62
$cache->clear_from_cache("default_value_for_mod_marc-");
63
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
63
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
64
64
65
## Setup Test
65
## Setup Test
Lines 711-717 $dbh->do('DELETE FROM reserves', undef, ($bibnum)); Link Here
711
711
712
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
712
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
713
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
713
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
714
$cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
714
$cache->clear_from_cache("default_value_for_mod_marc-");
715
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
715
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
716
716
717
subtest '_koha_notify_reserve() tests' => sub {
717
subtest '_koha_notify_reserve() tests' => sub {
718
- 

Return to bug 19096