View | Details | Raw Unified | Return to bug 11413
Collapse All | Expand All

(-)a/t/db_dependent/MarcModificationTemplates.t (-7 / +46 lines)
Lines 1-6 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
use Test::More tests => 74;
3
use Test::More tests => 77;
4
4
5
use_ok("MARC::Field");
5
use_ok("MARC::Field");
6
use_ok("MARC::Record");
6
use_ok("MARC::Record");
Lines 146-161 my @USERENV = ( Link Here
146
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
146
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
147
C4::Context->set_userenv ( @USERENV );
147
C4::Context->set_userenv ( @USERENV );
148
148
149
$template_id = AddModificationTemplate("template_name");
149
$template_id = AddModificationTemplate("new_template_test");
150
like( $template_id, qr|^\d+$|, "new template returns an id" );
150
like( $template_id, qr|^\d+$|, "new template returns an id" );
151
151
152
is( AddModificationTemplateAction(
152
is( AddModificationTemplateAction(
153
    $template_id, 'delete_field', 0,
154
    '245', '', '', '', '', '',
155
    '', '', '',
156
    'if', '245', 'a', 'equals', 'Bad title', '',
157
    'Delete field 245 if 245$a eq "Bad title"'
158
), 1, 'Add first action: delete field 245 if 245$a eq "Bad title"');
159
160
is( AddModificationTemplateAction(
153
    $template_id, 'copy_field', 0,
161
    $template_id, 'copy_field', 0,
154
    '245', 'a', '', '246', 'a',
162
    '245', 'a', '', '246', 'a',
155
    '', '', '',
163
    '', '', '',
156
    '', '', '', '', '', '',
164
    '', '', '', '', '', '',
157
    'copy field 245$a to 246$a'
165
    'copy field 245$a to 246$a'
158
), 1, 'Add first action: copy 245$a to 246$a');
166
), 1, 'Add second action: copy 245$a to 246$a');
159
167
160
is( AddModificationTemplateAction(
168
is( AddModificationTemplateAction(
161
    $template_id, 'delete_field', 0,
169
    $template_id, 'delete_field', 0,
Lines 163-169 is( AddModificationTemplateAction( Link Here
163
    '', '', '',
171
    '', '', '',
164
    'if', '650', '9', 'equals', '462', '',
172
    'if', '650', '9', 'equals', '462', '',
165
    'Delete field 650$a if 650$9=462'
173
    'Delete field 650$a if 650$9=462'
166
), 1, 'Add second action: delete field 650$a if 650$9=462');
174
), 1, 'Add third action: delete field 650$a if 650$9=462');
167
175
168
is( AddModificationTemplateAction(
176
is( AddModificationTemplateAction(
169
    $template_id, 'update_field', 0,
177
    $template_id, 'update_field', 0,
Lines 171-177 is( AddModificationTemplateAction( Link Here
171
    '', '', '',
179
    '', '', '',
172
    'unless', '650', '9', 'equals', '42', '',
180
    'unless', '650', '9', 'equals', '42', '',
173
    'Update field 952$p with "3010023917_updated" if 650$9 != 42'
181
    'Update field 952$p with "3010023917_updated" if 650$9 != 42'
174
), 1, 'Add third action: update field 952$p with "3010023917_updated" if 650$9 != 42');
182
), 1, 'Add fourth action: update field 952$p with "3010023917_updated" if 650$9 != 42');
175
183
176
is( AddModificationTemplateAction(
184
is( AddModificationTemplateAction(
177
    $template_id, 'move_field', 0,
185
    $template_id, 'move_field', 0,
Lines 179-185 is( AddModificationTemplateAction( Link Here
179
    '', '', '',
187
    '', '', '',
180
    'if', '952', 'c', 'equals', '^GEN', '1',
188
    'if', '952', 'c', 'equals', '^GEN', '1',
181
    'Move field 952$d to 952$e if 952$c =~ /^GE/'
189
    'Move field 952$d to 952$e if 952$c =~ /^GE/'
182
), 1, 'Add fourth action: move field 952$d to 952$e if 952$c =~ /^GE/');
190
), 1, 'Add fifth action: move field 952$d to 952$e if 952$c =~ /^GE/');
191
192
is( AddModificationTemplateAction(
193
    $template_id, 'update_field', 0,
194
    '650', 'a', 'Computer algorithms.', '', '', '',
195
    '', '', '',
196
    'if', '650', '9', 'equals', '499', '',
197
    'Update field 650$a with "Computer algorithms." to 651 if 650$9 == 499'
198
), 1, 'Add sixth action: update field 650$a with "Computer algorithms." if 650$9 == 499');
199
200
is( AddModificationTemplateAction(
201
    $template_id, 'move_field', 0,
202
    '650', '', '', '651', '', '',
203
    '', '', '',
204
    'if', '650', '9', 'equals', '499', '',
205
    'Move field 650 to 651 if 650$9 == 499'
206
), 1, 'Add seventh action: move field 650 to 651 if 650$9 == 499');
207
183
208
184
my $record = new_record();
209
my $record = new_record();
185
210
Lines 205-215 sub new_record { Link Here
205
            c => 'Donald E. Knuth.',
230
            c => 'Donald E. Knuth.',
206
        ),
231
        ),
207
        MARC::Field->new(
232
        MARC::Field->new(
233
            245, '1', '4',
234
            a => 'field to remove',
235
            c => 'Donald E. Knuth.',
236
        ),
237
        MARC::Field->new(
208
            650, ' ', '0',
238
            650, ' ', '0',
209
            a => 'Computer programming.',
239
            a => 'Computer programming.',
210
            9 => '462',
240
            9 => '462',
211
        ),
241
        ),
212
        MARC::Field->new(
242
        MARC::Field->new(
243
            650, ' ', '0',
244
            a => 'Computer programming.',
245
            9 => '499',
246
        ),
247
        MARC::Field->new(
213
            952, ' ', ' ',
248
            952, ' ', ' ',
214
            p => '3010023917',
249
            p => '3010023917',
215
            y => 'BK',
250
            y => 'BK',
Lines 250-255 sub expected_record { Link Here
250
            246, '', ' ',
285
            246, '', ' ',
251
            a => 'The art of computer programming',
286
            a => 'The art of computer programming',
252
        ),
287
        ),
288
        MARC::Field->new(
289
            651, ' ', '0',
290
            a => 'Computer algorithms.',
291
            9 => '499',
292
        ),
253
    );
293
    );
254
    $record->append_fields(@fields);
294
    $record->append_fields(@fields);
255
    return $record;
295
    return $record;
256
- 

Return to bug 11413