|
Lines 330-332
subtest "TO_JSON() tests" => sub {
Link Here
|
| 330 |
|
330 |
|
| 331 |
$schema->storage->txn_rollback; |
331 |
$schema->storage->txn_rollback; |
| 332 |
}; |
332 |
}; |
| 333 |
- |
333 |
|
|
|
334 |
# Koha::Object[s] must behave the same as DBIx::Class |
| 335 |
subtest 'Return same values as DBIx::Class' => sub { |
| 336 |
plan tests => 1; |
| 337 |
|
| 338 |
subtest 'Delete' => sub { |
| 339 |
plan tests => 2; |
| 340 |
|
| 341 |
$schema->storage->txn_begin; |
| 342 |
|
| 343 |
subtest 'Simple Koha::Objects - Koha::Cities' => sub { |
| 344 |
plan tests => 3; |
| 345 |
|
| 346 |
my ( $r_us, $e_us, $r_them, $e_them ); |
| 347 |
{ |
| 348 |
my $c = Koha::City->new({ city_name => 'city4test' }); |
| 349 |
try {$r_us = $c->delete;} catch { $e_us = ref($_) }; |
| 350 |
|
| 351 |
|
| 352 |
$c = $schema->resultset('City')->new({ city_name => 'city4test' }); |
| 353 |
try {$r_them = $c->delete;} catch { $e_them = ref($_) }; |
| 354 |
|
| 355 |
is( $r_us, $r_them ); |
| 356 |
is( $e_us, $e_them ); # FIXME This is need adjustment, we want to throw a Koha::Exception |
| 357 |
} |
| 358 |
|
| 359 |
{ |
| 360 |
|
| 361 |
my $city = $builder->build_object({ class => 'Koha::Cities' }); |
| 362 |
try{ |
| 363 |
$schema->storage->txn_do(sub{ |
| 364 |
my $c = Koha::Cities->find($city->cityid); |
| 365 |
$r_us = $c->delete; |
| 366 |
$c->update({force_fail=>'foo'}); |
| 367 |
});}; |
| 368 |
try{ |
| 369 |
$schema->storage->txn_do(sub{ |
| 370 |
my $c = $schema->resultset('City')->find($city->cityid); |
| 371 |
$r_them = $c->delete; |
| 372 |
$c->update({force_fail=>'foo'}); |
| 373 |
});}; |
| 374 |
is( $r_us, $r_them ); |
| 375 |
} |
| 376 |
}; |
| 377 |
|
| 378 |
subtest 'Overwritten Koha::Objects->delete - Koha::Patrons' => sub { |
| 379 |
plan tests => 4; |
| 380 |
|
| 381 |
my ( $r_us, $e_us, $r_them, $e_them ); |
| 382 |
|
| 383 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 384 |
my $patron_data = $patron->unblessed; |
| 385 |
$patron->delete; |
| 386 |
|
| 387 |
{ |
| 388 |
my $p = Koha::Patron->new( $patron_data ); |
| 389 |
try {$r_us = $p->delete;} catch { $e_us = ref($_) }; |
| 390 |
|
| 391 |
|
| 392 |
$p = $schema->resultset('Borrower')->new( $patron_data ); |
| 393 |
try {$r_them = $p->delete;} catch { $e_them = ref($_) }; |
| 394 |
|
| 395 |
is( $r_us, $r_them ); |
| 396 |
is( $e_us, $e_them ); # FIXME This is need adjustment, we want to throw a Koha::Exception |
| 397 |
} |
| 398 |
|
| 399 |
{ |
| 400 |
try { |
| 401 |
$schema->storage->txn_do( |
| 402 |
sub { |
| 403 |
my $p = Koha::Patrons->find( $patron->borrowernumber ); |
| 404 |
$r_us = $p->delete; |
| 405 |
$p->update( { force_fail => 'foo' } ); |
| 406 |
} |
| 407 |
); |
| 408 |
}; |
| 409 |
try { |
| 410 |
$schema->storage->txn_do( |
| 411 |
sub { |
| 412 |
my $p = $schema->resultset('City')->find( $patron->borrowernumber ); |
| 413 |
$r_them = $p->delete; |
| 414 |
$p->update( { force_fail => 'foo' } ); |
| 415 |
} |
| 416 |
); |
| 417 |
}; |
| 418 |
is( $r_us, $r_them ); |
| 419 |
} |
| 420 |
|
| 421 |
# TODO Test value of Koha::Object->delete when the row cannot be deleted |
| 422 |
|
| 423 |
# TODO Add tests for Koha::Objects->delete |
| 424 |
}; |
| 425 |
|
| 426 |
$schema->storage->txn_rollback; |
| 427 |
|
| 428 |
}; |
| 429 |
}; |