Lines 20-26
Link Here
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
use utf8; |
21 |
use utf8; |
22 |
|
22 |
|
23 |
use Test::More tests => 38; |
23 |
use Test::More tests => 39; |
24 |
use Test::Exception; |
24 |
use Test::Exception; |
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
26 |
use Test::Warn; |
26 |
use Test::Warn; |
Lines 45-50
use t::lib::Dates;
Link Here
|
45 |
my $schema = Koha::Database->new->schema; |
45 |
my $schema = Koha::Database->new->schema; |
46 |
my $builder = t::lib::TestBuilder->new; |
46 |
my $builder = t::lib::TestBuilder->new; |
47 |
|
47 |
|
|
|
48 |
subtest '_status' => sub { |
49 |
plan tests => 12; |
50 |
|
51 |
$schema->storage->txn_begin; |
52 |
|
53 |
my $item = $builder->build_sample_item(); |
54 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
55 |
t::lib::Mocks::mock_userenv({ |
56 |
branchcode => $library->branchcode |
57 |
}); |
58 |
|
59 |
t::lib::Mocks::mock_preference('UseRecalls', 1); |
60 |
|
61 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
62 |
|
63 |
my @test_cases = ( |
64 |
{ |
65 |
setup => sub { |
66 |
my $onloan_item = $builder->build_sample_item(); |
67 |
AddIssue( $patron, $onloan_item->barcode, dt_from_string ); |
68 |
return $onloan_item; |
69 |
}, |
70 |
expected_status => 'checked_out', |
71 |
description => 'Checked out status correctly returned', |
72 |
}, |
73 |
{ |
74 |
setup => sub { |
75 |
my $onsite_item = $builder->build_sample_item(); |
76 |
AddIssue( $patron, $onsite_item->barcode, dt_from_string, undef, undef, undef, { onsite_checkout => 1 } ); |
77 |
return $onsite_item; |
78 |
}, |
79 |
expected_status => 'local_use', |
80 |
description => 'Local use status correctly returned', |
81 |
}, |
82 |
{ |
83 |
setup => sub { |
84 |
return $item; |
85 |
}, |
86 |
expected_status => 'available', |
87 |
description => 'Available status correctly returned', |
88 |
}, |
89 |
{ |
90 |
setup => sub { |
91 |
$item->itemlost(1)->store(); |
92 |
return $item; |
93 |
}, |
94 |
expected_status => 'lost', |
95 |
description => 'Lost status correctly returned', |
96 |
}, |
97 |
{ |
98 |
setup => sub { |
99 |
$item->withdrawn(1)->store(); |
100 |
return $item; |
101 |
}, |
102 |
expected_status => qr/lost,withdrawn/, |
103 |
description => 'Lost and withdrawn status correctly returned', |
104 |
}, |
105 |
{ |
106 |
setup => sub { |
107 |
$item->damaged(1)->store(); |
108 |
return $item; |
109 |
}, |
110 |
expected_status => qr/lost,withdrawn,damaged/, |
111 |
description => 'Lost, withdrawn, and damaged status correctly returned', |
112 |
}, |
113 |
{ |
114 |
setup => sub { |
115 |
$item->notforloan(1)->store(); |
116 |
return $item; |
117 |
}, |
118 |
expected_status => 'not_for_loan', |
119 |
description => 'Positive not_for_loan status correctly returned', |
120 |
}, |
121 |
{ |
122 |
setup => sub { |
123 |
$item->notforloan(-1)->store(); |
124 |
return $item; |
125 |
}, |
126 |
expected_status => 'not_for_loan', |
127 |
description => 'Negative not_for_loan status correctly returned', |
128 |
}, |
129 |
{ |
130 |
setup => sub { |
131 |
my $itemtype = $builder->build_object( { class => "Koha::ItemTypes", value => { notforloan => 1 } } ); |
132 |
my $notforloan_item = $builder->build_sample_item( { itype => $itemtype->itemtype, } ); |
133 |
return $notforloan_item; |
134 |
}, |
135 |
expected_status => 'not_for_loan', |
136 |
description => 'Item type not_for_loan status correctly returned', |
137 |
}, |
138 |
{ |
139 |
setup => sub { |
140 |
my $onhold_item = $builder->build_sample_item(); |
141 |
C4::Reserves::AddReserve( |
142 |
{ |
143 |
branchcode => $library->branchcode, |
144 |
borrowernumber => $patron->borrowernumber, |
145 |
biblionumber => $onhold_item->biblionumber, |
146 |
itemnumber => $onhold_item->itemnumber, |
147 |
} |
148 |
); |
149 |
return $onhold_item; |
150 |
}, |
151 |
expected_status => 'on_hold', |
152 |
description => 'On hold status correctly returned', |
153 |
}, |
154 |
{ |
155 |
setup => sub { |
156 |
my $recalled_item = $builder->build_sample_item(); |
157 |
AddIssue( $patron, $recalled_item->barcode, dt_from_string ); |
158 |
Koha::Recalls->add_recall( |
159 |
{ biblio => $recalled_item->biblio, item => $recalled_item, patron => $patron } ); |
160 |
return $recalled_item; |
161 |
}, |
162 |
expected_status => 'recalled', |
163 |
description => 'Recalled status correctly returned', |
164 |
}, |
165 |
{ |
166 |
setup => sub { |
167 |
$item->restricted(1)->store(); |
168 |
return $item; |
169 |
}, |
170 |
expected_status => 'restricted', |
171 |
description => 'Restricted status correctly returned', |
172 |
}, |
173 |
); |
174 |
|
175 |
|
176 |
foreach my $test_case (@test_cases) { |
177 |
my $item = $test_case->{setup}->(); |
178 |
ok( $item->_status() =~ /$test_case->{expected_status}/, $test_case->{description} ); |
179 |
} |
180 |
|
181 |
t::lib::Mocks::mock_preference('UseRecalls', 0); |
182 |
|
183 |
$schema->storage->txn_rollback; |
184 |
}; |
185 |
|
48 |
subtest 'z3950_status' => sub { |
186 |
subtest 'z3950_status' => sub { |
49 |
plan tests => 9; |
187 |
plan tests => 9; |
50 |
|
188 |
|
51 |
- |
|
|