|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 9; |
22 |
use Test::More tests => 12; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
|
25 |
|
|
Lines 831-833
subtest 'can_request_article() tests' => sub {
Link Here
|
| 831 |
|
831 |
|
| 832 |
$schema->storage->txn_rollback; |
832 |
$schema->storage->txn_rollback; |
| 833 |
}; |
833 |
}; |
| 834 |
- |
834 |
|
|
|
835 |
subtest 'article_requests() tests' => sub { |
| 836 |
|
| 837 |
plan tests => 3; |
| 838 |
|
| 839 |
$schema->storage->txn_begin; |
| 840 |
|
| 841 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 842 |
|
| 843 |
my $article_requests = $patron->article_requests; |
| 844 |
is( ref($article_requests), 'Koha::ArticleRequests', |
| 845 |
'In scalar context, type is correct' ); |
| 846 |
is( $article_requests->count, 0, 'No article requests' ); |
| 847 |
|
| 848 |
foreach my $i ( 0 .. 3 ) { |
| 849 |
|
| 850 |
my $item = $builder->build_sample_item; |
| 851 |
|
| 852 |
Koha::ArticleRequest->new( |
| 853 |
{ |
| 854 |
borrowernumber => $patron->id, |
| 855 |
biblionumber => $item->biblionumber, |
| 856 |
itemnumber => $item->id, |
| 857 |
title => "Title", |
| 858 |
} |
| 859 |
)->request; |
| 860 |
} |
| 861 |
|
| 862 |
$article_requests = $patron->article_requests; |
| 863 |
is( $article_requests->count, 4, '4 article requests' ); |
| 864 |
|
| 865 |
$schema->storage->txn_rollback; |
| 866 |
}; |
| 867 |
|
| 868 |
subtest 'article_requests_current() tests' => sub { |
| 869 |
|
| 870 |
plan tests => 7; |
| 871 |
|
| 872 |
$schema->storage->txn_begin; |
| 873 |
|
| 874 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 875 |
my $item = $builder->build_sample_item; |
| 876 |
|
| 877 |
my $article_request = Koha::ArticleRequest->new( |
| 878 |
{ |
| 879 |
borrowernumber => $patron->id, |
| 880 |
biblionumber => $item->biblionumber, |
| 881 |
itemnumber => $item->itemnumber, |
| 882 |
title => "Boo", |
| 883 |
} |
| 884 |
)->request(); |
| 885 |
|
| 886 |
my $ar = $patron->article_requests(); |
| 887 |
is( ref($ar), 'Koha::ArticleRequests', |
| 888 |
'$patron->article_requests returns Koha::ArticleRequests object' ); |
| 889 |
is( $ar->next->id, $article_request->id, |
| 890 |
'Returned article request matches' ); |
| 891 |
|
| 892 |
is( $patron->article_requests_current()->count(), |
| 893 |
1, 'Open request returned for article_requests_current' ); |
| 894 |
$article_request->set_pending(); |
| 895 |
is( $patron->article_requests_current()->count(), |
| 896 |
1, 'Pending request returned for article_requests_current' ); |
| 897 |
$article_request->process(); |
| 898 |
is( $patron->article_requests_current()->count(), |
| 899 |
1, 'Processing request returned for article_requests_current' ); |
| 900 |
$article_request->complete(); |
| 901 |
is( $patron->article_requests_current()->count(), |
| 902 |
0, 'Completed request not returned for article_requests_current' ); |
| 903 |
$article_request->cancel(); |
| 904 |
is( $patron->article_requests_current()->count(), |
| 905 |
0, 'Canceled request not returned for article_requests_current' ); |
| 906 |
|
| 907 |
$schema->storage->txn_rollback; |
| 908 |
}; |
| 909 |
|
| 910 |
subtest 'article_requests_finished() tests' => sub { |
| 911 |
|
| 912 |
plan tests => 7; |
| 913 |
|
| 914 |
$schema->storage->txn_begin; |
| 915 |
|
| 916 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 917 |
my $item = $builder->build_sample_item; |
| 918 |
|
| 919 |
my $article_request = Koha::ArticleRequest->new( |
| 920 |
{ |
| 921 |
borrowernumber => $patron->id, |
| 922 |
biblionumber => $item->biblionumber, |
| 923 |
itemnumber => $item->itemnumber, |
| 924 |
title => "Boo", |
| 925 |
} |
| 926 |
)->request(); |
| 927 |
|
| 928 |
my $ar = $patron->article_requests(); |
| 929 |
is( ref($ar), 'Koha::ArticleRequests', |
| 930 |
'$patron->article_requests returns Koha::ArticleRequests object' ); |
| 931 |
is( $ar->next->id, $article_request->id, |
| 932 |
'Returned article request matches' ); |
| 933 |
|
| 934 |
is( $patron->article_requests_finished->count, |
| 935 |
0, 'Open request returned for article_requests_finished' ); |
| 936 |
$article_request->set_pending(); |
| 937 |
is( $patron->article_requests_finished->count, |
| 938 |
0, 'Pending request returned for article_requests_finished' ); |
| 939 |
$article_request->process(); |
| 940 |
is( $patron->article_requests_finished->count, |
| 941 |
0, 'Processing request returned for article_requests_finished' ); |
| 942 |
$article_request->complete(); |
| 943 |
is( $patron->article_requests_finished->count, |
| 944 |
1, 'Completed request returned for article_requests_finished' ); |
| 945 |
$article_request->cancel(); |
| 946 |
is( $patron->article_requests_finished->count, |
| 947 |
1, 'Cancelled request not returned for article_requests_finished' ); |
| 948 |
|
| 949 |
$schema->storage->txn_rollback; |
| 950 |
}; |