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

(-)a/Koha/ArticleRequests.pm (-1 / +44 lines)
Lines 33-39 Koha::ArticleRequests - Koha ArticleRequests Object class Link Here
33
33
34
=head1 API
34
=head1 API
35
35
36
=head2 Class Methods
36
=head2 Class methods
37
37
38
=cut
38
=cut
39
39
Lines 60-65 sub search_limited { Link Here
60
    return $self->search( $params, $attributes );
60
    return $self->search( $params, $attributes );
61
}
61
}
62
62
63
=head3 filter_by_current
64
65
    my $current_article_requests = $article_requests->filter_by_current;
66
67
Returns a new resultset, filtering out finished article requests.
68
69
=cut
70
71
sub filter_by_current {
72
    my ($self) = @_;
73
74
    return $self->search(
75
        {
76
            status => [
77
                Koha::ArticleRequest::Status::Requested,
78
                Koha::ArticleRequest::Status::Pending,
79
                Koha::ArticleRequest::Status::Processing,
80
            ]
81
        }
82
    );
83
}
84
85
=head3 filter_by_finished
86
87
    my $finished_article_requests = $article_requests->filter_by_finished;
88
89
Returns a new resultset, filtering out current article requests.
90
91
=cut
92
93
sub filter_by_finished {
94
    my ($self) = @_;
95
96
    return $self->search(
97
        {
98
            status => [
99
                Koha::ArticleRequest::Status::Completed,
100
                Koha::ArticleRequest::Status::Canceled,
101
            ]
102
        }
103
    );
104
}
105
63
=head3 requested
106
=head3 requested
64
107
65
=cut
108
=cut
(-)a/t/db_dependent/Koha/ArticleRequests.t (-5 / +111 lines)
Lines 17-31 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 1;
20
use Test::More tests => 3;
21
use Test::MockModule;
21
use Test::MockModule;
22
22
23
use t::lib::TestBuilder;
23
use Koha::ArticleRequest::Status;
24
use t::lib::Mocks;
25
26
use Koha::ArticleRequests;
24
use Koha::ArticleRequests;
27
use Koha::Database;
25
use Koha::Database;
28
26
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
29
my $schema  = Koha::Database->new->schema;
30
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
my $builder = t::lib::TestBuilder->new;
31
32
Lines 77-79 subtest 'requested() tests' => sub { Link Here
77
78
78
    $schema->storage->txn_rollback;
79
    $schema->storage->txn_rollback;
79
};
80
};
80
- 
81
82
subtest 'filter_by_current() tests' => sub {
83
84
    plan tests => 1;
85
86
    $schema->storage->txn_begin;
87
88
    my $ar_requested = $builder->build_object(
89
        {
90
            class => 'Koha::ArticleRequests',
91
            value => { status => Koha::ArticleRequest::Status::Requested }
92
        }
93
    );
94
    my $ar_pending = $builder->build_object(
95
        {
96
            class => 'Koha::ArticleRequests',
97
            value => { status => Koha::ArticleRequest::Status::Pending }
98
        }
99
    );
100
    my $ar_processing = $builder->build_object(
101
        {
102
            class => 'Koha::ArticleRequests',
103
            value => { status => Koha::ArticleRequest::Status::Processing }
104
        }
105
    );
106
    my $ar_completed = $builder->build_object(
107
        {
108
            class => 'Koha::ArticleRequests',
109
            value => { status => Koha::ArticleRequest::Status::Completed }
110
        }
111
    );
112
    my $ar_cancelled = $builder->build_object(
113
        {
114
            class => 'Koha::ArticleRequests',
115
            value => { status => Koha::ArticleRequest::Status::Canceled }
116
        }
117
    );
118
119
    my $article_requests = Koha::ArticleRequests->search(
120
        {
121
            id => [
122
                $ar_requested->id, $ar_pending->id, $ar_processing->id,
123
                $ar_completed->id, $ar_cancelled->id
124
            ]
125
        }
126
    );
127
128
    my $current_article_requests = $article_requests->filter_by_current;
129
130
    is( $current_article_requests->count, 3, 'Count is correct' );
131
132
    $schema->storage->txn_rollback;
133
};
134
135
subtest 'filter_by_current() tests' => sub {
136
137
    plan tests => 1;
138
139
    $schema->storage->txn_begin;
140
141
    my $ar_requested = $builder->build_object(
142
        {
143
            class => 'Koha::ArticleRequests',
144
            value => { status => Koha::ArticleRequest::Status::Requested }
145
        }
146
    );
147
    my $ar_pending = $builder->build_object(
148
        {
149
            class => 'Koha::ArticleRequests',
150
            value => { status => Koha::ArticleRequest::Status::Pending }
151
        }
152
    );
153
    my $ar_processing = $builder->build_object(
154
        {
155
            class => 'Koha::ArticleRequests',
156
            value => { status => Koha::ArticleRequest::Status::Processing }
157
        }
158
    );
159
    my $ar_completed = $builder->build_object(
160
        {
161
            class => 'Koha::ArticleRequests',
162
            value => { status => Koha::ArticleRequest::Status::Completed }
163
        }
164
    );
165
    my $ar_cancelled = $builder->build_object(
166
        {
167
            class => 'Koha::ArticleRequests',
168
            value => { status => Koha::ArticleRequest::Status::Canceled }
169
        }
170
    );
171
172
    my $article_requests = Koha::ArticleRequests->search(
173
        {
174
            id => [
175
                $ar_requested->id, $ar_pending->id, $ar_processing->id,
176
                $ar_completed->id, $ar_cancelled->id
177
            ]
178
        }
179
    );
180
181
    my $finished_article_requests = $article_requests->filter_by_finished;
182
183
    is( $finished_article_requests->count, 2, 'Count is correct' );
184
185
    $schema->storage->txn_rollback;
186
};

Return to bug 29082