Bug 4941: Make tests non DB dependent

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2016-01-06 10:41:21 +00:00 committed by Kyle M Hall
parent a1bd7af5fb
commit 92c37ef4e2
2 changed files with 39 additions and 25 deletions

View File

@ -25,7 +25,7 @@ use Module::Load::Conditional qw/check_install/;
BEGIN {
if ( check_install( module => 'Test::DBIx::Class' ) ) {
plan tests => 33;
plan tests => 34;
} else {
plan skip_all => "Need Test::DBIx::Class"
}
@ -38,15 +38,19 @@ use Test::DBIx::Class {
connect_info => ['dbi:SQLite:dbname=:memory:','',''],
connect_opts => { name_sep => '.', quote_char => '`', },
fixture_class => '::Populate',
}, 'AuthorisedValue' ;
}, 'AuthorisedValue', 'Branch' ;
sub fixtures {
my ( $data ) = @_;
my ( $av, $libraries ) = @_;
fixtures_ok [
AuthorisedValue => [
[ 'category', 'authorised_value' ],
@$data,
@$av,
],
Branch => [
['branchcode', 'branchname'],
@$libraries,
]
], 'add fixtures';
}
@ -57,7 +61,10 @@ my $authorised_values = [
['LOC', 'LOC'],
['RELTERMS', 'RELTERMS'],
];
fixtures($authorised_values);
my $libraries = [
['XXX_test', 'my branchname XXX'],
];
fixtures($authorised_values, $libraries);
is ( IsAuthorisedValueCategory('LOC'), 1, 'LOC is a valid authorized value category');
is ( IsAuthorisedValueCategory('something'), 0, 'something is not a valid authorized value category');
@ -117,4 +124,30 @@ 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' );
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($authorised_values, $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)'
);
};
1;

View File

@ -8,7 +8,7 @@ use C4::Context;
use Koha::DateUtils qw(dt_from_string);
use Koha::AuthorisedValue;
use Test::More tests => 10;
use Test::More tests => 9;
use DateTime::Format::MySQL;
BEGIN {
@ -258,25 +258,6 @@ subtest 'ISBN tests' => sub {
};
subtest 'getFacets() tests' => sub {
plan tests => 2;
C4::Context->set_preference('singleBranchMode', 0);
my $facets = C4::Koha::getFacets();
is(
scalar( grep { defined $_->{idx} && $_->{idx} eq 'location' } @$facets ),
1,
'location facet present with singleBranchMode off (bug 10078)'
);
C4::Context->set_preference('singleBranchMode', 1);
$facets = C4::Koha::getFacets();
is(
scalar( grep { defined $_->{idx} && $_->{idx} eq 'location' } @$facets ),
1,
'location facet present with singleBranchMode on (bug 10078)'
);
};
subtest 'GetFrameworksLoop() tests' => sub {
plan tests => 6;