From 269057719f4324af1f8f8eec3b0b388b51fea144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Demians?= Date: Wed, 28 Oct 2015 17:25:57 +0100 Subject: [PATCH] Bug 13146 UT Run the test before applying the second patch: prove -v t/db_dependent/FieldMapping.t Apply the 2nd patch, and redo the test. --- t/db_dependent/FieldMapping.t | 100 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100755 t/db_dependent/FieldMapping.t diff --git a/t/db_dependent/FieldMapping.t b/t/db_dependent/FieldMapping.t new file mode 100755 index 0000000..87a8d4b --- /dev/null +++ b/t/db_dependent/FieldMapping.t @@ -0,0 +1,100 @@ +#!/usr/bin/perl + +# Copyright 2015 Tamil s.a.r.l. +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; +use File::Basename; +use File::Path; +use DateTime; +use Test::MockModule; +use Test::More tests => 18; +use C4::Biblio; +use Koha::Schema; + + + +use Test::DBIx::Class { + schema_class => 'Koha::Schema', + connect_info => ['dbi:SQLite:dbname=:memory:','',''], + connect_opts => { name_sep => '.', quote_char => '`', }, + fixture_class => '::Populate', +}, 'Fieldmapping' ; + + +# Make the code in the module use our mocked Koha::Schema/Koha::Database +my $db = Test::MockModule->new('Koha::Database'); +$db->mock( + # Schema() gives us the DB connection set up by Test::DBIx::Class + _new_schema => sub { return Schema(); } +); + + +if (0) { + fixtures_ok [ + Fieldmapping => [ + [ qw/ field fieldcode subfieldcode / ], + [ qw / subtitle 245 b / ], + [ qw / maintiel 245 a / ], + ], + ], 'add fixtures for two field mappings'; +} + + +SetFieldMapping('', 'maintitle', '245', 'a'); +ok my $fm = Fieldmapping->find( {field => 'maintitle'} ) + => 'maintitle field mapping properly set for default framework'; + +SetFieldMapping('', 'subtitle', '245', 'b'); +ok $fm = Fieldmapping->find( {field => 'subtitle'} ) + => 'subtitle field mapping properly set for default framework'; +is_fields $fm, { + frameworkcode => '', + field => 'subtitle', + fieldcode => '245', + subfieldcode => 'b', +}, 'expected fields are there'; + +SetFieldMapping('BOOK', 'subtitle', '245', 'b'); +ok $fm = Fieldmapping->find( {frameworkcode => 'BOOK', field => 'subtitle'} ) + => 'subtitle field mapping properly set for BOOK framework'; +is_fields $fm, { + frameworkcode => 'BOOK', + field => 'subtitle', + fieldcode => '245', + subfieldcode => 'b', +}, 'expected fields are there'; + +my $fms = GetFieldMapping(''); +is(@$fms, 2, "2 mappings for default framework"); +is($fms->[0]->{id}, '1', "id is '1'"); +is($fms->[0]->{frameworkcode}, '', "frameworkcode is ''"); +is($fms->[0]->{field}, 'maintitle', "field is 'maintile'"); +is($fms->[0]->{fieldcode}, '245', "fieldcode is '245'"); +is($fms->[0]->{subfieldcode}, 'a', "subfieldcode is 'a'"); + +DeleteFieldMapping(1); +$fms = GetFieldMapping(''); +is(@$fms, 1, "1 mappings for default framework after calling DeleteFieldMapping()"); +is($fms->[0]->{id}, '2', "id is '1'"); +is($fms->[0]->{frameworkcode}, '', "frameworkcode is ''"); +is($fms->[0]->{field}, 'subtitle', "field is 'subtile'"); +is($fms->[0]->{fieldcode}, '245', "fieldcode is '245'"); +is($fms->[0]->{subfieldcode}, 'b', "subfieldcode is 'b'"); + +$fms = GetFieldMapping('BOOK'); +is(@$fms, 1, "1 mapping for BOOK framework"); -- 2.6.2