Bug 19209: (QA followup) Improve tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Wed, 30 Aug 2017 15:30:05 +0000 (12:30 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 1 Sep 2017 16:00:06 +0000 (13:00 -0300)
This path merges the pager() test and adds search results count tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Koha/Objects.t

index b382ce1..069c2c8 100644 (file)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 16;
+use Test::More tests => 15;
 use Test::Warn;
 
 use Koha::Authority::Types;
@@ -74,12 +74,6 @@ subtest 'update' => sub {
     is( Koha::Cities->search( { city_country => 'UK' } )->count, 0, 'Koha::Objects->update should have updated the 3 rows' );
 };
 
-subtest 'pager' => sub {
-    plan tests => 1;
-    my $pager = Koha::Patrons->search( {}, { page => 1, rows => 2 } )->pager;
-    is( ref($pager), 'DBIx::Class::ResultSet::Pager', 'Koha::Objects->pager returns a valid DBIx::Class object' );
-};
-
 subtest 'reset' => sub {
     plan tests => 3;
 
@@ -215,20 +209,31 @@ subtest 'Exceptions' => sub {
 
 $schema->storage->txn_rollback;
 
-subtest '->is_paged tests' => sub {
+subtest '->is_paged and ->pager tests' => sub {
 
-    plan tests => 2;
+    plan tests => 5;
 
     $schema->storage->txn_begin;
 
+    # Delete existing patrons
+    Koha::Patrons->search->delete;
+    # Create 10 patrons
     foreach (1..10) {
         $builder->build_object({ class => 'Koha::Patrons' });
     }
 
+    # Non-paginated search
     my $patrons = Koha::Patrons->search();
+    is( $patrons->count, 10, 'Search returns all patrons' );
     ok( !$patrons->is_paged, 'Search is not paged' );
+
+    # Paginated search
     $patrons = Koha::Patrons->search( undef, { 'page' => 1, 'rows' => 3 } );
+    is( $patrons->count, 3, 'Search returns only one page, 3 patrons' );
     ok( $patrons->is_paged, 'Search is paged' );
+    my $pager = $patrons->pager;
+    is( ref($patrons->pager), 'DBIx::Class::ResultSet::Pager',
+       'Koha::Objects->pager returns a valid DBIx::Class object' );
 
     $schema->storage->txn_rollback;
 }