Bug 22701: Unit tests for Koha::Biblio->items
authorTomas Cohen Arazi <tomascohen@theke.io>
Sat, 20 Apr 2019 12:47:43 +0000 (09:47 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Wed, 24 Apr 2019 10:56:33 +0000 (10:56 +0000)
This patch adds tests fr the current items() implementation. The idea is
to verify no behaviour change takes place after we make it us
_new_from_dbic instead of calling Koha::Items->search.

To test:
- Run:
  $ kshell
 k$ prove t/db_dependent/Koha/Biblio.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>

t/db_dependent/Koha/Biblio.t

index 72c06e0..1e050ca 100644 (file)
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 4;
+use Test::More tests => 5;
 
 use t::lib::TestBuilder;
 
@@ -86,3 +86,24 @@ subtest 'hidden_in_opac() tests' => sub {
 
     $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;
+    is( scalar @items, 2, 'Same result, but in list context' );
+
+    $schema->storage->txn_rollback;
+
+};