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

(-)a/t/db_dependent/ArticleRequests.t (-1 / +175 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 POSIX qw(strftime);
21
22
use Test::More tests => 33;
23
use Koha::Database;
24
25
use Koha::Biblio;
26
use Koha::Borrower;
27
use Koha::Branch;
28
29
BEGIN {
30
    use_ok('Koha::ArticleRequest');
31
    use_ok('Koha::ArticleRequests');
32
    use_ok('Koha::ArticleRequest::Status');
33
}
34
35
my $schema = Koha::Database->new()->schema();
36
$schema->storage->txn_begin();
37
38
my $dbh = C4::Context->dbh;
39
$dbh->{RaiseError} = 1;
40
41
$dbh->do("DELETE FROM issuingrules");
42
43
my $biblio = Koha::Biblio->new()->store();
44
ok( $biblio->id, 'Koha::Biblio created' );
45
46
my $biblioitem = $schema->resultset('Biblioitem')->new(
47
    {
48
        biblionumber => $biblio->id
49
    }
50
)->insert();
51
ok( $biblioitem->id, 'biblioitem created' );
52
53
my $item = Koha::Item->new(
54
    {
55
        biblionumber     => $biblio->id,
56
        biblioitemnumber => $biblioitem->id
57
    }
58
)->store();
59
ok( $item->id, 'Koha::Item created' );
60
61
my $branch   = Koha::Branches->search()->next();
62
my $category = $schema->resultset('Category')->next();
63
my $patron   = Koha::Borrower->new(
64
    {
65
        categorycode => $category->id,
66
        branchcode   => $branch->id,
67
    }
68
)->store();
69
ok( $patron->id, 'Koha::Borrower created' );
70
71
my $article_request = Koha::ArticleRequest->new(
72
    {
73
        borrowernumber => $patron->id,
74
        biblionumber   => $biblio->id,
75
        itemnumber     => $item->id,
76
    }
77
)->store();
78
$article_request = Koha::ArticleRequests->find( $article_request->id );
79
ok( $article_request->id, 'Koha::ArticleRequest created' );
80
81
is( $article_request->status, Koha::ArticleRequest::Status::Open, 'New article request has status of Open' );
82
$article_request->process();
83
is( $article_request->status, Koha::ArticleRequest::Status::Processing, '$ar->process() changes status to Processing' );
84
$article_request->complete();
85
is( $article_request->status, Koha::ArticleRequest::Status::Completed, '$ar->complete() changes status to Completed' );
86
$article_request->cancel();
87
is( $article_request->status, Koha::ArticleRequest::Status::Canceled, '$ar->complete() changes status to Canceled' );
88
$article_request->status(Koha::ArticleRequest::Status::Open);
89
$article_request->store();
90
91
is( $article_request->biblio->id,   $biblio->id, '$ar->biblio() gets corrosponding Koha::Biblio object' );
92
is( $article_request->item->id,     $item->id,   '$ar->item() gets corrosponding Koha::Item object' );
93
is( $article_request->borrower->id, $patron->id, '$ar->borrower() gets corrosponding Koha::Borrower object' );
94
95
my $ar = $patron->article_requests();
96
is( ref($ar),      'Koha::ArticleRequests', '$patron->article_requests returns Koha::ArticleRequests object' );
97
is( $ar->next->id, $article_request->id,    'Returned article request matches' );
98
99
is( $patron->article_requests_current()->count(), 1, 'Open request returned for article_requests_current' );
100
$article_request->process();
101
is( $patron->article_requests_current()->count(), 1, 'Processing request returned for article_requests_current' );
102
$article_request->complete();
103
is( $patron->article_requests_current()->count(), 0, 'Completed request not returned for article_requests_current' );
104
$article_request->cancel();
105
is( $patron->article_requests_current()->count(), 0, 'Canceled request not returned for article_requests_current' );
106
107
$article_request->status(Koha::ArticleRequest::Status::Open);
108
$article_request->store();
109
110
is( $patron->article_requests_finished()->count(), 0, 'Open request returned for article_requests_finished' );
111
$article_request->process();
112
is( $patron->article_requests_finished()->count(), 0, 'Processing request returned for article_requests_finished' );
113
$article_request->complete();
114
$article_request->cancel();
115
is( $patron->article_requests_finished()->count(), 1, 'Canceled request not returned for article_requests_finished' );
116
117
$article_request->status(Koha::ArticleRequest::Status::Open);
118
$article_request->store();
119
120
$ar = $biblio->article_requests();
121
is( ref($ar),      'Koha::ArticleRequests', '$biblio->article_requests returns Koha::ArticleRequests object' );
122
is( $ar->next->id, $article_request->id,    'Returned article request matches' );
123
124
is( $biblio->article_requests_current()->count(), 1, 'Open request returned for article_requests_current' );
125
$article_request->process();
126
is( $biblio->article_requests_current()->count(), 1, 'Processing request returned for article_requests_current' );
127
$article_request->complete();
128
is( $biblio->article_requests_current()->count(), 0, 'Completed request not returned for article_requests_current' );
129
$article_request->cancel();
130
is( $biblio->article_requests_current()->count(), 0, 'Canceled request not returned for article_requests_current' );
131
132
$article_request->status(Koha::ArticleRequest::Status::Open);
133
$article_request->store();
134
135
is( $biblio->article_requests_finished()->count(), 0, 'Open request returned for article_requests_finished' );
136
$article_request->process();
137
is( $biblio->article_requests_finished()->count(), 0, 'Processing request returned for article_requests_finished' );
138
$article_request->complete();
139
$article_request->cancel();
140
is( $biblio->article_requests_finished()->count(), 1, 'Canceled request not returned for article_requests_finished' );
141
142
my $rule;
143
$rule = $schema->resultset('Issuingrule')
144
  ->new( { categorycode => '*', itemtype => '*', branchcode => '*', article_requests => 'yes' } )->insert();
145
ok( $biblio->can_article_request($patron), 'Record is requestable with rule type yes' );
146
is( $biblio->article_request_type($patron), 'yes', 'Biblio article request type is yes' );
147
ok( $item->can_article_request($patron),   'Item is requestable with rule type yes' );
148
is( $item->article_request_type($patron), 'yes', 'Item article request type is yes' );
149
$rule->delete();
150
151
$rule = $schema->resultset('Issuingrule')
152
  ->new( { categorycode => '*', itemtype => '*', branchcode => '*', article_requests => 'bib_only' } )->insert();
153
ok( $biblio->can_article_request($patron), 'Record is requestable with rule type bib_only' );
154
is( $biblio->article_request_type($patron), 'bib_only', 'Biblio article request type is bib_only' );
155
ok( !$item->can_article_request($patron),  'Item is not requestable with rule type bib_only' );
156
is( $item->article_request_type($patron), 'bib_only', 'Item article request type is bib_only' );
157
$rule->delete();
158
159
$rule = $schema->resultset('Issuingrule')
160
  ->new( { categorycode => '*', itemtype => '*', branchcode => '*', article_requests => 'item_only' } )->insert();
161
ok( $biblio->can_article_request($patron), 'Record is requestable with rule type item_only' );
162
is( $biblio->article_request_type($patron), 'item_only', 'Biblio article request type is item_only' );
163
ok( $item->can_article_request($patron),   'Item is not requestable with rule type item_only' );
164
is( $item->article_request_type($patron), 'item_only', 'Item article request type is item_only' );
165
$rule->delete();
166
167
$rule = $schema->resultset('Issuingrule')
168
  ->new( { categorycode => '*', itemtype => '*', branchcode => '*', article_requests => 'no' } )->insert();
169
ok( !$biblio->can_article_request($patron), 'Record is requestable with rule type no' );
170
is( $biblio->article_request_type($patron), 'no', 'Biblio article request type is no' );
171
ok( !$item->can_article_request($patron),   'Item is not requestable with rule type no' );
172
is( $item->article_request_type($patron), 'no', 'Item article request type is no' );
173
$rule->delete();
174
175
$schema->storage->txn_rollback();

Return to bug 14610