|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 15; |
20 |
use Test::More tests => 18; |
| 21 |
|
21 |
|
| 22 |
use C4::Biblio qw( AddBiblio ModBiblio ); |
22 |
use C4::Biblio qw( AddBiblio ModBiblio ); |
| 23 |
use Koha::Database; |
23 |
use Koha::Database; |
|
Lines 690-692
subtest 'host_items() tests' => sub {
Link Here
|
| 690 |
|
690 |
|
| 691 |
$schema->storage->txn_rollback; |
691 |
$schema->storage->txn_rollback; |
| 692 |
}; |
692 |
}; |
| 693 |
- |
693 |
|
|
|
694 |
subtest 'article_requests() tests' => sub { |
| 695 |
|
| 696 |
plan tests => 3; |
| 697 |
|
| 698 |
$schema->storage->txn_begin; |
| 699 |
|
| 700 |
my $item = $builder->build_sample_item; |
| 701 |
my $biblio = $item->biblio; |
| 702 |
|
| 703 |
my $article_requests = $biblio->article_requests; |
| 704 |
is( ref($article_requests), 'Koha::ArticleRequests', |
| 705 |
'In scalar context, type is correct' ); |
| 706 |
is( $article_requests->count, 0, 'No article requests' ); |
| 707 |
|
| 708 |
foreach my $i ( 0 .. 3 ) { |
| 709 |
|
| 710 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 711 |
|
| 712 |
Koha::ArticleRequest->new( |
| 713 |
{ |
| 714 |
borrowernumber => $patron->id, |
| 715 |
biblionumber => $biblio->id, |
| 716 |
itemnumber => $item->id, |
| 717 |
title => $biblio->title, |
| 718 |
} |
| 719 |
)->request; |
| 720 |
} |
| 721 |
|
| 722 |
$article_requests = $biblio->article_requests; |
| 723 |
is( $article_requests->count, 4, '4 article requests' ); |
| 724 |
|
| 725 |
$schema->storage->txn_rollback; |
| 726 |
}; |
| 727 |
|
| 728 |
subtest 'article_requests_current() tests' => sub { |
| 729 |
|
| 730 |
plan tests => 7; |
| 731 |
|
| 732 |
$schema->storage->txn_begin; |
| 733 |
|
| 734 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 735 |
my $item = $builder->build_sample_item; |
| 736 |
my $biblio = $item->biblio; |
| 737 |
|
| 738 |
my $article_request = Koha::ArticleRequest->new( |
| 739 |
{ |
| 740 |
borrowernumber => $patron->id, |
| 741 |
biblionumber => $biblio->id, |
| 742 |
itemnumber => $item->id, |
| 743 |
title => $biblio->title, |
| 744 |
} |
| 745 |
)->request(); |
| 746 |
|
| 747 |
my $ar = $biblio->article_requests(); |
| 748 |
is( ref($ar), 'Koha::ArticleRequests', |
| 749 |
'$biblio->article_requests returns Koha::ArticleRequests object' ); |
| 750 |
is( $ar->next->id, $article_request->id, |
| 751 |
'Returned article request matches' ); |
| 752 |
|
| 753 |
is( $biblio->article_requests_current()->count(), |
| 754 |
1, 'Open request returned for article_requests_current' ); |
| 755 |
$article_request->set_pending(); |
| 756 |
is( $biblio->article_requests_current()->count(), |
| 757 |
1, 'Pending request returned for article_requests_current' ); |
| 758 |
$article_request->process(); |
| 759 |
is( $biblio->article_requests_current()->count(), |
| 760 |
1, 'Processing request returned for article_requests_current' ); |
| 761 |
$article_request->complete(); |
| 762 |
is( $biblio->article_requests_current()->count(), |
| 763 |
0, 'Completed request not returned for article_requests_current' ); |
| 764 |
$article_request->cancel(); |
| 765 |
is( $biblio->article_requests_current()->count(), |
| 766 |
0, 'Canceled request not returned for article_requests_current' ); |
| 767 |
|
| 768 |
$schema->storage->txn_rollback; |
| 769 |
}; |
| 770 |
|
| 771 |
subtest 'article_requests_finished() tests' => sub { |
| 772 |
|
| 773 |
plan tests => 7; |
| 774 |
|
| 775 |
$schema->storage->txn_begin; |
| 776 |
|
| 777 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 778 |
my $item = $builder->build_sample_item; |
| 779 |
my $biblio = $item->biblio; |
| 780 |
|
| 781 |
my $article_request = Koha::ArticleRequest->new( |
| 782 |
{ |
| 783 |
borrowernumber => $patron->id, |
| 784 |
biblionumber => $biblio->id, |
| 785 |
itemnumber => $item->id, |
| 786 |
title => $biblio->title, |
| 787 |
} |
| 788 |
)->request(); |
| 789 |
|
| 790 |
my $ar = $biblio->article_requests(); |
| 791 |
is( ref($ar), 'Koha::ArticleRequests', |
| 792 |
'$biblio->article_requests returns Koha::ArticleRequests object' ); |
| 793 |
is( $ar->next->id, $article_request->id, |
| 794 |
'Returned article request matches' ); |
| 795 |
|
| 796 |
is( $biblio->article_requests_finished->count, |
| 797 |
0, 'Open request returned for article_requests_finished' ); |
| 798 |
$article_request->set_pending(); |
| 799 |
is( $biblio->article_requests_finished->count, |
| 800 |
0, 'Pending request returned for article_requests_finished' ); |
| 801 |
$article_request->process(); |
| 802 |
is( $biblio->article_requests_finished->count, |
| 803 |
0, 'Processing request returned for article_requests_finished' ); |
| 804 |
$article_request->complete(); |
| 805 |
is( $biblio->article_requests_finished->count, |
| 806 |
1, 'Completed request returned for article_requests_finished' ); |
| 807 |
$article_request->cancel(); |
| 808 |
is( $biblio->article_requests_finished->count, |
| 809 |
1, 'Cancelled request not returned for article_requests_finished' ); |
| 810 |
|
| 811 |
$schema->storage->txn_rollback; |
| 812 |
}; |