Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 25; |
22 |
use Test::More tests => 26; |
23 |
|
23 |
|
24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
25 |
use Test::Exception; |
25 |
use Test::Exception; |
Lines 2608-2610
subtest 'filter_by_has_recalls' => sub {
Link Here
|
2608 |
$schema->storage->txn_rollback; |
2608 |
$schema->storage->txn_rollback; |
2609 |
|
2609 |
|
2610 |
}; |
2610 |
}; |
2611 |
- |
2611 |
|
|
|
2612 |
subtest 'filter_by_available' => sub { |
2613 |
plan tests => 6; |
2614 |
|
2615 |
$schema->storage->txn_begin; |
2616 |
|
2617 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
2618 |
my $biblio = $builder->build_sample_biblio(); |
2619 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2620 |
t::lib::Mocks::mock_userenv( { branchcode => $patron->branchcode } ); |
2621 |
|
2622 |
my $item_1 = $builder->build_sample_item( |
2623 |
{ |
2624 |
biblionumber => $biblio->biblionumber, |
2625 |
library => $library->branchcode, |
2626 |
itemlost => 0, |
2627 |
withdrawn => 0, |
2628 |
damaged => 0, |
2629 |
notforloan => 0, |
2630 |
onloan => undef, |
2631 |
} |
2632 |
); |
2633 |
|
2634 |
my $item_2 = $builder->build_sample_item( |
2635 |
{ |
2636 |
biblionumber => $biblio->biblionumber, |
2637 |
library => $library->branchcode, |
2638 |
itemlost => 0, |
2639 |
withdrawn => 0, |
2640 |
damaged => 0, |
2641 |
notforloan => 0, |
2642 |
onloan => undef, |
2643 |
} |
2644 |
); |
2645 |
|
2646 |
my $item_3 = $builder->build_sample_item( |
2647 |
{ |
2648 |
biblionumber => $biblio->biblionumber, |
2649 |
library => $library->branchcode, |
2650 |
itemlost => 0, |
2651 |
withdrawn => 0, |
2652 |
damaged => 0, |
2653 |
notforloan => 0, |
2654 |
onloan => undef, |
2655 |
} |
2656 |
); |
2657 |
|
2658 |
my $item_4 = $builder->build_sample_item( |
2659 |
{ |
2660 |
biblionumber => $biblio->biblionumber, |
2661 |
library => $library->branchcode, |
2662 |
itemlost => 0, |
2663 |
withdrawn => 0, |
2664 |
damaged => 0, |
2665 |
notforloan => 0, |
2666 |
onloan => undef, |
2667 |
} |
2668 |
); |
2669 |
|
2670 |
my $item_5 = $builder->build_sample_item( |
2671 |
{ |
2672 |
biblionumber => $biblio->biblionumber, |
2673 |
library => $library->branchcode, |
2674 |
itemlost => 0, |
2675 |
withdrawn => 0, |
2676 |
damaged => 0, |
2677 |
notforloan => 0, |
2678 |
onloan => undef, |
2679 |
} |
2680 |
); |
2681 |
|
2682 |
# Create items with varying states |
2683 |
# Test: Initial available items |
2684 |
is( |
2685 |
$biblio->items->filter_by_available->count, |
2686 |
5, |
2687 |
"Filtered to 4 available items" |
2688 |
); |
2689 |
|
2690 |
# Mark item_1 as lost |
2691 |
$item_1->itemlost(3)->store; |
2692 |
C4::Circulation::LostItem( $item_1->itemnumber, 1 ); |
2693 |
|
2694 |
is( |
2695 |
$biblio->items->filter_by_available->count, |
2696 |
4, |
2697 |
"Filtered to 4 available items, 1 is lost" |
2698 |
); |
2699 |
|
2700 |
#Mark item_2 as damaged |
2701 |
$item_2->damaged(1)->store; |
2702 |
|
2703 |
is( |
2704 |
$biblio->items->filter_by_available->count, |
2705 |
3, |
2706 |
"Filtered to 3 available items, 1 is lost, 1 is damaged" |
2707 |
); |
2708 |
|
2709 |
#Mark item_3 as withdrawn |
2710 |
$item_3->withdrawn(1)->store; |
2711 |
|
2712 |
is( |
2713 |
$biblio->items->filter_by_available->count, |
2714 |
2, |
2715 |
"Filtered to 2 available items, 1 is lost, 1 is damaged, 1 is withdrawn" |
2716 |
); |
2717 |
|
2718 |
#Checkout item_4 |
2719 |
C4::Circulation::AddIssue( $patron, $item_4->barcode ); |
2720 |
is( |
2721 |
$biblio->items->filter_by_available->count, |
2722 |
1, |
2723 |
"Filtered to 1 available items, 1 is lost, 1 is damaged, 1 is withdrawn, 1 is checked out" |
2724 |
); |
2725 |
|
2726 |
#Mark item_5 as notforloan |
2727 |
$item_5->notforloan(1)->store; |
2728 |
is( |
2729 |
$biblio->items->filter_by_available->count, |
2730 |
0, |
2731 |
"Filtered to 0 available items, 1 is lost, 1 is damaged, 1 is withdrawn, 1 is checked out, 1 is notforloan" |
2732 |
); |
2733 |
|
2734 |
$schema->storage->txn_rollback; |
2735 |
}; |