Bug 21832: add unit test
[koha.git] / t / Koha.t
index 366a21b..b8d4346 100755 (executable)
--- a/t/Koha.t
+++ b/t/Koha.t
@@ -25,7 +25,7 @@ use Module::Load::Conditional qw/check_install/;
 
 BEGIN {
     if ( check_install( module => 'Test::DBIx::Class' ) ) {
-        plan tests => 33;
+        plan tests => 38;
     } else {
         plan skip_all => "Need Test::DBIx::Class"
     }
@@ -33,35 +33,26 @@ BEGIN {
 
 use_ok('C4::Koha');
 
-use Test::DBIx::Class {
-    schema_class => 'Koha::Schema',
-    connect_info => ['dbi:SQLite:dbname=:memory:','',''],
-    connect_opts => { name_sep => '.', quote_char => '`', },
-    fixture_class => '::Populate',
-}, 'AuthorisedValue' ;
+use Test::DBIx::Class;
 
 sub fixtures {
-    my ( $data ) = @_;
+    my ( $libraries ) = @_;
     fixtures_ok [
-        AuthorisedValue => [
-            [ 'category', 'authorised_value' ],
-            @$data,
-        ],
+        Branch => [
+            ['branchcode', 'branchname'],
+            @$libraries,
+        ]
     ], 'add fixtures';
 }
 
 my $db = Test::MockModule->new('Koha::Database');
 $db->mock( _new_schema => sub { return Schema(); } );
+Koha::Database::flush_schema_cache();
 
-my $authorised_values = [
-    ['LOC', 'LOC'],
-    ['RELTERMS', 'RELTERMS'],
+my $libraries = [
+    ['XXX_test', 'my branchname XXX'],
 ];
-fixtures($authorised_values);
-
-is ( IsAuthorisedValueCategory('LOC'), 1, 'LOC is a valid authorized value category');
-is ( IsAuthorisedValueCategory('something'), 0, 'something is not a valid authorized value category');
-is ( IsAuthorisedValueCategory('RELTERMS'), 1, 'RELTERMS is a valid authorized value category');
+fixtures($libraries);
 
 my $isbn13 = "9780330356473";
 my $isbn13D = "978-0-330-35647-3";
@@ -117,4 +108,46 @@ is( C4::Koha::GetNormalizedISBN(), undef, 'GetNormalizedISBN should return undef
 is( C4::Koha::GetNormalizedEAN(), undef, 'GetNormalizedEAN should return undef if no record and no isbn are passed' );
 is( C4::Koha::GetNormalizedOCLCNumber(), undef, 'GetNormalizedOCLCNumber should return undef if no record and no isbn are passed' );
 
-1;
+subtest 'getFacets() tests' => sub {
+    plan tests => 5;
+
+    is ( Koha::Libraries->search->count, 1, 'There should be only 1 library (singleBranchMode on)' );
+    my $facets = C4::Koha::getFacets();
+    is(
+        scalar( grep { defined $_->{idx} && $_->{idx} eq 'location' } @$facets ),
+        1,
+        'location facet present with singleBranchMode on (bug 10078)'
+    );
+
+    $libraries = [
+        ['YYY_test', 'my branchname YYY'],
+        ['ZZZ_test', 'my branchname XXX'],
+    ];
+    fixtures($libraries);
+    is ( Koha::Libraries->search->count, 3, 'There should be only more than 1 library (singleBranchMode off)' );
+
+    $facets = C4::Koha::getFacets();
+    is(
+        scalar( grep { defined $_->{idx} && $_->{idx} eq 'location' } @$facets ),
+        1,
+        'location facet present with singleBranchMode off (bug 10078)'
+    );
+};
+
+is(C4::Koha::NormalizeISSN({ issn => '0024-9319', strip_hyphen => 1 }), '00249319', 'Test NormalizeISSN with all features enabled' );
+is(C4::Koha::NormalizeISSN({ issn => '0024-9319', strip_hyphen => 0 }), '0024-9319', 'Test NormalizeISSN with all features enabled' );
+
+my @issns = qw/ 0024-9319 00249319 /;
+is( join('|', @issns), join('|', GetVariationsOfISSN('0024-9319')), 'GetVariationsOfISSN returns all variations' );
+is( join('|', @issns), join('|', GetVariationsOfISSNs('0024-9319')), 'GetVariationsOfISSNs returns all variations' );
+
+my $issn;
+eval {
+    $issn = C4::Koha::NormalizeISSN({ issn => '1234-5678', strip_hyphen => 1 });
+};
+ok($@ eq '', 'NormalizeISSN does not throw exception when parsing invalid ISSN');
+
+@issns = GetVariationsOfISSNs('abc');
+is($issns[0], 'abc', 'Original ISSN passed through even if invalid');
+is(scalar(@issns), 1, 'zero additional variations returned of invalid ISSN');
+