Bug 9031: (QA follow-up) Pass the same timezone in Calendar.t
[koha.git] / t / db_dependent / MarcModificationTemplates.t
index f54527e..d2fcffc 100644 (file)
@@ -1,6 +1,6 @@
 use Modern::Perl;
 
-use Test::More tests => 94;
+use Test::More tests => 96;
 
 use Koha::SimpleMARC;
 
@@ -336,6 +336,47 @@ is_deeply( \@fields_245a, [
         'Bad title'
     ], 'delete field has been deleted the right field"' );
 
+subtest 'GetModificationTemplates' => sub {
+    plan tests => 1;
+    $dbh->do(q|DELETE FROM marc_modification_templates|);
+    AddModificationTemplate("zzz");
+    AddModificationTemplate("aaa");
+    AddModificationTemplate("mmm");
+    my @templates = GetModificationTemplates();
+    is_deeply( [map{$_->{name}} @templates], ['aaa', 'mmm', 'zzz'] );
+};
+
+subtest "not_equals" => sub {
+    plan tests => 2;
+    $dbh->do(q|DELETE FROM marc_modification_templates|);
+    my $template_id = AddModificationTemplate("template_name");
+    AddModificationTemplateAction(
+        $template_id, 'move_field', 0,
+        '650', '', '', '651', '',
+        '', '', '',
+        'if', '650', '9', 'not_equals', '499', '',
+        'Move field 650 to 651 if 650$9 != 499'
+    );
+    my $record = new_record();
+    ModifyRecordWithTemplate( $template_id, $record );
+    my $expected_record = expected_record_2();
+    is_deeply( $record, $expected_record, '650 has been moved to 651 when 650$9 != 499' );
+
+    $dbh->do(q|DELETE FROM marc_modification_templates|);
+    $template_id = AddModificationTemplate("template_name");
+    AddModificationTemplateAction(
+        $template_id, 'move_field', 0,
+        '650', '', '', '651', '',
+        '', '', '',
+        'if', '650', 'b', 'not_equals', '499', '',
+        'Move field 650 to 651 if 650$b != 499'
+    );
+    $record = new_record();
+    ModifyRecordWithTemplate( $template_id, $record );
+    $expected_record = new_record();
+    is_deeply( $record, $expected_record, 'None 650 have been moved, no $650$b exists' );
+};
+
 sub new_record {
     my $record = MARC::Record->new;
     $record->leader('03174nam a2200445 a 4500');
@@ -434,29 +475,27 @@ sub expected_record_2 {
             a => 'The art of computer programming',
             c => 'Donald E. Knuth.',
         ),
+        MARC::Field->new(
+            245, '1', '4',
+            a => 'Bad title',
+            c => 'Donald E. Knuth.',
+        ),
         MARC::Field->new(
             650, ' ', '0',
-            9 => '462',
+            a => 'Computer programming.',
+            9 => '499',
         ),
         MARC::Field->new(
             952, ' ', ' ',
-            p => '3010023917_updated',
+            p => '3010023917',
             y => 'BK',
             c => 'GEN',
-            e => '2001-06-25',
-        ),
-        MARC::Field->new(
-            246, '', ' ',
-            a => 'The art of computer programming',
+            d => '2001-06-25',
         ),
         MARC::Field->new(
             651, ' ', '0',
-            a => 'Computer algorithms.',
-            9 => '499',
-        ),
-        MARC::Field->new(
-            999, ' ', ' ',
-            a => 'non existent.',
+            a => 'Computer programming.',
+            9 => '462',
         ),
     );
     $record->append_fields(@fields);