3 # Copyright 2019 BibLibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Test::More tests => 4;
31 use t::lib::TestBuilder;
33 my $schema = Koha::Database->new->schema;
34 $schema->storage->txn_begin;
35 my $dbh = C4::Context->dbh;
37 $dbh->do('DELETE FROM oai_sets');
38 $dbh->do('DELETE FROM oai_sets_descriptions');
39 $dbh->do('DELETE FROM oai_sets_mappings');
40 $dbh->do('DELETE FROM oai_sets_biblios');
42 my $builder = t::lib::TestBuilder->new;
48 my $set1_id = AddOAISet($set1);
50 my $marcflavour = C4::Context->preference('marcflavour');
53 if ($marcflavour eq 'UNIMARC' ){
60 marcvalue => 'myTitle'
64 rule_operator => 'and',
68 marcvalue => 'myAuthor'
78 marcvalue => 'myTitle'
82 rule_operator => 'and',
86 marcvalue => 'myAuthor'
91 #Add 1st mapping for set1
92 ModOAISetMappings($set1_id, $mapping1);
94 my $biblio_1 = $builder->build_sample_biblio({ title => 'myTitle' });
95 my $biblio_2 = $builder->build_sample_biblio({ title => 'myTitle', author => 'myAuthor' });
97 my $biblionumber1 = $biblio_1->biblionumber;
98 my $biblionumber2 = $biblio_2->biblionumber;
101 my $record = GetMarcBiblio({ biblionumber => $biblionumber1 });
102 my @setsEq = CalcOAISetsBiblio($record);
103 ok(!@setsEq, 'If only one condition is true, the record does not belong to the set');
105 $record = GetMarcBiblio({ biblionumber => $biblionumber2 });
106 @setsEq = CalcOAISetsBiblio($record);
107 is_deeply(@setsEq, $set1_id, 'If all conditions are true, the record belongs to the set');
109 if ($marcflavour eq 'UNIMARC' ){
116 marcvalue => 'myTitle'
120 rule_operator => 'or',
124 marcvalue => 'myAuthor'
128 rule_operator => 'and',
132 marcvalue => 'myItemType'
143 marcvalue => 'myTitle'
147 rule_operator => 'or',
151 marcvalue => 'myAuthor'
155 rule_operator => 'and',
159 marcvalue => 'myItemType'
164 ModOAISetMappings($set1_id, $mapping1);
166 $biblio_1 = $builder->build_sample_biblio({ title => 'myTitle' });
167 $biblio_2 = $builder->build_sample_biblio({ author => 'myAuthor', itemtype => 'myItemType' });
169 $biblionumber1 = $biblio_1->biblionumber;
170 $biblionumber2 = $biblio_2->biblionumber;
172 $record = GetMarcBiblio({ biblionumber => $biblionumber1 });
173 @setsEq = CalcOAISetsBiblio($record);
175 is_deeply(@setsEq, $set1_id, 'Boolean operators precedence is respected, the record with only the title belongs to the set');
177 $record = GetMarcBiblio({ biblionumber => $biblionumber2 });
178 @setsEq = CalcOAISetsBiblio($record);
179 is_deeply(@setsEq, $set1_id, 'Boolean operators precedence is respected, the record with author and itemtype belongs to the set');
181 $schema->storage->txn_rollback;