Bug 21912: Add tests for Koha::Objects->search

This patch adds simple tests for the current behaviour. Specifically the
return values in both scalar and list context.

To test:
- Apply this patch
- Run:
  $ prove t/db_dependent/Koha/Objects.t
=> SUCCESS: Tests pass
- Sign off :-D

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 7669697732)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomas Cohen Arazi 2018-11-29 11:59:05 -03:00 committed by Martin Renvoize
parent 5e1efa83f7
commit 464dcd7d9e
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 27 additions and 1 deletions

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 14;
use Test::More tests => 15;
use Test::Exception;
use Test::Warn;
@ -254,3 +254,29 @@ subtest '->is_paged and ->pager tests' => sub {
$schema->storage->txn_rollback;
};
subtest '->search() tests' => sub {
plan tests => 12;
$schema->storage->txn_begin;
Koha::Patrons->delete;
# Create 10 patrons
foreach (1..10) {
$builder->build_object({ class => 'Koha::Patrons' });
}
my $patrons = Koha::Patrons->search();
is( ref($patrons), 'Koha::Patrons', 'search in scalar context returns the Koha::Object-based type' );
my @patrons = Koha::Patrons->search();
is( scalar @patrons, 10, 'search in list context returns a list of objects' );
my $i = 0;
foreach (1..10) {
is( ref($patrons[$i]), 'Koha::Patron', 'Objects in the list have the singular type' );
$i++;
}
$schema->storage->txn_rollback;
};