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