|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2018 Biblibre |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Test::More tests => 8; |
| 23 |
|
| 24 |
use Koha::Database; |
| 25 |
use Koha::SearchFields; |
| 26 |
|
| 27 |
use t::lib::Mocks; |
| 28 |
use t::lib::TestBuilder; |
| 29 |
|
| 30 |
my $schema = Koha::Database->new->schema; |
| 31 |
$schema->storage->txn_begin; |
| 32 |
|
| 33 |
my $builder = t::lib::TestBuilder->new; |
| 34 |
|
| 35 |
t::lib::Mocks::mock_preference('marcflavour', 'marc21'); |
| 36 |
|
| 37 |
my $sf = $builder->build({ |
| 38 |
source => 'SearchField', |
| 39 |
}); |
| 40 |
|
| 41 |
my $smm = $builder->build({ |
| 42 |
source => 'SearchMarcMap', |
| 43 |
value => { |
| 44 |
index_name => 'biblios', |
| 45 |
marc_type => 'marc21', |
| 46 |
marc_field => '410abcdef' |
| 47 |
} |
| 48 |
}); |
| 49 |
|
| 50 |
my $smtf = $builder->build({ |
| 51 |
source => 'SearchMarcToField', |
| 52 |
value => { |
| 53 |
search_marc_map_id => $smm->{id}, |
| 54 |
search_field_id => $sf->{id} |
| 55 |
} |
| 56 |
}); |
| 57 |
|
| 58 |
my $smm2 = $builder->build({ |
| 59 |
source => 'SearchMarcMap', |
| 60 |
value => { |
| 61 |
index_name => 'biblios', |
| 62 |
marc_type => 'unimarc', |
| 63 |
marc_field => '410abcdef' |
| 64 |
} |
| 65 |
}); |
| 66 |
|
| 67 |
my $smtf2 = $builder->build({ |
| 68 |
source => 'SearchMarcToField', |
| 69 |
value => { |
| 70 |
search_marc_map_id => $smm2->{id}, |
| 71 |
search_field_id => $sf->{id} |
| 72 |
} |
| 73 |
}); |
| 74 |
|
| 75 |
my $search_field = Koha::SearchFields->find($sf->{id}); |
| 76 |
my @marc_map = $search_field->search_marc_maps; |
| 77 |
is(scalar(@marc_map), 1, 'search_marc_maps should return 1 marc map'); |
| 78 |
is($marc_map[0]->index_name, 'biblios', 'Marc map index name is biblios'); |
| 79 |
is($marc_map[0]->marc_type, 'marc21', 'Marc map type is marc21'); |
| 80 |
is($marc_map[0]->marc_field, '410abcdef', 'Marc map field is 410abcdef'); |
| 81 |
|
| 82 |
ok($search_field->is_mapped_biblios, 'Search field 1 is mapped with biblios'); |
| 83 |
|
| 84 |
my $sf2 = $builder->build({ |
| 85 |
source => 'SearchField', |
| 86 |
}); |
| 87 |
|
| 88 |
my $smm3 = $builder->build({ |
| 89 |
source => 'SearchMarcMap', |
| 90 |
value => { |
| 91 |
index_name => 'authorities', |
| 92 |
marc_type => 'marc21', |
| 93 |
marc_field => '700a' |
| 94 |
} |
| 95 |
}); |
| 96 |
|
| 97 |
my $smtf3 = $builder->build({ |
| 98 |
source => 'SearchMarcToField', |
| 99 |
value => { |
| 100 |
search_marc_map_id => $smm3->{id}, |
| 101 |
search_field_id => $sf2->{id} |
| 102 |
} |
| 103 |
}); |
| 104 |
|
| 105 |
$search_field = Koha::SearchFields->find($sf2->{id}); |
| 106 |
ok(!$search_field->is_mapped_biblios, 'Search field is mapped with authorities only'); |
| 107 |
|
| 108 |
my $smm4 = $builder->build({ |
| 109 |
source => 'SearchMarcMap', |
| 110 |
value => { |
| 111 |
index_name => 'biblios', |
| 112 |
marc_type => 'marc21', |
| 113 |
marc_field => '200a' |
| 114 |
} |
| 115 |
}); |
| 116 |
|
| 117 |
my $smtf4 = $builder->build({ |
| 118 |
source => 'SearchMarcToField', |
| 119 |
value => { |
| 120 |
search_marc_map_id => $smm4->{id}, |
| 121 |
search_field_id => $sf2->{id} |
| 122 |
} |
| 123 |
}); |
| 124 |
|
| 125 |
$search_field = Koha::SearchFields->find($sf2->{id}); |
| 126 |
ok($search_field->is_mapped_biblios, 'Search field is mapped with authorities and biblios'); |
| 127 |
|
| 128 |
my $sf3 = $builder->build({ |
| 129 |
source => 'SearchField', |
| 130 |
}); |
| 131 |
|
| 132 |
$search_field = Koha::SearchFields->find($sf3->{id}); |
| 133 |
ok(!$search_field->is_mapped_biblios, 'Search field is not mapped'); |
| 134 |
|
| 135 |
$schema->storage->txn_rollback; |