1 package KohaTest::Biblio::ModBiblio;
2 use base qw( KohaTest::Biblio );
12 =head2 STARTUP METHODS
14 These get run once, before the main test methods in this module
16 =head3 add_bib_to_modify
20 sub add_bib_to_modify : Test( startup => 3 ) {
23 my $bib = MARC::Record->new();
24 $bib->leader(' ngm a22 7a 4500');
26 MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
27 MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'),
30 my ($bibnum, $bibitemnum) = AddBiblio($bib, '');
31 $self->{'bib_to_modify'} = $bibnum;
34 my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => 'CPL', holdingbranch => 'CPL' } , $bibnum);
36 cmp_ok($item_bibnum, '==', $bibnum, "new item is linked to correct biblionumber");
37 cmp_ok($item_bibitemnum, '==', $bibitemnum, "new item is linked to correct biblioitemnumber");
39 $self->reindex_marc();
41 my $marc = $self->fetch_bib($bibnum);
42 $self->sort_item_and_bibnumber_fields($marc);
43 $self->{'bib_to_modify_formatted'} = $marc->as_formatted(); # simple way to compare later
52 Regression test for bug 2297 (saving a subscription duplicates MARC item fields)
56 sub bug_2297 : Test( 5 ) {
59 my $bibnum = $self->{'bib_to_modify'};
60 my $marc = $self->fetch_bib($bibnum);
61 $self->check_item_count($marc, 1);
63 ModBiblio($marc, $bibnum, ''); # no change made to bib
65 my $modified_marc = $self->fetch_bib($bibnum);
66 diag "checking item field count after null modification";
67 $self->check_item_count($modified_marc, 1);
69 $self->sort_item_and_bibnumber_fields($modified_marc);
70 is($modified_marc->as_formatted(), $self->{'bib_to_modify_formatted'}, "no change to bib after null modification");
75 These methods are used by other test methods, but
76 are not meant to be called directly.
84 sub fetch_bib { # +1 to test count per call
88 my $marc = GetMarcBiblio($bibnum);
89 ok(defined($marc), "retrieved bib record $bibnum");
94 =head3 check_item_count
98 sub check_item_count { # +1 to test count per call
101 my $expected_items = shift;
103 my ($itemtag, $itemsubfield) = GetMarcFromKohaField("items.itemnumber", '');
104 my @item_fields = $marc->field($itemtag);
105 cmp_ok(scalar(@item_fields), "==", $expected_items, "exactly one item field");
108 =head3 sort_item_and_bibnumber_fields
110 This method sorts the field containing the embedded item data
111 and the bibnumber - ModBiblio(), AddBiblio(), and ModItem() do
112 not guarantee that these fields will be sorted in tag order.
116 sub sort_item_and_bibnumber_fields {
120 my ($itemtag, $itemsubfield) = GetMarcFromKohaField("items.itemnumber", '');
121 my ($bibnumtag, $bibnumsubfield) = GetMarcFromKohaField("biblio.biblionumber", '');
123 my @item_fields = ();
124 foreach my $field ($marc->field($itemtag)) {
125 push @item_fields, $field;
126 $marc->delete_field($field);
128 $marc->insert_fields_ordered(@item_fields) if scalar(@item_fields);;
130 my @bibnum_fields = ();
131 foreach my $field ($marc->field($bibnumtag)) {
132 push @bibnum_fields, $field;
133 $marc->delete_field($field);
135 $marc->insert_fields_ordered(@bibnum_fields) if scalar(@bibnum_fields);
139 =head2 SHUTDOWN METHODS
141 These get run once, after the main test methods in this module
143 =head3 shutdown_clean_object
147 sub shutdown_clean_object : Test( shutdown => 0 ) {
150 delete $self->{'bib_to_modify'};
151 delete $self->{'bib_to_modify_formatted'};