From c90dcfe574e45d2b5eb0380815feedc79540c28d Mon Sep 17 00:00:00 2001 From: Blou Date: Mon, 2 Jun 2014 15:58:34 -0400 Subject: [PATCH] Bug 10937 - Add unit tests. Modified t/db_dependant/Koha.t to test the two new functions from C4/Koha.pm. --- t/db_dependent/Koha.t | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha.t b/t/db_dependent/Koha.t index 0e90403..71d3bbb 100644 --- a/t/db_dependent/Koha.t +++ b/t/db_dependent/Koha.t @@ -8,11 +8,11 @@ use warnings; use C4::Context; use Koha::DateUtils qw(dt_from_string); -use Test::More tests => 7; +use Test::More tests => 8; use DateTime::Format::MySQL; BEGIN { - use_ok('C4::Koha', qw( :DEFAULT GetDailyQuote )); + use_ok('C4::Koha', qw( :DEFAULT GetDailyQuote GetItemTypesByCategory GetItemTypesCategorized)); use_ok('C4::Members'); } @@ -261,3 +261,34 @@ subtest 'getFacets() tests' => sub { 'location facet present with singleBranchMode on (bug 10078)' ); }; + +subtest 'GetItemTypesByCategory GetItemTypesCategorized test' => sub{ + plan tests => 7; + + my $insertGroup = AddAuthorisedValue('DOCTYPECAT', 'Qwertyware'); + ok($insertGroup, "Create group Qwertyware"); + + my $query = "INSERT into itemtypes (itemtype, description, searchcategory, hideinopac) values (?,?,?,?)"; + my $insertSth = C4::Context->dbh->prepare($query); + $insertSth->execute('BKghjklo1', 'One type of book', '', 0); + $insertSth->execute('BKghjklo2', 'Another type of book', 'Qwertyware', 0); + $insertSth->execute('BKghjklo3', 'Yet another type of book', 'Qwertyware', 0); + # test for empty result + my @results = GetItemTypesByCategory('Azertyware'); + is(scalar @results, 0, 'GetItemTypesByCategory: Invalid category returns nothing'); + @results = GetItemTypesByCategory('Qwertyware'); + is($results[1], 'BKghjklo3', 'GetItemTypesByCategory: valid category returns itemtypes'); + + # add more data since GetItemTypesCategorized's search is more subtle + $insertSth->execute('BKghjklo4', 'An hidden book', 'Qwertyware', 1); + AddAuthorisedValue('DOCTYPECAT', 'Veryveryheavybook'); + $insertSth->execute('BKghjklo5', 'Some encyclopedia', 'Veryveryheavybook', 0); + $insertSth->execute('BKghjklo6', 'A collection of dictionnary', 'Veryveryheavybook', 0); + # get the grouped itemtypes. + my $hrCat = GetItemTypesCategorized(); + ok(exists $hrCat->{Qwertyware}, 'GetItemTypesCategorized: first category exists'); + ok(exists $hrCat->{Veryveryheavybook}, 'GetItemTypesCategorized: second category exists'); + ok(exists $hrCat->{BKghjklo1}, 'GetItemTypesCategorized: ungrouped item exists'); + ok(!exists $hrCat->{BKghjklo2}, 'GetItemTypesCategorized: grouped itemtype not returned'); +} + -- 1.7.9.5