|
Lines 280-282
subtest '->search() tests' => sub {
Link Here
|
| 280 |
|
280 |
|
| 281 |
$schema->storage->txn_rollback; |
281 |
$schema->storage->txn_rollback; |
| 282 |
}; |
282 |
}; |
| 283 |
- |
283 |
|
|
|
284 |
# Koha::Object[s] must behave the same as DBIx::Class |
| 285 |
subtest 'Return same values as DBIx::Class' => sub { |
| 286 |
plan tests => 1; |
| 287 |
|
| 288 |
subtest 'Delete' => sub { |
| 289 |
plan tests => 2; |
| 290 |
|
| 291 |
$schema->storage->txn_begin; |
| 292 |
|
| 293 |
subtest 'Simple Koha::Objects - Koha::Cities' => sub { |
| 294 |
plan tests => 3; |
| 295 |
|
| 296 |
my ( $r_us, $e_us, $r_them, $e_them ); |
| 297 |
{ |
| 298 |
my $c = Koha::City->new({ city_name => 'city4test' }); |
| 299 |
try {$r_us = $c->delete;} catch { $e_us = ref($_) }; |
| 300 |
|
| 301 |
|
| 302 |
$c = $schema->resultset('City')->new({ city_name => 'city4test' }); |
| 303 |
try {$r_them = $c->delete;} catch { $e_them = ref($_) }; |
| 304 |
|
| 305 |
is( $r_us, $r_them ); |
| 306 |
is( $e_us, $e_them ); # FIXME This is need adjustment, we want to throw a Koha::Exception |
| 307 |
} |
| 308 |
|
| 309 |
{ |
| 310 |
|
| 311 |
my $city = $builder->build_object({ class => 'Koha::Cities' }); |
| 312 |
try{ |
| 313 |
$schema->storage->txn_do(sub{ |
| 314 |
my $c = Koha::Cities->find($city->cityid); |
| 315 |
$r_us = $c->delete; |
| 316 |
$c->update({force_fail=>'foo'}); |
| 317 |
});}; |
| 318 |
try{ |
| 319 |
$schema->storage->txn_do(sub{ |
| 320 |
my $c = $schema->resultset('City')->find($city->cityid); |
| 321 |
$r_them = $c->delete; |
| 322 |
$c->update({force_fail=>'foo'}); |
| 323 |
});}; |
| 324 |
is( $r_us, $r_them ); |
| 325 |
} |
| 326 |
}; |
| 327 |
|
| 328 |
subtest 'Overwritten Koha::Objects->delete - Koha::Patrons' => sub { |
| 329 |
plan tests => 4; |
| 330 |
|
| 331 |
my ( $r_us, $e_us, $r_them, $e_them ); |
| 332 |
|
| 333 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 334 |
my $patron_data = $patron->unblessed; |
| 335 |
$patron->delete; |
| 336 |
|
| 337 |
{ |
| 338 |
my $p = Koha::Patron->new( $patron_data ); |
| 339 |
try {$r_us = $p->delete;} catch { $e_us = ref($_) }; |
| 340 |
|
| 341 |
|
| 342 |
$p = $schema->resultset('Borrower')->new( $patron_data ); |
| 343 |
try {$r_them = $p->delete;} catch { $e_them = ref($_) }; |
| 344 |
|
| 345 |
is( $r_us, $r_them ); |
| 346 |
is( $e_us, $e_them ); # FIXME This is need adjustment, we want to throw a Koha::Exception |
| 347 |
} |
| 348 |
|
| 349 |
{ |
| 350 |
try { |
| 351 |
$schema->storage->txn_do( |
| 352 |
sub { |
| 353 |
my $p = Koha::Patrons->find( $patron->borrowernumber ); |
| 354 |
$r_us = $p->delete; |
| 355 |
$p->update( { force_fail => 'foo' } ); |
| 356 |
} |
| 357 |
); |
| 358 |
}; |
| 359 |
try { |
| 360 |
$schema->storage->txn_do( |
| 361 |
sub { |
| 362 |
my $p = $schema->resultset('City')->find( $patron->borrowernumber ); |
| 363 |
$r_them = $p->delete; |
| 364 |
$p->update( { force_fail => 'foo' } ); |
| 365 |
} |
| 366 |
); |
| 367 |
}; |
| 368 |
is( $r_us, $r_them ); |
| 369 |
} |
| 370 |
|
| 371 |
# TODO Test value of Koha::Object->delete when the row cannot be deleted |
| 372 |
|
| 373 |
# TODO Add tests for Koha::Objects->delete |
| 374 |
}; |
| 375 |
|
| 376 |
$schema->storage->txn_rollback; |
| 377 |
|
| 378 |
}; |
| 379 |
}; |