Lines 17-37
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 2; |
20 |
use Test::More tests => 4; |
21 |
use C4::Context; |
21 |
use C4::Context; |
22 |
use Koha::Biblios; |
22 |
use Koha::Biblios; |
|
|
23 |
use Koha::Biblioitems; |
23 |
use Koha::Database; |
24 |
use Koha::Database; |
24 |
use Koha::Library; |
25 |
use Koha::DateUtils; |
25 |
use Koha::RotatingCollections; |
26 |
use Koha::RotatingCollections; |
26 |
use Koha::Items; |
27 |
use Koha::Items; |
27 |
use Koha::Item::Transfers; |
28 |
use Koha::Item::Transfers; |
28 |
use Koha::Libraries; |
29 |
use Koha::Libraries; |
|
|
30 |
use Koha::Patrons; |
29 |
|
31 |
|
30 |
use t::lib::TestBuilder; |
32 |
use t::lib::TestBuilder; |
|
|
33 |
use Test::MockModule; |
31 |
|
34 |
|
32 |
my $schema = Koha::Database->new->schema; |
35 |
my $schema = Koha::Database->new->schema; |
33 |
my $builder = t::lib::TestBuilder->new; |
36 |
my $builder = t::lib::TestBuilder->new; |
34 |
|
37 |
|
|
|
38 |
|
39 |
# TODO test for untransferred_items |
40 |
# |
35 |
subtest 'remove_and_add_items' => sub { |
41 |
subtest 'remove_and_add_items' => sub { |
36 |
plan tests => 8; |
42 |
plan tests => 8; |
37 |
|
43 |
|
Lines 140-142
subtest 'transfer' => sub {
Link Here
|
140 |
|
146 |
|
141 |
$schema->storage->txn_rollback; |
147 |
$schema->storage->txn_rollback; |
142 |
}; |
148 |
}; |
143 |
- |
149 |
|
|
|
150 |
subtest 'new_create_creator' => sub { |
151 |
plan tests => 3; |
152 |
|
153 |
$schema->storage->txn_begin; |
154 |
|
155 |
my $collection1 = Koha::RotatingCollection->new( { |
156 |
colTitle => "Collection 1", |
157 |
colDesc => "Collection 1 description", |
158 |
} )->store; |
159 |
|
160 |
is($collection1->creator, undef, "Creator should not be set if patron is not set in userenv"); |
161 |
|
162 |
my $categorycode = $builder->build({ source => 'Category' })->{categorycode}; |
163 |
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; |
164 |
|
165 |
my $patron = Koha::Patron->new( { |
166 |
firstname => "Creative", |
167 |
surname => "Librarian", |
168 |
categorycode => $categorycode, |
169 |
branchcode => $branchcode, |
170 |
})->store; |
171 |
|
172 |
my $context = new Test::MockModule('C4::Context'); |
173 |
$context->mock('userenv', sub { |
174 |
return { |
175 |
number => $patron->borrowernumber, |
176 |
} |
177 |
}); |
178 |
my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); |
179 |
|
180 |
my $collection2 = Koha::RotatingCollection->new( { |
181 |
colTitle => "Collection 2", |
182 |
colDesc => "Collection 2 description", |
183 |
} )->store; |
184 |
|
185 |
is( $collection2->createdOn, $today , "Collection create day should be set"); |
186 |
is( $collection2->creator->borrowernumber, $patron->borrowernumber, "Collection creator should be set"); |
187 |
|
188 |
$schema->storage->txn_rollback; |
189 |
}; |
190 |
|
191 |
subtest 'untransferred_items' => sub { |
192 |
plan tests => 5; |
193 |
|
194 |
$schema->storage->txn_begin; |
195 |
|
196 |
my $library1 = Koha::Library->new({ |
197 |
branchcode => "LIBCOL1", |
198 |
branchname => "Library for testing collection 1", |
199 |
})->store; |
200 |
|
201 |
my $library2 = Koha::Library->new({ |
202 |
branchcode => "LIBCOL2", |
203 |
branchname => "Library for testing colletions 2", |
204 |
})->store; |
205 |
|
206 |
my $biblio = Koha::Biblio->new({ |
207 |
author => "Some author 1", |
208 |
title => "Some title 2", |
209 |
})->store; |
210 |
|
211 |
my $biblioitem = Koha::Biblioitem->new({ |
212 |
biblionumber => $biblio->biblionumber, |
213 |
})->store; |
214 |
|
215 |
my $item1 = Koha::Item->new({ |
216 |
barcode => "BC1000001", |
217 |
biblionumber => $biblio->biblionumber, |
218 |
biblioitemnumber => $biblioitem->biblioitemnumber, |
219 |
homebranch => $library1->branchcode, |
220 |
holdingbranch => $library1->branchcode, |
221 |
})->store; |
222 |
|
223 |
my $item2 = Koha::Item->new({ |
224 |
barcode => "BC1000002", |
225 |
biblionumber => $biblio->biblionumber, |
226 |
biblioitemnumber => $biblioitem->biblioitemnumber, |
227 |
homebranch => $library1->branchcode, |
228 |
holdingbranch => $library1->branchcode, |
229 |
})->store; |
230 |
|
231 |
my $item3 = Koha::Item->new({ |
232 |
barcode => "BC1000003", |
233 |
biblionumber => $biblio->biblionumber, |
234 |
biblioitemnumber => $biblioitem->biblioitemnumber, |
235 |
homebranch => $library1->branchcode, |
236 |
holdingbranch => $library1->branchcode, |
237 |
})->store; |
238 |
|
239 |
my $collection = Koha::RotatingCollection->new({ |
240 |
colTitle => "Collection", |
241 |
colDesc => "Collection description", |
242 |
})->store; |
243 |
|
244 |
is($collection->untransferred_items->count, 0, "There are no items, so no untransferred"); |
245 |
|
246 |
$collection->add_item( $item1 ); |
247 |
$collection->add_item( $item2 ); |
248 |
|
249 |
is($collection->untransferred_items->count, 2, "We added 2 items"); |
250 |
|
251 |
$collection->transfer( $library2 ); |
252 |
|
253 |
is($collection->untransferred_items->count, 0, "There are no untransferred items after transfer"); |
254 |
|
255 |
$collection->add_item( $item3 ); |
256 |
|
257 |
is($collection->untransferred_items->count, 1, "We added 1 more item"); |
258 |
is($collection->untransferred_items->next->itemnumber, $item3->itemnumber, "The returned item is the one added after transfer"); |
259 |
|
260 |
$schema->storage->txn_rollback; |
261 |
}; |