Bug 5404: Move the test to a new IsMarcStructureInternal sub
[koha.git] / t / db_dependent / Biblio.t
index 31bd958..e23dc34 100755 (executable)
 
 use Modern::Perl;
 
-use Test::More tests => 5;
+use Test::More tests => 6;
 use Test::MockModule;
 
+use List::MoreUtils qw( uniq );
 use MARC::Record;
 use t::lib::Mocks qw( mock_preference );
 
@@ -37,11 +38,19 @@ my $context = new Test::MockModule('C4::Context');
 
 mock_marcfromkohafield();
 
-my $currency = new Test::MockModule('C4::Budgets');
-$currency->mock( 'GetCurrency', sub {
-    return { symbol   => '$',   isocode  => 'USD',
-             currency => 'USD', active => 1 };
-});
+my $currency = new Test::MockModule('Koha::Acquisition::Currencies');
+$currency->mock(
+    'get_active',
+    sub {
+        return Koha::Acquisition::Currency->new(
+            {   symbol   => '$',
+                isocode  => 'USD',
+                currency => 'USD',
+                active   => 1,
+            }
+        );
+    }
+);
 
 sub run_tests {
 
@@ -315,4 +324,23 @@ subtest 'GetMarcSubfieldStructureFromKohaField' => sub {
     is($marc_subfield_structure, undef, "invalid kohafield returns undef");
 };
 
+subtest 'IsMarcStructureInternal' => sub {
+    plan tests => 6;
+    my $tagslib = GetMarcStructure();
+    my @internals;
+    for my $tag ( sort keys %$tagslib ) {
+        next unless $tag;
+        for my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
+            push @internals, $subfield if IsMarcStructureInternal($tagslib->{$tag}{$subfield});
+        }
+    }
+    @internals = uniq @internals;
+    is( scalar(@internals), 4, '');
+    is( grep( /^lib$/, @internals ), 1, '' );
+    is( grep( /^tab$/, @internals ), 1, '' );
+    is( grep( /^mandatory$/, @internals ), 1, '' );
+    is( grep( /^repeatable$/, @internals ), 1, '' );
+    is( grep( /^a$/, @internals ), 0, '' );
+};
+
 1;