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 |
}; |