Bug 29234: Further clean Z3950 Tests
[koha-ffzg.git] / t / db_dependent / Koha / Holds.t
index 1ab51b1..4b859cf 100755 (executable)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 8;
+use Test::More tests => 11;
 use Test::Warn;
 
 use C4::Circulation qw( AddIssue );
@@ -529,7 +529,7 @@ subtest 'get_items_that_can_fill' => sub {
         }
     );
     $items = $holds->get_items_that_can_fill;
-    is_deeply( [ sort map { $_->itemnumber } $items->as_list ],
+    is_deeply( [ sort { $a <=> $b } map { $_->itemnumber } $items->as_list ],
         [ $item_1->itemnumber, $item_2->itemnumber, $item_5->itemnumber ], 'Items 1, 2, and 5 are available for filling the holds' );
 
     my $no_holds = Koha::Holds->new->empty();
@@ -650,7 +650,6 @@ subtest 'Test Koha::Hold::item_group' => sub {
     my $item_group = $builder->build_object(
         {
             class => 'Koha::Biblio::ItemGroups',
-            value => { biblionumber => $item->biblionumber }
         }
     );
     my $reserve_id = AddReserve(
@@ -671,6 +670,36 @@ subtest 'Test Koha::Hold::item_group' => sub {
 
 $schema->storage->txn_rollback;
 
+subtest 'filter_by_found() tests' => sub {
+
+    plan tests => 5;
+
+    $schema->storage->txn_begin;
+
+    my $unfilled   = $builder->build_object( { class => 'Koha::Holds', value => { found => undef } } );
+    my $processing = $builder->build_object( { class => 'Koha::Holds', value => { found => 'P' } } );
+    my $in_transit = $builder->build_object( { class => 'Koha::Holds', value => { found => 'T' } } );
+    my $waiting    = $builder->build_object( { class => 'Koha::Holds', value => { found => 'W' } } );
+
+    my $holds = Koha::Holds->search(
+        { reserve_id => [ $unfilled->id, $processing->id, $in_transit->id, $waiting->id ] },
+        { order_by => ['reserve_id'] }
+    );
+
+    is( $holds->count, 4, 'Resultset count is correct' );
+
+    my $found_holds = $holds->filter_by_found;
+
+    is( $found_holds->count, 3, 'Resultset count is correct' );
+
+    ok( $found_holds->next->is_in_processing, 'Status is correct (P)' );
+    ok( $found_holds->next->is_in_transit, 'Status is correct (T)' );
+    ok( $found_holds->next->is_waiting, 'Status is correct (W)' );
+
+
+    $schema->storage->txn_rollback;
+};
+
 subtest 'filter_by_has_cancellation_requests() and filter_out_has_cancellation_requests() tests' => sub {
 
     plan tests => 7;
@@ -744,3 +773,38 @@ subtest 'filter_by_has_cancellation_requests() and filter_out_has_cancellation_r
 
     $schema->storage->txn_rollback;
 };
+
+subtest 'processing() tests' => sub {
+
+    plan tests => 3;
+
+    $schema->storage->txn_begin;
+
+    my $hold_1 = $builder->build_object(
+        {
+            class => 'Koha::Holds',
+            value => { found => 'P' }
+        }
+    );
+    my $hold_2 = $builder->build_object(
+        {
+            class => 'Koha::Holds',
+            value => { found => undef }
+        }
+    );
+    my $hold_3 = $builder->build_object(
+        {
+            class => 'Koha::Holds',
+            value => { found => 'T' }
+        }
+    );
+
+    my $holds = Koha::Holds->search({ reserve_id => [ $hold_1->id, $hold_2->id, $hold_3->id ] });
+    is( $holds->count, 3, 'Resultset contains 3 holds' );
+
+    my $processing = $holds->processing;
+    is( $processing->count, 1 );
+    is( $processing->next->id, $hold_1->id, "First hold is the only one in 'processing'" );
+
+    $schema->storage->txn_rollback;
+};