View | Details | Raw Unified | Return to bug 29083
Collapse All | Expand All

(-)a/t/db_dependent/ArticleRequests.t (-25 / +2 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use POSIX qw(strftime);
20
use POSIX qw(strftime);
21
21
22
use Test::More tests => 55;
22
use Test::More tests => 46;
23
use Test::MockModule;
23
use Test::MockModule;
24
24
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
Lines 110-139 is( $article_request->biblio->id, $biblio->id, '$ar->biblio() gets correspondi Link Here
110
is( $article_request->item->id,     $item->id,   '$ar->item() gets corresponding Koha::Item object' );
110
is( $article_request->item->id,     $item->id,   '$ar->item() gets corresponding Koha::Item object' );
111
is( $article_request->borrower->id, $patron->id, '$ar->borrower() gets corresponding Koha::Patron object' );
111
is( $article_request->borrower->id, $patron->id, '$ar->borrower() gets corresponding Koha::Patron object' );
112
112
113
my $ar = $patron->article_requests();
113
my $ar = $biblio->article_requests();
114
is( ref($ar),      'Koha::ArticleRequests', '$patron->article_requests returns Koha::ArticleRequests object' );
115
is( $ar->next->id, $article_request->id,    'Returned article request matches' );
116
117
is( $patron->article_requests_current()->count(), 1, 'Open request returned for article_requests_current' );
118
$article_request->process();
119
is( $patron->article_requests_current()->count(), 1, 'Processing request returned for article_requests_current' );
120
$article_request->complete();
121
is( $patron->article_requests_current()->count(), 0, 'Completed request not returned for article_requests_current' );
122
$article_request->cancel();
123
is( $patron->article_requests_current()->count(), 0, 'Canceled request not returned for article_requests_current' );
124
125
$article_request->set_pending();
126
127
is( $patron->article_requests_finished()->count(), 0, 'Open request returned for article_requests_finished' );
128
$article_request->process();
129
is( $patron->article_requests_finished()->count(), 0, 'Processing request returned for article_requests_finished' );
130
$article_request->complete();
131
$article_request->cancel();
132
is( $patron->article_requests_finished()->count(), 1, 'Canceled request not returned for article_requests_finished' );
133
134
$article_request->set_pending();
135
136
$ar = $biblio->article_requests();
137
is( ref($ar),      'Koha::ArticleRequests', '$biblio->article_requests returns Koha::ArticleRequests object' );
114
is( ref($ar),      'Koha::ArticleRequests', '$biblio->article_requests returns Koha::ArticleRequests object' );
138
is( $ar->next->id, $article_request->id,    'Returned article request matches' );
115
is( $ar->next->id, $article_request->id,    'Returned article request matches' );
139
116
(-)a/t/db_dependent/Koha/Patron.t (-2 / +118 lines)
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
};

Return to bug 29083