Bug 22571: Add tests
[koha-equinox.git] / t / SimpleMARC.t
index 5958508..4812e31 100644 (file)
@@ -1,6 +1,6 @@
 use Modern::Perl;
 
-use Test::More tests => 10;
+use Test::More tests => 11;
 
 use_ok("MARC::Field");
 use_ok("MARC::Record");
@@ -11,6 +11,9 @@ sub new_record {
     $record->leader('03174nam a2200445 a 4500');
     my @fields = (
         MARC::Field->new(
+            '008', '120829t20132012nyu bk 001 0ceng',
+        ),
+        MARC::Field->new(
             100, '1', ' ',
             a => 'Knuth, Donald Ervin',
             d => '1938',
@@ -1693,3 +1696,47 @@ subtest 'delete_field' => sub {
         is_deeply( \@fields_952, [], 'Delete all 952, 2 deleted' );
     };
 };
+
+subtest 'field_equals' => sub {
+    plan tests => 2;
+    my $record = new_record;
+    subtest 'standard MARC fields' => sub {
+        plan tests => 2;
+        my $match = Koha::SimpleMARC::field_equals({
+                record => $record,
+                value => 'Donald',
+                field => '100',
+                subfield => 'a',
+            });
+        is_deeply( $match, [], '100$a not equal to "Donald"' );
+
+        $match = Koha::SimpleMARC::field_equals({
+                record => $record,
+                value => 'Donald',
+                field => '100',
+                subfield => 'a',
+                is_regex => 1,
+            });
+        is_deeply( $match, [1], 'first 100$a matches "Donald"');
+    };
+
+    subtest 'control fields' => sub {
+        plan tests => 2;
+        my $match = Koha::SimpleMARC::field_equals({
+                record => $record,
+                value => 'eng',
+                field => '008',
+                subfield => '',
+            });
+        is_deeply( $match, [], '008 control field not equal to "Donald"' );
+
+        $match = Koha::SimpleMARC::field_equals({
+                record => $record,
+                value => 'eng',
+                field => '008',
+                subfield => '',
+                is_regex => 1,
+            });
+        is_deeply( $match, [1], 'first 008 control field matches "Donald"' );
+    };
+};