Lines 33-39
my $schema = Koha::Database->new->schema;
Link Here
|
33 |
my $builder = t::lib::TestBuilder->new; |
33 |
my $builder = t::lib::TestBuilder->new; |
34 |
|
34 |
|
35 |
subtest 'Relation accessor tests' => sub { |
35 |
subtest 'Relation accessor tests' => sub { |
36 |
plan tests => 3; |
36 |
plan tests => 4; |
37 |
|
37 |
|
38 |
subtest 'biblio relation tests' => sub { |
38 |
subtest 'biblio relation tests' => sub { |
39 |
plan tests => 3; |
39 |
plan tests => 3; |
Lines 76-81
subtest 'Relation accessor tests' => sub {
Link Here
|
76 |
$schema->storage->txn_rollback; |
76 |
$schema->storage->txn_rollback; |
77 |
}; |
77 |
}; |
78 |
|
78 |
|
|
|
79 |
subtest 'pickup_library relation tests' => sub { |
80 |
plan tests => 3; |
81 |
$schema->storage->txn_begin; |
82 |
|
83 |
my $pickup_library = $builder->build_object( { class => "Koha::Libraries" } ); |
84 |
my $booking = |
85 |
$builder->build_object( |
86 |
{ class => 'Koha::Bookings', value => { pickup_library_id => $pickup_library->branchcode } } ); |
87 |
|
88 |
my $THE_pickup_library = $booking->pickup_library; |
89 |
is( ref($THE_pickup_library), 'Koha::Library', "Koha::Booking->pickup_library returns a Koha::Library object" ); |
90 |
is( |
91 |
$THE_pickup_library->branchcode, $pickup_library->branchcode, |
92 |
"Koha::Booking->pickup_library returns the linked pickup library object" |
93 |
); |
94 |
|
95 |
$THE_pickup_library->delete; |
96 |
$booking = Koha::Bookings->find( $booking->booking_id ); |
97 |
is( $booking, undef, "The booking is deleted when the pickup_library it's attached to is deleted" ); |
98 |
|
99 |
$schema->storage->txn_rollback; |
100 |
}; |
101 |
|
79 |
subtest 'item relation tests' => sub { |
102 |
subtest 'item relation tests' => sub { |
80 |
plan tests => 3; |
103 |
plan tests => 3; |
81 |
$schema->storage->txn_begin; |
104 |
$schema->storage->txn_begin; |
Lines 116-126
subtest 'store() tests' => sub {
Link Here
|
116 |
|
139 |
|
117 |
my $booking = Koha::Booking->new( |
140 |
my $booking = Koha::Booking->new( |
118 |
{ |
141 |
{ |
119 |
patron_id => $patron->borrowernumber, |
142 |
patron_id => $patron->borrowernumber, |
120 |
biblio_id => $biblio->biblionumber, |
143 |
biblio_id => $biblio->biblionumber, |
121 |
item_id => $deleted_item->itemnumber, |
144 |
item_id => $deleted_item->itemnumber, |
122 |
start_date => $start_0, |
145 |
pickup_library_id => $deleted_item->homebranch, |
123 |
end_date => $end_0 |
146 |
start_date => $start_0, |
|
|
147 |
end_date => $end_0 |
124 |
} |
148 |
} |
125 |
); |
149 |
); |
126 |
|
150 |
|
Lines 129-139
subtest 'store() tests' => sub {
Link Here
|
129 |
|
153 |
|
130 |
$booking = Koha::Booking->new( |
154 |
$booking = Koha::Booking->new( |
131 |
{ |
155 |
{ |
132 |
patron_id => $patron->borrowernumber, |
156 |
patron_id => $patron->borrowernumber, |
133 |
biblio_id => $biblio->biblionumber, |
157 |
biblio_id => $biblio->biblionumber, |
134 |
item_id => $wrong_item->itemnumber, |
158 |
item_id => $wrong_item->itemnumber, |
135 |
start_date => $start_0, |
159 |
pickup_library_id => $wrong_item->homebranch, |
136 |
end_date => $end_0 |
160 |
start_date => $start_0, |
|
|
161 |
end_date => $end_0 |
137 |
} |
162 |
} |
138 |
); |
163 |
); |
139 |
|
164 |
|
Lines 142-152
subtest 'store() tests' => sub {
Link Here
|
142 |
|
167 |
|
143 |
$booking = Koha::Booking->new( |
168 |
$booking = Koha::Booking->new( |
144 |
{ |
169 |
{ |
145 |
patron_id => $patron->borrowernumber, |
170 |
patron_id => $patron->borrowernumber, |
146 |
biblio_id => $biblio->biblionumber, |
171 |
biblio_id => $biblio->biblionumber, |
147 |
item_id => $item_1->itemnumber, |
172 |
item_id => $item_1->itemnumber, |
148 |
start_date => $start_0, |
173 |
pickup_library_id => $item_1->homebranch, |
149 |
end_date => $end_0 |
174 |
start_date => $start_0, |
|
|
175 |
end_date => $end_0 |
150 |
} |
176 |
} |
151 |
); |
177 |
); |
152 |
|
178 |
|
Lines 166-176
subtest 'store() tests' => sub {
Link Here
|
166 |
my $end_1 = $start_1->clone()->add( days => 6 ); |
192 |
my $end_1 = $start_1->clone()->add( days => 6 ); |
167 |
$booking = Koha::Booking->new( |
193 |
$booking = Koha::Booking->new( |
168 |
{ |
194 |
{ |
169 |
patron_id => $patron->borrowernumber, |
195 |
patron_id => $patron->borrowernumber, |
170 |
biblio_id => $biblio->biblionumber, |
196 |
biblio_id => $biblio->biblionumber, |
171 |
item_id => $item_1->itemnumber, |
197 |
item_id => $item_1->itemnumber, |
172 |
start_date => $start_1, |
198 |
pickup_library_id => $item_1->homebranch, |
173 |
end_date => $end_1 |
199 |
start_date => $start_1, |
|
|
200 |
end_date => $end_1 |
174 |
} |
201 |
} |
175 |
); |
202 |
); |
176 |
throws_ok { $booking->store } 'Koha::Exceptions::Booking::Clash', |
203 |
throws_ok { $booking->store } 'Koha::Exceptions::Booking::Clash', |
Lines 183-193
subtest 'store() tests' => sub {
Link Here
|
183 |
$end_1 = $start_1->clone()->add( days => 6 ); |
210 |
$end_1 = $start_1->clone()->add( days => 6 ); |
184 |
$booking = Koha::Booking->new( |
211 |
$booking = Koha::Booking->new( |
185 |
{ |
212 |
{ |
186 |
patron_id => $patron->borrowernumber, |
213 |
patron_id => $patron->borrowernumber, |
187 |
biblio_id => $biblio->biblionumber, |
214 |
biblio_id => $biblio->biblionumber, |
188 |
item_id => $item_1->itemnumber, |
215 |
item_id => $item_1->itemnumber, |
189 |
start_date => $start_1, |
216 |
pickup_library_id => $item_1->homebranch, |
190 |
end_date => $end_1 |
217 |
start_date => $start_1, |
|
|
218 |
end_date => $end_1 |
191 |
} |
219 |
} |
192 |
); |
220 |
); |
193 |
throws_ok { $booking->store } 'Koha::Exceptions::Booking::Clash', |
221 |
throws_ok { $booking->store } 'Koha::Exceptions::Booking::Clash', |
Lines 200-210
subtest 'store() tests' => sub {
Link Here
|
200 |
$end_1 = $start_1->clone()->add( days => 10 ); |
228 |
$end_1 = $start_1->clone()->add( days => 10 ); |
201 |
$booking = Koha::Booking->new( |
229 |
$booking = Koha::Booking->new( |
202 |
{ |
230 |
{ |
203 |
patron_id => $patron->borrowernumber, |
231 |
patron_id => $patron->borrowernumber, |
204 |
biblio_id => $biblio->biblionumber, |
232 |
biblio_id => $biblio->biblionumber, |
205 |
item_id => $item_1->itemnumber, |
233 |
item_id => $item_1->itemnumber, |
206 |
start_date => $start_1, |
234 |
pickup_library_id => $item_1->homebranch, |
207 |
end_date => $end_1 |
235 |
start_date => $start_1, |
|
|
236 |
end_date => $end_1 |
208 |
} |
237 |
} |
209 |
); |
238 |
); |
210 |
throws_ok { $booking->store } 'Koha::Exceptions::Booking::Clash', |
239 |
throws_ok { $booking->store } 'Koha::Exceptions::Booking::Clash', |
Lines 217-227
subtest 'store() tests' => sub {
Link Here
|
217 |
$end_1 = $start_1->clone()->add( days => 4 ); |
246 |
$end_1 = $start_1->clone()->add( days => 4 ); |
218 |
$booking = Koha::Booking->new( |
247 |
$booking = Koha::Booking->new( |
219 |
{ |
248 |
{ |
220 |
patron_id => $patron->borrowernumber, |
249 |
patron_id => $patron->borrowernumber, |
221 |
biblio_id => $biblio->biblionumber, |
250 |
biblio_id => $biblio->biblionumber, |
222 |
item_id => $item_1->itemnumber, |
251 |
item_id => $item_1->itemnumber, |
223 |
start_date => $start_1, |
252 |
pickup_library_id => $item_1->homebranch, |
224 |
end_date => $end_1 |
253 |
start_date => $start_1, |
|
|
254 |
end_date => $end_1 |
225 |
} |
255 |
} |
226 |
); |
256 |
); |
227 |
throws_ok { $booking->store } 'Koha::Exceptions::Booking::Clash', |
257 |
throws_ok { $booking->store } 'Koha::Exceptions::Booking::Clash', |
Lines 235-245
subtest 'store() tests' => sub {
Link Here
|
235 |
# ✓ Item 2 |--| |
265 |
# ✓ Item 2 |--| |
236 |
$booking = Koha::Booking->new( |
266 |
$booking = Koha::Booking->new( |
237 |
{ |
267 |
{ |
238 |
patron_id => $patron->borrowernumber, |
268 |
patron_id => $patron->borrowernumber, |
239 |
biblio_id => $biblio->biblionumber, |
269 |
biblio_id => $biblio->biblionumber, |
240 |
item_id => $item_2->itemnumber, |
270 |
item_id => $item_2->itemnumber, |
241 |
start_date => $start_1, |
271 |
pickup_library_id => $item_2->homebranch, |
242 |
end_date => $end_1 |
272 |
start_date => $start_1, |
|
|
273 |
end_date => $end_1 |
243 |
} |
274 |
} |
244 |
)->store(); |
275 |
)->store(); |
245 |
ok( |
276 |
ok( |
Lines 253-262
subtest 'store() tests' => sub {
Link Here
|
253 |
# ✘ Any |--| |
284 |
# ✘ Any |--| |
254 |
$booking = Koha::Booking->new( |
285 |
$booking = Koha::Booking->new( |
255 |
{ |
286 |
{ |
256 |
patron_id => $patron->borrowernumber, |
287 |
patron_id => $patron->borrowernumber, |
257 |
biblio_id => $biblio->biblionumber, |
288 |
biblio_id => $biblio->biblionumber, |
258 |
start_date => $start_1, |
289 |
pickup_library_id => $item_2->homebranch, |
259 |
end_date => $end_1 |
290 |
start_date => $start_1, |
|
|
291 |
end_date => $end_1 |
260 |
} |
292 |
} |
261 |
); |
293 |
); |
262 |
throws_ok { $booking->store } 'Koha::Exceptions::Booking::Clash', |
294 |
throws_ok { $booking->store } 'Koha::Exceptions::Booking::Clash', |
Lines 270-279
subtest 'store() tests' => sub {
Link Here
|
270 |
$end_1 = $start_1->clone()->add( days => 4 ); |
302 |
$end_1 = $start_1->clone()->add( days => 4 ); |
271 |
$booking = Koha::Booking->new( |
303 |
$booking = Koha::Booking->new( |
272 |
{ |
304 |
{ |
273 |
patron_id => $patron->borrowernumber, |
305 |
patron_id => $patron->borrowernumber, |
274 |
biblio_id => $biblio->biblionumber, |
306 |
biblio_id => $biblio->biblionumber, |
275 |
start_date => $start_1, |
307 |
pickup_library_id => $item_2->homebranch, |
276 |
end_date => $end_1 |
308 |
start_date => $start_1, |
|
|
309 |
end_date => $end_1 |
277 |
} |
310 |
} |
278 |
)->store(); |
311 |
)->store(); |
279 |
ok( $booking->in_storage, 'Booking stored OK when item not specified and the booking slot is available' ); |
312 |
ok( $booking->in_storage, 'Booking stored OK when item not specified and the booking slot is available' ); |
280 |
- |
|
|