Bug 14100: Fix Search.t tests
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 28 Oct 2015 10:43:55 +0000 (10:43 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Thu, 29 Oct 2015 11:47:33 +0000 (08:47 -0300)
commitd9426ddfc5c4b9bc91f39117e7a96adc1aae47ef
tree41e7067ccd28cf1d6254465794de8992538943fd
parent4c103508b2d631a2b70dda005763b4d50b3d289b
Bug 14100: Fix Search.t tests

So, this one is VERY weird, let me try to explain what I have
understood.

Bisecting using run prove t/db_dependent/Search.t, I have found that the
following commit make the test fail:
  commit 0f63f89f66e40cc01ef02da3654fcfb404c9001d
    Bug 14100: Generic solution for language overlay - Item types
The error is
  DBI bind_columns: invalid number of arguments: got handle + 0, expected handle + between 1 and -1
  Usage: $h->bind_columns(\$var1 [, \$var2, ...]) at /usr/lib/i386-linux-gnu/perl5/5.20/DBI.pm line 2065.

Note that the interface (admin/itemtypes.pl) which calls the same
subroutine with the same parameter (style => 'array') works great.

The problem comes from the change in C4::Search::searchResults, if I
only apply the change done to this subroutine on 0f63f89f^1, I reproduce
the issue.

Looking closely at how %itemtypes is built, we could actually call
GetItemTypes with the style => 'hash' to get exactly what we want.
The following piece prove it for you:
    use Test::More;
    use C4::Koha;
    my $i = GetItemTypes;
    my $j = GetItemTypes(style => 'array');
    my %itemtypes;
    for my $itemtype ( @$j ) {
        $itemtypes{ $itemtype->{itemtype} } = $itemtype;
    }
    is_deeply( \%itemtypes, $i);

So changing the code accordingly and just forget this last hour...

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/Search.pm