|
Lines 1-6
Link Here
|
| 1 |
use Modern::Perl; |
1 |
use Modern::Perl; |
| 2 |
|
2 |
|
| 3 |
use Test::More tests => 37; |
3 |
use Test::More tests => 41; |
| 4 |
|
4 |
|
| 5 |
use_ok("MARC::Field"); |
5 |
use_ok("MARC::Field"); |
| 6 |
use_ok("MARC::Record"); |
6 |
use_ok("MARC::Record"); |
|
Lines 53-111
$record->append_fields(
Link Here
|
| 53 |
|
53 |
|
| 54 |
is( field_exists( $record, '650', 'a'), 'Computer programming.', '650$a exists, field_exists returns the first one' ); |
54 |
is( field_exists( $record, '650', 'a'), 'Computer programming.', '650$a exists, field_exists returns the first one' ); |
| 55 |
|
55 |
|
| 56 |
# read_field |
56 |
# Koha::SimpleMARC::read |
| 57 |
my @fields_650a = read_field( $record, '650', 'a'); |
57 |
my @fields_650a = Koha::SimpleMARC::read( $record, '650', 'a'); |
| 58 |
is( $fields_650a[0], 'Computer programming.', 'first 650$a' ); |
58 |
is( $fields_650a[0], 'Computer programming.', 'first 650$a' ); |
| 59 |
is( $fields_650a[1], 'Computer algorithms.', 'second 650$a' ); |
59 |
is( $fields_650a[1], 'Computer algorithms.', 'second 650$a' ); |
| 60 |
is( read_field( $record, '650', 'a', 1 ), 'Computer programming.', 'first 650$a bis' ); |
60 |
is( Koha::SimpleMARC::read( $record, '650', 'a', 1 ), 'Computer programming.', 'first 650$a bis' ); |
| 61 |
is( read_field( $record, '650', 'a', 2 ), 'Computer algorithms.', 'second 650$a bis' ); |
61 |
is( Koha::SimpleMARC::read( $record, '650', 'a', 2 ), 'Computer algorithms.', 'second 650$a bis' ); |
| 62 |
is( read_field( $record, '650', 'a', 3 ), undef, 'There is no 3 650$a' ); |
62 |
is( Koha::SimpleMARC::read( $record, '650', 'a', 3 ), undef, 'There is no 3 650$a' ); |
| 63 |
|
63 |
|
| 64 |
# copy_field |
64 |
# copy_field |
| 65 |
copy_field( $record, '245', 'a', '246', 'a' ); |
65 |
copy_field( $record, '245', 'a', '246', 'a' ); |
| 66 |
is_deeply( read_field( $record, '245', 'a' ), 'The art of computer programming', 'After copy 245$a still exists' ); |
66 |
is_deeply( Koha::SimpleMARC::read( $record, '245', 'a' ), 'The art of computer programming', 'After copy 245$a still exists' ); |
| 67 |
is_deeply( read_field( $record, '246', 'a' ), 'The art of computer programming', '246$a is a new field' ); |
67 |
is_deeply( Koha::SimpleMARC::read( $record, '246', 'a' ), 'The art of computer programming', '246$a is a new field' ); |
| 68 |
delete_field( $record, '246' ); |
68 |
Koha::SimpleMARC::delete( $record, '246' ); |
| 69 |
is( field_exists( $record, '246', 'a', '246$a does not exist anymore' ), undef ); |
69 |
is( field_exists( $record, '246', 'a', '246$a does not exist anymore' ), undef ); |
| 70 |
|
70 |
|
| 71 |
copy_field( $record, '650', 'a', '651', 'a' ); |
71 |
copy_field( $record, '650', 'a', '651', 'a' ); |
| 72 |
my @fields_651a = read_field( $record, '651', 'a' ); |
72 |
my @fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' ); |
| 73 |
is_deeply( \@fields_651a, ['Computer programming.', 'Computer algorithms.'], 'Copy multivalued field' ); |
73 |
is_deeply( \@fields_651a, ['Computer programming.', 'Computer algorithms.'], 'Copy multivalued field' ); |
| 74 |
delete_field( $record, '651' ); |
74 |
Koha::SimpleMARC::delete( $record, '651' ); |
| 75 |
|
75 |
|
| 76 |
copy_field( $record, '650', 'a', '651', 'a', undef, 1 ); |
76 |
copy_field( $record, '650', 'a', '651', 'a', undef, 1 ); |
| 77 |
@fields_651a = read_field( $record, '651', 'a' ); |
77 |
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' ); |
| 78 |
is_deeply( read_field( $record, '651', 'a' ), 'Computer programming.', 'Copy first field 650$a' ); |
78 |
is_deeply( Koha::SimpleMARC::read( $record, '651', 'a' ), 'Computer programming.', 'Copy first field 650$a' ); |
| 79 |
delete_field( $record, '651' ); |
79 |
Koha::SimpleMARC::delete( $record, '651' ); |
| 80 |
|
80 |
|
| 81 |
copy_field( $record, '650', 'a', '651', 'a', undef, 2 ); |
81 |
copy_field( $record, '650', 'a', '651', 'a', undef, 2 ); |
| 82 |
@fields_651a = read_field( $record, '651', 'a' ); |
82 |
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' ); |
| 83 |
is_deeply( read_field( $record, '651', 'a' ), 'Computer algorithms.', 'Copy second field 650$a' ); |
83 |
is_deeply( Koha::SimpleMARC::read( $record, '651', 'a' ), 'Computer algorithms.', 'Copy second field 650$a' ); |
| 84 |
delete_field( $record, '651' ); |
84 |
Koha::SimpleMARC::delete( $record, '651' ); |
| 85 |
|
85 |
|
| 86 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } ); |
86 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } ); |
| 87 |
@fields_651a = read_field( $record, '651', 'a' ); |
87 |
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' ); |
| 88 |
is_deeply( \@fields_651a, ['The art of programming.', 'The art of algorithms.'], 'Copy field using regex' ); |
88 |
is_deeply( \@fields_651a, ['The art of programming.', 'The art of algorithms.'], 'Copy field using regex' ); |
| 89 |
|
89 |
|
| 90 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' } ); |
90 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' } ); |
| 91 |
@fields_651a = read_field( $record, '651', 'a' ); |
91 |
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' ); |
| 92 |
is_deeply( \@fields_651a, ['The mistake of programming.', 'The mistake of algorithms.'], 'Copy fields using regex on existing fields' ); |
92 |
is_deeply( \@fields_651a, ['The mistake of programming.', 'The mistake of algorithms.'], 'Copy fields using regex on existing fields' ); |
| 93 |
delete_field( $record, '651' ); |
93 |
Koha::SimpleMARC::delete( $record, '651' ); |
| 94 |
|
94 |
|
| 95 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } ); |
95 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } ); |
| 96 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' }, 1, "dont_erase" ); |
96 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' }, 1, "dont_erase" ); |
| 97 |
@fields_651a = read_field( $record, '651', 'a' ); |
97 |
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' ); |
| 98 |
is_deeply( \@fields_651a, [ |
98 |
is_deeply( \@fields_651a, [ |
| 99 |
'The art of programming.', |
99 |
'The art of programming.', |
| 100 |
'The mistake of programming.', |
100 |
'The mistake of programming.', |
| 101 |
'The art of algorithms.', |
101 |
'The art of algorithms.', |
| 102 |
'The mistake of programming.' |
102 |
'The mistake of programming.' |
| 103 |
], 'Copy first field using regex on existing fields without erase existing values' ); |
103 |
], 'Copy first field using regex on existing fields without erase existing values' ); |
| 104 |
delete_field( $record, '651' ); |
104 |
Koha::SimpleMARC::delete( $record, '651' ); |
| 105 |
|
105 |
|
| 106 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } ); |
106 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } ); |
| 107 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' }, undef , "dont_erase" ); |
107 |
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' }, undef , "dont_erase" ); |
| 108 |
@fields_651a = read_field( $record, '651', 'a' ); |
108 |
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' ); |
| 109 |
is_deeply( \@fields_651a, [ |
109 |
is_deeply( \@fields_651a, [ |
| 110 |
'The art of programming.', |
110 |
'The art of programming.', |
| 111 |
'The mistake of programming.', |
111 |
'The mistake of programming.', |
|
Lines 114-146
is_deeply( \@fields_651a, [
Link Here
|
| 114 |
'The mistake of programming.', |
114 |
'The mistake of programming.', |
| 115 |
'The mistake of algorithms.' |
115 |
'The mistake of algorithms.' |
| 116 |
], 'Copy fields using regex on existing fields without erase existing values' ); |
116 |
], 'Copy fields using regex on existing fields without erase existing values' ); |
| 117 |
delete_field( $record, '651' ); |
117 |
Koha::SimpleMARC::delete( $record, '651' ); |
| 118 |
|
118 |
|
| 119 |
# Copy with regex modifiers |
119 |
# Copy with regex modifiers |
| 120 |
copy_field( $record, '650', 'a', '652', 'a', { search => 'o', replace => 'foo' } ); |
120 |
copy_field( $record, '650', 'a', '652', 'a', { search => 'o', replace => 'foo' } ); |
| 121 |
my @fields_652a = read_field( $record, '652', 'a' ); |
121 |
my @fields_652a = Koha::SimpleMARC::read( $record, '652', 'a' ); |
| 122 |
is_deeply( \@fields_652a, ['Cfoomputer programming.', 'Cfoomputer algorithms.'], 'Copy field using regex' ); |
122 |
is_deeply( \@fields_652a, ['Cfoomputer programming.', 'Cfoomputer algorithms.'], 'Copy field using regex' ); |
| 123 |
|
123 |
|
| 124 |
copy_field( $record, '650', 'a', '653', 'a', { search => 'o', replace => 'foo', modifiers => 'g' } ); |
124 |
copy_field( $record, '650', 'a', '653', 'a', { search => 'o', replace => 'foo', modifiers => 'g' } ); |
| 125 |
my @fields_653a = read_field( $record, '653', 'a' ); |
125 |
my @fields_653a = Koha::SimpleMARC::read( $record, '653', 'a' ); |
| 126 |
is_deeply( \@fields_653a, ['Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.'], 'Copy field using regex' ); |
126 |
is_deeply( \@fields_653a, ['Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.'], 'Copy field using regex' ); |
| 127 |
|
127 |
|
| 128 |
copy_field( $record, '650', 'a', '654', 'a', { search => 'O', replace => 'foo', modifiers => 'i' } ); |
128 |
copy_field( $record, '650', 'a', '654', 'a', { search => 'O', replace => 'foo', modifiers => 'i' } ); |
| 129 |
my @fields_654a = read_field( $record, '654', 'a' ); |
129 |
my @fields_654a = Koha::SimpleMARC::read( $record, '654', 'a' ); |
| 130 |
is_deeply( \@fields_654a, ['Cfoomputer programming.', 'Cfoomputer algorithms.'], 'Copy field using regex' ); |
130 |
is_deeply( \@fields_654a, ['Cfoomputer programming.', 'Cfoomputer algorithms.'], 'Copy field using regex' ); |
| 131 |
|
131 |
|
| 132 |
copy_field( $record, '650', 'a', '655', 'a', { search => 'O', replace => 'foo', modifiers => 'gi' } ); |
132 |
copy_field( $record, '650', 'a', '655', 'a', { search => 'O', replace => 'foo', modifiers => 'gi' } ); |
| 133 |
my @fields_655a = read_field( $record, '655', 'a' ); |
133 |
my @fields_655a = Koha::SimpleMARC::read( $record, '655', 'a' ); |
| 134 |
is_deeply( \@fields_655a, ['Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.'], 'Copy field using regex' ); |
134 |
is_deeply( \@fields_655a, ['Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.'], 'Copy field using regex' ); |
| 135 |
|
135 |
|
| 136 |
# update_field |
136 |
# update_field |
| 137 |
update_field( $record, '952', 'p', undef, '3010023918' ); |
137 |
update_field( $record, '952', 'p', undef, '3010023918' ); |
| 138 |
is_deeply( read_field( $record, '952', 'p' ), '3010023918', 'update existing subfield 952$p' ); |
138 |
is_deeply( Koha::SimpleMARC::read( $record, '952', 'p' ), '3010023918', 'update existing subfield 952$p' ); |
| 139 |
delete_field( $record, '952' ); |
139 |
Koha::SimpleMARC::delete( $record, '952' ); |
| 140 |
update_field( $record, '952', 'p', undef, '3010023918' ); |
140 |
update_field( $record, '952', 'p', undef, '3010023918' ); |
| 141 |
update_field( $record, '952', 'y', undef, 'BK' ); |
141 |
update_field( $record, '952', 'y', undef, 'BK' ); |
| 142 |
is_deeply( read_field( $record, '952', 'p' ), '3010023918', 'create subfield 952$p' ); |
142 |
is_deeply( Koha::SimpleMARC::read( $record, '952', 'p' ), '3010023918', 'create subfield 952$p' ); |
| 143 |
is_deeply( read_field( $record, '952', 'y' ), 'BK', 'create subfield 952$k on existing 952 field' ); |
143 |
is_deeply( Koha::SimpleMARC::read( $record, '952', 'y' ), 'BK', 'create subfield 952$k on existing 952 field' ); |
| 144 |
$record->append_fields( |
144 |
$record->append_fields( |
| 145 |
MARC::Field->new( |
145 |
MARC::Field->new( |
| 146 |
952, ' ', ' ', |
146 |
952, ' ', ' ', |
|
Lines 149-159
$record->append_fields(
Link Here
|
| 149 |
), |
149 |
), |
| 150 |
); |
150 |
); |
| 151 |
update_field( $record, '952', 'p', undef, '3010023919' ); |
151 |
update_field( $record, '952', 'p', undef, '3010023919' ); |
| 152 |
my @fields_952p = read_field( $record, '952', 'p' ); |
152 |
my @fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' ); |
| 153 |
is_deeply( \@fields_952p, ['3010023919', '3010023919'], 'update all subfields 952$p with the same value' ); |
153 |
is_deeply( \@fields_952p, ['3010023919', '3010023919'], 'update all subfields 952$p with the same value' ); |
| 154 |
|
154 |
|
| 155 |
update_field( $record, '952', 'p', undef, ('3010023917', '3010023918') ); |
155 |
update_field( $record, '952', 'p', undef, ('3010023917', '3010023918') ); |
| 156 |
@fields_952p = read_field( $record, '952', 'p' ); |
156 |
@fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' ); |
| 157 |
is_deeply( \@fields_952p, ['3010023917', '3010023918'], 'update all subfields 952$p with the different values' ); |
157 |
is_deeply( \@fields_952p, ['3010023917', '3010023918'], 'update all subfields 952$p with the different values' ); |
| 158 |
|
158 |
|
| 159 |
# move_field |
159 |
# move_field |
|
Lines 167-184
$record->append_fields(
Link Here
|
| 167 |
), |
167 |
), |
| 168 |
); |
168 |
); |
| 169 |
copy_field( $record, '952', 'd', '952', 'd' ); |
169 |
copy_field( $record, '952', 'd', '952', 'd' ); |
| 170 |
@fields_952d = read_field( $record, '952', 'd' ); |
170 |
@fields_952d = Koha::SimpleMARC::read( $record, '952', 'd' ); |
| 171 |
is_deeply( \@fields_952d, ['2001-06-25', '2001-06-25'], 'copy 952$d into others 952 field' ); |
171 |
is_deeply( \@fields_952d, ['2001-06-25', '2001-06-25'], 'copy 952$d into others 952 field' ); |
| 172 |
|
172 |
|
| 173 |
move_field( $record, '952', 'c', '954', 'c' ); |
173 |
move_field( $record, '952', 'c', '954', 'c' ); |
| 174 |
@fields_952c = read_field( $record, '952', 'c' ); |
174 |
@fields_952c = Koha::SimpleMARC::read( $record, '952', 'c' ); |
| 175 |
@fields_954c = read_field( $record, '954', 'c' ); |
175 |
@fields_954c = Koha::SimpleMARC::read( $record, '954', 'c' ); |
| 176 |
is_deeply( \@fields_952c, [], 'The 952$c has moved' ); |
176 |
is_deeply( \@fields_952c, [], 'The 952$c has moved' ); |
| 177 |
is_deeply( \@fields_954c, ['GEN'], 'Now 954$c exists' ); |
177 |
is_deeply( \@fields_954c, ['GEN'], 'Now 954$c exists' ); |
| 178 |
|
178 |
|
| 179 |
move_field( $record, '952', 'p', '954', 'p', undef, 1 ); # Move the first field |
179 |
move_field( $record, '952', 'p', '954', 'p', undef, 1 ); # Move the first field |
| 180 |
@fields_952p = read_field( $record, '952', 'p' ); |
180 |
@fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' ); |
| 181 |
@fields_954p = read_field( $record, '954', 'p' ); |
181 |
@fields_954p = Koha::SimpleMARC::read( $record, '954', 'p' ); |
| 182 |
is_deeply( \@fields_952p, ['3010023917'], 'One of 952$p has moved' ); |
182 |
is_deeply( \@fields_952p, ['3010023917'], 'One of 952$p has moved' ); |
| 183 |
is_deeply( \@fields_954p, ['3010023917'], 'Now 954$p exists' ); |
183 |
is_deeply( \@fields_954p, ['3010023917'], 'Now 954$p exists' ); |
| 184 |
|
184 |
|
|
Lines 192-199
$record->append_fields(
Link Here
|
| 192 |
); |
192 |
); |
| 193 |
|
193 |
|
| 194 |
move_field( $record, '952', 'p', '954', 'p' ); # Move all field |
194 |
move_field( $record, '952', 'p', '954', 'p' ); # Move all field |
| 195 |
@fields_952p = read_field( $record, '952', 'p' ); |
195 |
@fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' ); |
| 196 |
@fields_954p = read_field( $record, '954', 'p' ); |
196 |
@fields_954p = Koha::SimpleMARC::read( $record, '954', 'p' ); |
| 197 |
is_deeply( \@fields_952p, [], 'All 952$p have moved' ); |
197 |
is_deeply( \@fields_952p, [], 'All 952$p have moved' ); |
| 198 |
is_deeply( \@fields_954p, ['3010023917', '3010023917'], 'Now 2 954$p exist' ); |
198 |
is_deeply( \@fields_954p, ['3010023917', '3010023917'], 'Now 2 954$p exist' ); |
| 199 |
|
199 |
|
|
|
200 |
# delete |
| 201 |
$record = new_record; |
| 202 |
Koha::SimpleMARC::delete( $record, '952' ); |
| 203 |
my @fields_952 = Koha::SimpleMARC::read( $record, '952' ); |
| 204 |
is_deeply( \@fields_952, [], 'Delete all 952, 1 deleted' ); |
| 205 |
|
| 206 |
$record = new_record; |
| 207 |
$record->append_fields( |
| 208 |
MARC::Field->new( |
| 209 |
952, ' ', ' ', |
| 210 |
p => '3010023917', |
| 211 |
y => 'BK', |
| 212 |
), |
| 213 |
); |
| 214 |
Koha::SimpleMARC::delete( $record, '952' ); |
| 215 |
@fields_952 = Koha::SimpleMARC::read( $record, '952' ); |
| 216 |
is_deeply( \@fields_952, [], 'Delete all 952, 2 deleted' ); |
| 217 |
|
| 218 |
$record = new_record; |
| 219 |
$record->append_fields( |
| 220 |
MARC::Field->new( |
| 221 |
952, ' ', ' ', |
| 222 |
p => '3010023917', |
| 223 |
y => 'BK', |
| 224 |
), |
| 225 |
); |
| 226 |
Koha::SimpleMARC::delete( $record, '952', 'p', 1 ); |
| 227 |
@fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' ); |
| 228 |
is_deeply( \@fields_952p, ['3010023917'], 'Delete first 952$p' ); |
| 229 |
|
| 230 |
$record = new_record; |
| 231 |
$record->append_fields( |
| 232 |
MARC::Field->new( |
| 233 |
952, ' ', ' ', |
| 234 |
p => '3010023917', |
| 235 |
y => 'BK', |
| 236 |
), |
| 237 |
); |
| 238 |
Koha::SimpleMARC::delete( $record, '952', 'p' ); |
| 239 |
@fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' ); |
| 240 |
is_deeply( \@fields_952p, [], 'Delete all 952$p' ); |