Bug 21912: Add tests for Koha::Objects->search
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 29 Nov 2018 14:59:05 +0000 (11:59 -0300)
committerFridolin Somers <fridolin.somers@biblibre.com>
Wed, 30 Jan 2019 08:01:55 +0000 (09:01 +0100)
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 7669697732e3abf3b2c5a32446115d277be7342e)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 464dcd7d9e2e7ba4e604ef0e7b5665dd8cd8b9b3)

Signed-off-by: Jesse Maseto <jesse@bywatersolutions.com>
(cherry picked from commit dc096dafe6453bbb7412da799f5acc0fff5da781)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

t/db_dependent/Koha/Objects.t

index 0a72664..d9533f5 100644 (file)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 14;
+use Test::More tests => 15;
 use Test::Warn;
 
 use Koha::Authority::Types;
@@ -252,4 +252,30 @@ subtest '->is_paged and ->pager tests' => sub {
        'Koha::Objects->pager returns a valid DBIx::Class object' );
 
     $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;
+};