use Modern::Perl;
-use Test::More tests => 11;
+use Test::More tests => 12;
use C4::Biblio;
use Koha::Database;
$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;
+};
use Modern::Perl;
-use Test::More tests => 6;
+use Test::More tests => 5;
use Test::Exception;
use MARC::Field;
};
-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' } );