From c63c0a11533b4a7687c5ad27d5507faa1fbe1b8a Mon Sep 17 00:00:00 2001 From: Bouzid Fergani Date: Fri, 7 Oct 2016 12:38:35 -0400 Subject: [PATCH] Bug5620 - Add tests for sub GetKohaAuthorisedValues --- t/Koha.t | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/t/Koha.t b/t/Koha.t index 21cbf68..1187c3b 100755 --- 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 => 31; + plan tests => 32; } else { plan skip_all => "Need Test::DBIx::Class" } @@ -138,4 +138,31 @@ subtest 'getFacets() tests' => sub { ); }; -1; +subtest 'GetKohaAuthorisedValues() tests' => sub { + plan tests => 6; + my $values; + is( C4::Koha::GetKohaAuthorisedValues('','','',''), undef, 'Test GetKohaAuthorisedValues with empty parameters values'); + + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare("INSERT INTO authorised_values (category,authorised_value,lib,lib_opac) VALUES (?, ?, ?, ?)"); + my $sth1 = $dbh->prepare("INSERT INTO marc_subfield_structure VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + + $sth->execute('TESTMODE','TestDebit','TestDebitstaff','TestDebitopac'); + $sth->execute('TESTMODE','TestCC','TestCCstaff','TestCCopac'); + $sth->execute('TESTFIELD','TestCC','TestCCstaff','TestCCopac'); + $sth1->execute(999,'z','Test','Test',0,0,'TestFieldKoha',10,'TESTMODE','','',0,0,'','','','',9999); + + $values = C4::Koha::GetKohaAuthorisedValues('TestFieldKoha'); + ok($values->{TestCC} eq 'TestCCstaff','GetKohaAuthorisedValues return the correct value when put kohafield parameter and empty for other parameters'); + + is (C4::Koha::GetKohaAuthorisedValues('TestFieldNotExist'), undef ,'GetKohaAuthorisedValues return undef when kohafield not exist'); + + $values = C4::Koha::GetKohaAuthorisedValues('','','','TESTMODE'); + ok(keys %$values eq 2,'GetKohaAuthorisedValues return the correct number of result'); + ok($values->{TestCC} eq 'TestCCstaff','GetKohaAuthorisedValues return a correct value when put category parameter and empty for other parameters'); + + $values = C4::Koha::GetKohaAuthorisedValues('','',1,'TESTMODE'); + ok($values->{TestDebit} eq 'TestDebitopac','GetKohaAuthorisedValues return a correct value when put category,opac parameter and empty for other parameters'); +}; + +-1; -- 1.9.1