Koha/t/db_dependent/OAI/AndSets.t
Jonathan Druart f1f9c6dc74 Bug 26384: Fix executable flags
.pm must not have -x
.t must have -x
.pl must have -x

Test plan:
Apply only the first patch, run the tests and confirm that the failures
make sense
Apply this patch and confirm that the test now returns green

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2020-09-11 09:56:56 +02:00

181 lines
5 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2019 BibLibre
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 4;
use Test::MockModule;
use Test::Warn;
use MARC::Record;
use Data::Dumper;
use Koha::Database;
use C4::Biblio;
use C4::OAI::Sets;
use t::lib::TestBuilder;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
my $dbh = C4::Context->dbh;
$dbh->do('DELETE FROM oai_sets');
$dbh->do('DELETE FROM oai_sets_descriptions');
$dbh->do('DELETE FROM oai_sets_mappings');
$dbh->do('DELETE FROM oai_sets_biblios');
my $builder = t::lib::TestBuilder->new;
my $set1 = {
'spec' => 'specSet1',
'name' => 'nameSet1',
};
my $set1_id = AddOAISet($set1);
my $marcflavour = C4::Context->preference('marcflavour');
my $mapping1;
if ($marcflavour eq 'UNIMARC' ){
$mapping1 = [
{
rule_order => 1,
marcfield => '200',
marcsubfield => 'a',
operator => 'equal',
marcvalue => 'myTitle'
},
{
rule_order => 2,
rule_operator => 'and',
marcfield => '200',
marcsubfield => 'f',
operator => 'equal',
marcvalue => 'myAuthor'
},
];
} else {
$mapping1 = [
{
rule_order => 1,
marcfield => '245',
marcsubfield => 'a',
operator => 'equal',
marcvalue => 'myTitle'
},
{
rule_order => 2,
rule_operator => 'and',
marcfield => '100',
marcsubfield => 'a',
operator => 'equal',
marcvalue => 'myAuthor'
},
];
}
#Add 1st mapping for set1
ModOAISetMappings($set1_id, $mapping1);
my $biblio_1 = $builder->build_sample_biblio({ title => 'myTitle' });
my $biblio_2 = $builder->build_sample_biblio({ title => 'myTitle', author => 'myAuthor' });
my $biblionumber1 = $biblio_1->biblionumber;
my $biblionumber2 = $biblio_2->biblionumber;
my $record = GetMarcBiblio({ biblionumber => $biblionumber1 });
my @setsEq = CalcOAISetsBiblio($record);
ok(!@setsEq, 'If only one condition is true, the record does not belong to the set');
$record = GetMarcBiblio({ biblionumber => $biblionumber2 });
@setsEq = CalcOAISetsBiblio($record);
is_deeply(@setsEq, $set1_id, 'If all conditions are true, the record belongs to the set');
if ($marcflavour eq 'UNIMARC' ){
$mapping1 = [
{
rule_order => 1,
marcfield => '200',
marcsubfield => 'a',
operator => 'equal',
marcvalue => 'myTitle'
},
{
rule_order => 2,
rule_operator => 'or',
marcfield => '200',
marcsubfield => 'f',
operator => 'equal',
marcvalue => 'myAuthor'
},
{
rule_order => 3,
rule_operator => 'and',
marcfield => '995',
marcsubfield => 'r',
operator => 'equal',
marcvalue => 'myItemType'
},
];
} else {
$mapping1 = [
{
rule_order => 1,
marcfield => '245',
marcsubfield => 'a',
operator => 'equal',
marcvalue => 'myTitle'
},
{
rule_order => 2,
rule_operator => 'or',
marcfield => '100',
marcsubfield => 'a',
operator => 'equal',
marcvalue => 'myAuthor'
},
{
rule_order => 3,
rule_operator => 'and',
marcfield => '942',
marcsubfield => 'c',
operator => 'equal',
marcvalue => 'myItemType'
},
];
}
ModOAISetMappings($set1_id, $mapping1);
$biblio_1 = $builder->build_sample_biblio({ title => 'myTitle' });
$biblio_2 = $builder->build_sample_biblio({ author => 'myAuthor', itemtype => 'myItemType' });
$biblionumber1 = $biblio_1->biblionumber;
$biblionumber2 = $biblio_2->biblionumber;
$record = GetMarcBiblio({ biblionumber => $biblionumber1 });
@setsEq = CalcOAISetsBiblio($record);
is_deeply(@setsEq, $set1_id, 'Boolean operators precedence is respected, the record with only the title belongs to the set');
$record = GetMarcBiblio({ biblionumber => $biblionumber2 });
@setsEq = CalcOAISetsBiblio($record);
is_deeply(@setsEq, $set1_id, 'Boolean operators precedence is respected, the record with author and itemtype belongs to the set');
$schema->storage->txn_rollback;