--
--
Henri-Damien LAURENT
BibLibre SARL
http://www.biblibre.com
Expert en Logiciels Libres pour l'info-doc
tel : +33 4 67 65 75 50
From 7861c3fdb75ca0f3a426756325e3173ccb0db04b Mon Sep 17 00:00:00 2001
From: Henri-Damien LAURENT <[email protected]>
Date: Wed, 16 Sep 2009 18:51:28 +0200
Subject: [PATCH] Adding Test for ModMarcItem
---
t/db_dependent/Items.t | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 68 insertions(+), 0 deletions(-)
create mode 100644 t/db_dependent/Items.t
diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t
new file mode 100644
index 0000000..cd54b64
--- /dev/null
+++ b/t/db_dependent/Items.t
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+#
+# This Koha test module is a stub!
+# Add more tests here!!!
+
+use strict;
+use warnings;
+use YAML;
+use C4::Items;
+use C4::Biblio;
+use C4::Debug;
+use List::MoreUtils qw(:all);
+use Test::More tests => 3;
+
+BEGIN {
+ use_ok('C4::Items');
+}
+
+my $biblio=MARC::Record->new;
+$biblio->append_fields(MARC::Field->new("200",' ',' ',f=>"Test"));
+my ($biblionumber, $biblioitemnumber)=AddBiblio($biblio,"");
+my $item=MARC::Record->new;
+my $itemfield=MARC::Field->new("995",' ',' ',f=>"123456789012",x=>"AAA");
+$item->append_fields($itemfield);
+my ($biblionumber, $biblioitemnumber,$itemnumber)=AddItemFromMarc($item,$biblionumber);
+my $bibliorecord=GetMarcBiblio($biblionumber);
+ok(Matchfield($itemfield,$bibliorecord->field(995),"fx"),"AddItemFromMarc preserves itemfield");
+warn $itemfield->as_formatted,"\n",$bibliorecord->field('995')->as_formatted;
+my $tmpmarcrecord=MARC::Record->new;
+#$tmpmarcrecord->append_fields($itemfield);
+#$tmpmarcrecord=MARC::Record->new;
+$itemfield->update(f=>"987654321");
+$itemfield->update(b=>"U1BUCG");
+$itemfield->update(v=>"Petite Note au passage");
+$itemfield->update(x=>"RAEDS");
+my $field=MARC::Field->new('100'," ", " ", a=>"Monchamp de test");
+$tmpmarcrecord->append_fields($field,$itemfield);
+ModItemFromMarc($tmpmarcrecord,$biblionumber,$itemnumber);
+$debug && warn $tmpmarcrecord->as_formatted;
+$bibliorecord=GetMarcBiblio($biblionumber);
+ok(Matchfield($itemfield,$bibliorecord->field(995),"fbvx"),"ModItemFromMarc preserves itemfield");
+
+=head2 Matchfield
+ Given
+ a reference field
+ a possible Match field
+ a string of subfields to use
+ Returns 1 if both matches 0 otherwise
+ USED in SearchAuthority
+ Uses normalize_string (otherwise you may have some funny problems)
+
+ Sample code :
+ my $boolean=Matchfield (MARC::Field->new(600,'','',a,Bicyclette),MARC::Field->new(610,'','',a,Bicyclette,x,BMX),'a')
+ boolean =1
+=cut
+
+sub Matchfield{
+ my ($searchfield,$field,$keysstring)=...@_;
+ my @subfields=$searchfield->subfields();
+ my $result=1;
+ foreach my $subfield (@subfields){
+ next unless index($keysstring,$$subfield[0])>=0;
+ $debug && warn "$$subfield[0] $$subfield[1] ".$field->subfield($$subfield[0]);
+ $result= $result && any {$debug && warn "$$subfield[0] $_ $$subfield[1]";$_ eq $$subfield[1]} $field->subfield($$subfield[0]);
+ $debug && warn "$result";
+ }
+ return $result;
+}
--
1.6.0.4
_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches