|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2015 Tamil s.a.r.l. |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 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 |
| 10 |
# version. |
| 11 |
# |
| 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. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License along |
| 17 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
| 18 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use File::Basename; |
| 22 |
use File::Path; |
| 23 |
use DateTime; |
| 24 |
use Test::MockModule; |
| 25 |
use Test::More tests => 18; |
| 26 |
use C4::Biblio; |
| 27 |
use Koha::Schema; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
use Test::DBIx::Class { |
| 32 |
schema_class => 'Koha::Schema', |
| 33 |
connect_info => ['dbi:SQLite:dbname=:memory:','',''], |
| 34 |
connect_opts => { name_sep => '.', quote_char => '`', }, |
| 35 |
fixture_class => '::Populate', |
| 36 |
}, 'Fieldmapping' ; |
| 37 |
|
| 38 |
|
| 39 |
# Make the code in the module use our mocked Koha::Schema/Koha::Database |
| 40 |
my $db = Test::MockModule->new('Koha::Database'); |
| 41 |
$db->mock( |
| 42 |
# Schema() gives us the DB connection set up by Test::DBIx::Class |
| 43 |
_new_schema => sub { return Schema(); } |
| 44 |
); |
| 45 |
|
| 46 |
|
| 47 |
if (0) { |
| 48 |
fixtures_ok [ |
| 49 |
Fieldmapping => [ |
| 50 |
[ qw/ field fieldcode subfieldcode / ], |
| 51 |
[ qw / subtitle 245 b / ], |
| 52 |
[ qw / maintiel 245 a / ], |
| 53 |
], |
| 54 |
], 'add fixtures for two field mappings'; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
SetFieldMapping('', 'maintitle', '245', 'a'); |
| 59 |
ok my $fm = Fieldmapping->find( {field => 'maintitle'} ) |
| 60 |
=> 'maintitle field mapping properly set for default framework'; |
| 61 |
|
| 62 |
SetFieldMapping('', 'subtitle', '245', 'b'); |
| 63 |
ok $fm = Fieldmapping->find( {field => 'subtitle'} ) |
| 64 |
=> 'subtitle field mapping properly set for default framework'; |
| 65 |
is_fields $fm, { |
| 66 |
frameworkcode => '', |
| 67 |
field => 'subtitle', |
| 68 |
fieldcode => '245', |
| 69 |
subfieldcode => 'b', |
| 70 |
}, 'expected fields are there'; |
| 71 |
|
| 72 |
SetFieldMapping('BOOK', 'subtitle', '245', 'b'); |
| 73 |
ok $fm = Fieldmapping->find( {frameworkcode => 'BOOK', field => 'subtitle'} ) |
| 74 |
=> 'subtitle field mapping properly set for BOOK framework'; |
| 75 |
is_fields $fm, { |
| 76 |
frameworkcode => 'BOOK', |
| 77 |
field => 'subtitle', |
| 78 |
fieldcode => '245', |
| 79 |
subfieldcode => 'b', |
| 80 |
}, 'expected fields are there'; |
| 81 |
|
| 82 |
my $fms = GetFieldMapping(''); |
| 83 |
is(@$fms, 2, "2 mappings for default framework"); |
| 84 |
is($fms->[0]->{id}, '1', "id is '1'"); |
| 85 |
is($fms->[0]->{frameworkcode}, '', "frameworkcode is ''"); |
| 86 |
is($fms->[0]->{field}, 'maintitle', "field is 'maintile'"); |
| 87 |
is($fms->[0]->{fieldcode}, '245', "fieldcode is '245'"); |
| 88 |
is($fms->[0]->{subfieldcode}, 'a', "subfieldcode is 'a'"); |
| 89 |
|
| 90 |
DeleteFieldMapping(1); |
| 91 |
$fms = GetFieldMapping(''); |
| 92 |
is(@$fms, 1, "1 mappings for default framework after calling DeleteFieldMapping()"); |
| 93 |
is($fms->[0]->{id}, '2', "id is '1'"); |
| 94 |
is($fms->[0]->{frameworkcode}, '', "frameworkcode is ''"); |
| 95 |
is($fms->[0]->{field}, 'subtitle', "field is 'subtile'"); |
| 96 |
is($fms->[0]->{fieldcode}, '245', "fieldcode is '245'"); |
| 97 |
is($fms->[0]->{subfieldcode}, 'b', "subfieldcode is 'b'"); |
| 98 |
|
| 99 |
$fms = GetFieldMapping('BOOK'); |
| 100 |
is(@$fms, 1, "1 mapping for BOOK framework"); |