Bug 15496: (QA follow-up) Fix new uses of Koha::Biblio::items in list context
[koha-equinox.git] / t / db_dependent / Koha / Biblio.t
index 281ad65..18b3bf2 100644 (file)
@@ -17,7 +17,9 @@
 
 use Modern::Perl;
 
-use Test::More tests => 3;
+use Test::More tests => 5;
+
+use t::lib::TestBuilder;
 
 use C4::Biblio;
 use Koha::Database;
@@ -27,7 +29,8 @@ BEGIN {
     use_ok('Koha::Biblios');
 }
 
-my $schema = Koha::Database->new->schema;
+my $schema  = Koha::Database->new->schema;
+my $builder = t::lib::TestBuilder->new;
 
 subtest 'metadata() tests' => sub {
 
@@ -55,3 +58,52 @@ subtest 'metadata() tests' => sub {
 
     $schema->storage->txn_rollback;
 };
+
+subtest 'hidden_in_opac() tests' => sub {
+
+    plan tests => 3;
+
+    $schema->storage->txn_begin;
+
+    my $biblio = $builder->build_sample_biblio();
+    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
+    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
+
+    $item_1->withdrawn( 1 )->store->discard_changes;
+    $item_2->withdrawn( 1 )->store->discard_changes;
+
+    ok( !$biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio not hidden' );
+
+    $item_2->withdrawn( 2 )->store->discard_changes;
+    $biblio->discard_changes; # refresh
+
+    ok( !$biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio not hidden' );
+
+    $item_1->withdrawn( 2 )->store->discard_changes;
+    $biblio->discard_changes; # refresh
+
+    ok( $biblio->hidden_in_opac({ rules => { withdrawn => [ 2 ] } }), 'Biblio hidden' );
+
+    $schema->storage->txn_rollback;
+};
+
+subtest 'items() tests' => sub {
+
+    plan tests => 3;
+
+    $schema->storage->txn_begin;
+
+    my $biblio = $builder->build_sample_biblio();
+    my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
+    my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
+
+    my $items = $biblio->items;
+    is( ref($items), 'Koha::Items', 'Returns a Koha::Items resultset' );
+    is( $items->count, 2, 'Two items in resultset' );
+
+    my @items = $biblio->items->as_list;
+    is( scalar @items, 2, 'Same result, but in list context' );
+
+    $schema->storage->txn_rollback;
+
+};