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 (-1 / +134 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 2;
21
22
use Koha::ArticleRequest::Status;
23
use Koha::ArticleRequests;
24
25
use t::lib::TestBuilder;
26
27
my $schema  = Koha::Database->new->schema;
28
my $builder = t::lib::TestBuilder->new;
29
30
subtest 'filter_by_current() tests' => sub {
31
32
    plan tests => 1;
33
34
    $schema->storage->txn_begin;
35
36
    my $ar_requested = $builder->build_object(
37
        {
38
            class => 'Koha::ArticleRequests',
39
            value => { status => Koha::ArticleRequest::Status::Requested }
40
        }
41
    );
42
    my $ar_pending = $builder->build_object(
43
        {
44
            class => 'Koha::ArticleRequests',
45
            value => { status => Koha::ArticleRequest::Status::Pending }
46
        }
47
    );
48
    my $ar_processing = $builder->build_object(
49
        {
50
            class => 'Koha::ArticleRequests',
51
            value => { status => Koha::ArticleRequest::Status::Processing }
52
        }
53
    );
54
    my $ar_completed = $builder->build_object(
55
        {
56
            class => 'Koha::ArticleRequests',
57
            value => { status => Koha::ArticleRequest::Status::Completed }
58
        }
59
    );
60
    my $ar_cancelled = $builder->build_object(
61
        {
62
            class => 'Koha::ArticleRequests',
63
            value => { status => Koha::ArticleRequest::Status::Canceled }
64
        }
65
    );
66
67
    my $article_requests = Koha::ArticleRequests->search(
68
        {
69
            id => [
70
                $ar_requested->id, $ar_pending->id, $ar_processing->id,
71
                $ar_completed->id, $ar_cancelled->id
72
            ]
73
        }
74
    );
75
76
    my $current_article_requests = $article_requests->filter_by_current;
77
78
    is( $current_article_requests->count, 3, 'Count is correct' );
79
80
    $schema->storage->txn_rollback;
81
};
82
83
subtest 'filter_by_current() tests' => sub {
84
85
    plan tests => 1;
86
87
    $schema->storage->txn_begin;
88
89
    my $ar_requested = $builder->build_object(
90
        {
91
            class => 'Koha::ArticleRequests',
92
            value => { status => Koha::ArticleRequest::Status::Requested }
93
        }
94
    );
95
    my $ar_pending = $builder->build_object(
96
        {
97
            class => 'Koha::ArticleRequests',
98
            value => { status => Koha::ArticleRequest::Status::Pending }
99
        }
100
    );
101
    my $ar_processing = $builder->build_object(
102
        {
103
            class => 'Koha::ArticleRequests',
104
            value => { status => Koha::ArticleRequest::Status::Processing }
105
        }
106
    );
107
    my $ar_completed = $builder->build_object(
108
        {
109
            class => 'Koha::ArticleRequests',
110
            value => { status => Koha::ArticleRequest::Status::Completed }
111
        }
112
    );
113
    my $ar_cancelled = $builder->build_object(
114
        {
115
            class => 'Koha::ArticleRequests',
116
            value => { status => Koha::ArticleRequest::Status::Canceled }
117
        }
118
    );
119
120
    my $article_requests = Koha::ArticleRequests->search(
121
        {
122
            id => [
123
                $ar_requested->id, $ar_pending->id, $ar_processing->id,
124
                $ar_completed->id, $ar_cancelled->id
125
            ]
126
        }
127
    );
128
129
    my $finished_article_requests = $article_requests->filter_by_finished;
130
131
    is( $finished_article_requests->count, 2, 'Count is correct' );
132
133
    $schema->storage->txn_rollback;
134
};

Return to bug 29082