Bug 24448: Unit tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 17 Jan 2020 14:17:33 +0000 (11:17 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 28 Jan 2020 14:56:28 +0000 (14:56 +0000)
This patch adds tests for the new method to be introduced. It also moves
the tests for Koha::Biblio->subscriptions to the Biblio.t where it
really belongs.

To test, run this tests along with the patch implementing the new
method.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
t/db_dependent/Koha/Biblio.t
t/db_dependent/Koha/Biblios.t

index 59dc5a5..363a080 100644 (file)
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 11;
+use Test::More tests => 12;
 
 use C4::Biblio;
 use Koha::Database;
@@ -541,3 +541,38 @@ subtest 'orders() and active_orders_count() tests' => sub {
 
     $schema->storage->txn_rollback;
 };
+
+subtest 'subscriptions() and subscriptions_count() tests' => sub {
+
+    plan tests => 6;
+
+    $schema->storage->txn_begin;
+
+    my $biblio = $builder->build_sample_biblio;
+
+    my $subscriptions = $biblio->subscriptions;
+    is( ref($subscriptions), 'Koha::Subscriptions',
+        'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
+    );
+    is( $subscriptions->count, 0, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
+    is( $biblio->subscriptions_count, 0, 'subscriptions_count returns the correct number' );
+
+    # Add two subscriptions
+    foreach (1..2) {
+        $builder->build_object(
+            {
+                class => 'Koha::Subscriptions',
+                value => { biblionumber => $biblio->biblionumber }
+            }
+        );
+    }
+
+    $subscriptions = $biblio->subscriptions;
+    is( ref($subscriptions), 'Koha::Subscriptions',
+        'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
+    );
+    is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
+    is( $biblio->subscriptions_count, 2, 'subscriptions_count returns the correct number' );
+
+    $schema->storage->txn_rollback;
+};
index d44d566..2d5acbb 100644 (file)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 6;
+use Test::More tests => 5;
 use Test::Exception;
 use MARC::Field;
 
@@ -81,22 +81,6 @@ subtest 'holds + current_holds' => sub {
 
 };
 
-subtest 'subscriptions' => sub {
-    plan tests => 2;
-    $builder->build(
-        { source => 'Subscription', value => { biblionumber => $biblio->id } }
-    );
-    $builder->build(
-        { source => 'Subscription', value => { biblionumber => $biblio->id } }
-    );
-    my $biblio        = Koha::Biblios->find( $biblio->id );
-    my $subscriptions = $biblio->subscriptions;
-    is( ref($subscriptions), 'Koha::Subscriptions',
-        'Koha::Biblio->subscriptions should return a Koha::Subscriptions object'
-    );
-    is( $subscriptions->count, 2, 'Koha::Biblio->subscriptions should return the correct number of subscriptions');
-};
-
 subtest 'waiting_or_in_transit' => sub {
     plan tests => 4;
     my $biblio = $builder->build( { source => 'Biblio' } );