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 => 54;
22
use Test::More tests => 45;
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 813-815 subtest 'can_request_article() tests' => sub { Link Here
813
813
814
    $schema->storage->txn_rollback;
814
    $schema->storage->txn_rollback;
815
};
815
};
816
- 
816
817
subtest 'article_requests() tests' => sub {
818
819
    plan tests => 3;
820
821
    $schema->storage->txn_begin;
822
823
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
824
825
    my $article_requests = $patron->article_requests;
826
    is( ref($article_requests), 'Koha::ArticleRequests',
827
        'In scalar context, type is correct' );
828
    is( $article_requests->count, 0, 'No article requests' );
829
830
    foreach my $i ( 0 .. 3 ) {
831
832
        my $item = $builder->build_sample_item;
833
834
        Koha::ArticleRequest->new(
835
            {
836
                borrowernumber => $patron->id,
837
                biblionumber   => $item->biblionumber,
838
                itemnumber     => $item->id,
839
                title          => "Title",
840
            }
841
        )->request;
842
    }
843
844
    $article_requests = $patron->article_requests;
845
    is( $article_requests->count, 4, '4 article requests' );
846
847
    $schema->storage->txn_rollback;
848
};
849
850
subtest 'article_requests_current() tests' => sub {
851
852
    plan tests => 7;
853
854
    $schema->storage->txn_begin;
855
856
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
857
    my $item   = $builder->build_sample_item;
858
859
    my $article_request = Koha::ArticleRequest->new(
860
        {
861
            borrowernumber => $patron->id,
862
            biblionumber   => $item->biblionumber,
863
            itemnumber     => $item->itemnumber,
864
            title          => "Boo",
865
        }
866
    )->request();
867
868
    my $ar = $patron->article_requests();
869
    is( ref($ar), 'Koha::ArticleRequests',
870
        '$patron->article_requests returns Koha::ArticleRequests object' );
871
    is( $ar->next->id, $article_request->id,
872
        'Returned article request matches' );
873
874
    is( $patron->article_requests_current()->count(),
875
        1, 'Open request returned for article_requests_current' );
876
    $article_request->set_pending();
877
    is( $patron->article_requests_current()->count(),
878
        1, 'Pending request returned for article_requests_current' );
879
    $article_request->process();
880
    is( $patron->article_requests_current()->count(),
881
        1, 'Processing request returned for article_requests_current' );
882
    $article_request->complete();
883
    is( $patron->article_requests_current()->count(),
884
        0, 'Completed request not returned for article_requests_current' );
885
    $article_request->cancel();
886
    is( $patron->article_requests_current()->count(),
887
        0, 'Canceled request not returned for article_requests_current' );
888
889
    $schema->storage->txn_rollback;
890
};
891
892
subtest 'article_requests_finished() tests' => sub {
893
894
    plan tests => 7;
895
896
    $schema->storage->txn_begin;
897
898
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
899
    my $item   = $builder->build_sample_item;
900
901
    my $article_request = Koha::ArticleRequest->new(
902
        {
903
            borrowernumber => $patron->id,
904
            biblionumber   => $item->biblionumber,
905
            itemnumber     => $item->itemnumber,
906
            title          => "Boo",
907
        }
908
    )->request();
909
910
    my $ar = $patron->article_requests();
911
    is( ref($ar), 'Koha::ArticleRequests',
912
        '$patron->article_requests returns Koha::ArticleRequests object' );
913
    is( $ar->next->id, $article_request->id,
914
        'Returned article request matches' );
915
916
    is( $patron->article_requests_finished->count,
917
        0, 'Open request returned for article_requests_finished' );
918
    $article_request->set_pending();
919
    is( $patron->article_requests_finished->count,
920
        0, 'Pending request returned for article_requests_finished' );
921
    $article_request->process();
922
    is( $patron->article_requests_finished->count,
923
        0, 'Processing request returned for article_requests_finished' );
924
    $article_request->complete();
925
    is( $patron->article_requests_finished->count,
926
        1, 'Completed request returned for article_requests_finished' );
927
    $article_request->cancel();
928
    is( $patron->article_requests_finished->count,
929
        1, 'Cancelled request not returned for article_requests_finished' );
930
931
    $schema->storage->txn_rollback;
932
};

Return to bug 29083