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

(-)a/t/SimpleMARC.t (-2 / +38 lines)
Lines 74-86 subtest 'field_exists' => sub { Link Here
74
subtest 'read_field' => sub {
74
subtest 'read_field' => sub {
75
    plan tests              => 2;
75
    plan tests              => 2;
76
    subtest 'read subfield' => sub {
76
    subtest 'read subfield' => sub {
77
        plan tests => 5;
77
        plan tests => 6;
78
        my $record = new_record;
78
        my $record = new_record;
79
        $record->append_fields(
79
        $record->append_fields(
80
            MARC::Field->new(
80
            MARC::Field->new(
81
                650, ' ', '0',
81
                650, ' ', '0',
82
                a => 'Computer algorithms.',
82
                a => 'Computer algorithms.',
83
                9 => '463',
83
                9 => '463',
84
            ),
85
            MARC::Field->new(
86
                600, ' ', '0',
87
                0 => '123456',
84
            )
88
            )
85
        );
89
        );
86
90
Lines 130-135 subtest 'read_field' => sub { Link Here
130
            [],
134
            [],
131
            'There is no 3 650$a'
135
            'There is no 3 650$a'
132
        );
136
        );
137
        is_deeply(
138
            [
139
                read_field(
140
                    {
141
                        record        => $record,
142
                        field         => '600',
143
                        subfield      => '0',
144
                        field_numbers => [1]
145
                    }
146
                )
147
            ],
148
            ['123456'],
149
            'first 600$0'
150
        );
133
    };
151
    };
134
    subtest 'read field' => sub {
152
    subtest 'read field' => sub {
135
        plan tests => 4;
153
        plan tests => 4;
Lines 191-197 subtest 'read_field' => sub { Link Here
191
subtest 'update_field' => sub {
209
subtest 'update_field' => sub {
192
    plan tests                => 1;
210
    plan tests                => 1;
193
    subtest 'update subfield' => sub {
211
    subtest 'update subfield' => sub {
194
        plan tests => 5;
212
        plan tests => 6;
195
        my $record = new_record;
213
        my $record = new_record;
196
214
197
        update_field(
215
        update_field(
Lines 250-255 subtest 'update_field' => sub { Link Here
250
                952, ' ', ' ',
268
                952, ' ', ' ',
251
                p => '3010023917',
269
                p => '3010023917',
252
                y => 'BK',
270
                y => 'BK',
271
                0 => '123456',
253
            ),
272
            ),
254
        );
273
        );
255
        update_field(
274
        update_field(
Lines 283-288 subtest 'update_field' => sub { Link Here
283
            [ '3010023917', '3010023918' ],
302
            [ '3010023917', '3010023918' ],
284
            'update all subfields 952$p with the different values'
303
            'update all subfields 952$p with the different values'
285
        );
304
        );
305
306
        update_field(
307
            {
308
                record   => $record,
309
                field    => '952',
310
                subfield => '0',
311
                values   => [ '654321' ]
312
            }
313
        );
314
        my @fields_9520 =
315
          read_field( { record => $record, field => '952', subfield => '0' } );
316
        is_deeply(
317
            \@fields_9520,
318
            [ '654321', '654321' ],
319
            'update all subfields 952$0 with the same value'
320
        );
321
286
    };
322
    };
287
};
323
};
288
324
(-)a/t/db_dependent/MarcModificationTemplates.t (-3 / +133 lines)
Lines 1-6 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
use Test::More tests => 115;
3
use Test::More tests => 125;
4
4
5
use Koha::Database;
5
use Koha::Database;
6
use Koha::SimpleMARC;
6
use Koha::SimpleMARC;
Lines 55-61 is( AddModificationTemplateAction( Link Here
55
# Getter
55
# Getter
56
56
57
my @actions = GetModificationTemplateActions( $template_id );
57
my @actions = GetModificationTemplateActions( $template_id );
58
is( @actions, 4, "4 actions are insered");
58
is( @actions, 4, "4 actions are inserted");
59
59
60
for my $action ( @actions ) {
60
for my $action ( @actions ) {
61
    isnt( GetModificationTemplateAction( $action->{mmta_id} ), undef, "action with id $action->{mmta_id} exists" );
61
    isnt( GetModificationTemplateAction( $action->{mmta_id} ), undef, "action with id $action->{mmta_id} exists" );
Lines 546-548 sub expected_record_2 { Link Here
546
    $record->append_fields(@fields);
546
    $record->append_fields(@fields);
547
    return $record;
547
    return $record;
548
}
548
}
549
- 
549
550
# Tests related to use of subfield 0 ($0)
551
552
sub new_record_0 {
553
    my $record = MARC::Record->new;
554
    $record->leader('03174nam a2200445 a 4500');
555
    my @fields = (
556
        MARC::Field->new(
557
            100, '1', ' ',
558
            0 => '12345',
559
            a => 'Knuth, Donald Ervin',
560
            d => '1938',
561
        ),
562
        MARC::Field->new(
563
            245, '1', '4',
564
            0 => '12345',
565
            a => 'The art of computer programming',
566
            c => 'Donald E. Knuth.',
567
        ),
568
        MARC::Field->new(
569
            650, ' ', '0',
570
            0 => '42',
571
            a => 'Computer programming.',
572
            9 => '462',
573
        ),
574
    );
575
    $record->append_fields(@fields);
576
    return $record;
577
}
578
579
sub expected_record_0 {
580
    my $record = MARC::Record->new;
581
    $record->leader('03174nam a2200445 a 4500');
582
    my @fields = (
583
        MARC::Field->new(
584
            245, '1', '4',
585
            0 => '12345',
586
            a => 'The art of computer programming',
587
            c => 'Donald E. Knuth.',
588
        ),
589
        MARC::Field->new(
590
            650, ' ', '0',
591
            0 => '42',
592
            a => 'Computer programming.',
593
            9 => '462',
594
        ),
595
        MARC::Field->new(
596
            600, ' ', ' ',
597
            0 => 'TestUpdated',
598
        ),
599
        MARC::Field->new(
600
            100, ' ', ' ',
601
            0 => 'TestUpdated',
602
        ),
603
        MARC::Field->new(
604
            700, '1', '4',
605
            0 => '12345',
606
            a => 'The art of computer programming',
607
            c => 'Donald E. Knuth.',
608
        ),
609
    );
610
    $record->append_fields(@fields);
611
    return $record;
612
}
613
614
$record = new_record_0();
615
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" );
616
617
$template_id = AddModificationTemplate("template_test_subfield_0");
618
like( $template_id, qr|^\d+$|, "new template returns an id" );
619
620
# Delete subfield 100$0
621
is( AddModificationTemplateAction(
622
    $template_id, 'delete_field', 0,
623
    '100', '0', '', '', '',
624
    '', '', '',
625
    '', '', '', '', '', '',
626
    'Action 1: Delete subfield 100$0'
627
), 1, 'Action 1: Delete subfield 100$0');
628
629
# Add new subfield 100$0 with value "Test"
630
is( AddModificationTemplateAction(
631
    $template_id, 'add_field', 0,
632
    '100', '0', 'Test', '', '',
633
    '', '', '',
634
    '', '', '', '', '', '',
635
    'Action 2: Add new subfield 100$0 with value "Test"'
636
), 1, 'Action 2: Add new subfield 100$0');
637
638
# Update existing or add new subfield 100$0 with value "TestUpdated"
639
is( AddModificationTemplateAction(
640
    $template_id, 'update_field', 0,
641
    '100', '0', 'TestUpdated', '', '',
642
    '', '', '',
643
    '', '', '', '', '', '',
644
    'Action 3: Update existing or add new subfield 100$0 with value "TestUpdated"'
645
), 1, 'Action 3: Update existing or add new subfield 100$0 with value "TestUpdated"');
646
647
# Move subfield 100$0 to 600$0
648
is( AddModificationTemplateAction(
649
    $template_id, 'move_field', 0,
650
    '100', '0', '', '600', '0',
651
    '', '', '',
652
    '', '', '', '', '', '',
653
    'Action 4: Move subfield 100$0 to 600$0'
654
), 1, 'Action 4: Move subfield 100$0 to 600$0');
655
656
# Copy subfield 600$0 to 100$0
657
is( AddModificationTemplateAction(
658
    $template_id, 'copy_field', 0,
659
    '600', '0', '', '100', '0',
660
    '', '', '',
661
    '', '', '', '', '', '',
662
    'Action 5: Copy subfield 600$0 to 100$0'
663
), 1, 'Action 5: Copy subfield 600$0 to 100$0');
664
665
# Copy and replace subfield 245$0 to 700$0
666
is( AddModificationTemplateAction(
667
    $template_id, 'copy_and_replace_field', 0,
668
    '245', '0', '', '700', '0',
669
    '', '', '',
670
    '', '', '', '', '', '',
671
    'Action 6: Copy and replace subfield 245$0 to 700$0'
672
), 1, 'Action 6: Copy and replace subfield 245$0 to 700$0');
673
674
my @actions_0 = GetModificationTemplateActions( $template_id );
675
is( @actions_0, 6, "6 actions are inserted");
676
677
ModifyRecordWithTemplate( $template_id, $record );
678
my $expected_record_0 = expected_record_0();
679
is_deeply( $record, $expected_record_0, '100$0 has been deleted, added back, updated, moved to 600$0, and copied back to 100$0; finally, 245$0 has been copied and replaced to 700$0' );

Return to bug 17510