|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 14; |
22 |
use Test::More tests => 15; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
|
25 |
|
|
Lines 254-256
subtest '->is_paged and ->pager tests' => sub {
Link Here
|
| 254 |
|
254 |
|
| 255 |
$schema->storage->txn_rollback; |
255 |
$schema->storage->txn_rollback; |
| 256 |
}; |
256 |
}; |
| 257 |
- |
257 |
|
|
|
258 |
# Koha::Object[s] must behave the same as DBIx::Class |
| 259 |
subtest 'Return same values as DBIx::Class' => sub { |
| 260 |
plan tests => 1; |
| 261 |
|
| 262 |
subtest 'Delete' => sub { |
| 263 |
plan tests => 2; |
| 264 |
|
| 265 |
$schema->storage->txn_begin; |
| 266 |
|
| 267 |
subtest 'Simple Koha::Objects - Koha::Cities' => sub { |
| 268 |
plan tests => 3; |
| 269 |
|
| 270 |
my ( $r_us, $e_us, $r_them, $e_them ); |
| 271 |
{ |
| 272 |
my $c = Koha::City->new({ city_name => 'city4test' }); |
| 273 |
try {$r_us = $c->delete;} catch { $e_us = ref($_) }; |
| 274 |
|
| 275 |
|
| 276 |
$c = $schema->resultset('City')->new({ city_name => 'city4test' }); |
| 277 |
try {$r_them = $c->delete;} catch { $e_them = ref($_) }; |
| 278 |
|
| 279 |
is( $r_us, $r_them ); |
| 280 |
is( $e_us, $e_them ); # FIXME This is need adjustment, we want to throw a Koha::Exception |
| 281 |
} |
| 282 |
|
| 283 |
{ |
| 284 |
|
| 285 |
my $city = $builder->build_object({ class => 'Koha::Cities' }); |
| 286 |
try{ |
| 287 |
$schema->storage->txn_do(sub{ |
| 288 |
my $c = Koha::Cities->find($city->cityid); |
| 289 |
$r_us = $c->delete; |
| 290 |
$c->update({force_fail=>'foo'}); |
| 291 |
});}; |
| 292 |
try{ |
| 293 |
$schema->storage->txn_do(sub{ |
| 294 |
my $c = $schema->resultset('City')->find($city->cityid); |
| 295 |
$r_them = $c->delete; |
| 296 |
$c->update({force_fail=>'foo'}); |
| 297 |
});}; |
| 298 |
is( $r_us, $r_them ); |
| 299 |
} |
| 300 |
}; |
| 301 |
|
| 302 |
subtest 'Overwritten Koha::Objects->delete - Koha::Patrons' => sub { |
| 303 |
plan tests => 4; |
| 304 |
|
| 305 |
my ( $r_us, $e_us, $r_them, $e_them ); |
| 306 |
|
| 307 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 308 |
my $patron_data = $patron->unblessed; |
| 309 |
$patron->delete; |
| 310 |
|
| 311 |
{ |
| 312 |
my $p = Koha::Patron->new( $patron_data ); |
| 313 |
try {$r_us = $p->delete;} catch { $e_us = ref($_) }; |
| 314 |
|
| 315 |
|
| 316 |
$p = $schema->resultset('Borrower')->new( $patron_data ); |
| 317 |
try {$r_them = $p->delete;} catch { $e_them = ref($_) }; |
| 318 |
|
| 319 |
is( $r_us, $r_them ); |
| 320 |
is( $e_us, $e_them ); # FIXME This is need adjustment, we want to throw a Koha::Exception |
| 321 |
} |
| 322 |
|
| 323 |
{ |
| 324 |
try { |
| 325 |
$schema->storage->txn_do( |
| 326 |
sub { |
| 327 |
my $p = Koha::Patrons->find( $patron->borrowernumber ); |
| 328 |
$r_us = $p->delete; |
| 329 |
$p->update( { force_fail => 'foo' } ); |
| 330 |
} |
| 331 |
); |
| 332 |
}; |
| 333 |
try { |
| 334 |
$schema->storage->txn_do( |
| 335 |
sub { |
| 336 |
my $p = $schema->resultset('City')->find( $patron->borrowernumber ); |
| 337 |
$r_them = $p->delete; |
| 338 |
$p->update( { force_fail => 'foo' } ); |
| 339 |
} |
| 340 |
); |
| 341 |
}; |
| 342 |
is( $r_us, $r_them ); |
| 343 |
} |
| 344 |
|
| 345 |
# TODO Test value of Koha::Object->delete when the row cannot be deleted |
| 346 |
|
| 347 |
# TODO Add tests for Koha::Objects->delete |
| 348 |
}; |
| 349 |
|
| 350 |
$schema->storage->txn_rollback; |
| 351 |
|
| 352 |
}; |
| 353 |
}; |