From aa74f104179b61b1b5657b93fca4f721eb1ead25 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 26 Oct 2018 13:54:47 -0300 Subject: [PATCH] Bug 21684: Add tests to show some of the discrepancies --- t/db_dependent/Koha/Objects.t | 97 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t index db7711e0db..6d5a01eeb9 100644 --- a/t/db_dependent/Koha/Objects.t +++ b/t/db_dependent/Koha/Objects.t @@ -280,3 +280,100 @@ subtest '->search() tests' => sub { $schema->storage->txn_rollback; }; + +# Koha::Object[s] must behave the same as DBIx::Class +subtest 'Return same values as DBIx::Class' => sub { + plan tests => 1; + + subtest 'Delete' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + + subtest 'Simple Koha::Objects - Koha::Cities' => sub { + plan tests => 3; + + my ( $r_us, $e_us, $r_them, $e_them ); + { + my $c = Koha::City->new({ city_name => 'city4test' }); + try {$r_us = $c->delete;} catch { $e_us = ref($_) }; + + + $c = $schema->resultset('City')->new({ city_name => 'city4test' }); + try {$r_them = $c->delete;} catch { $e_them = ref($_) }; + + is( $r_us, $r_them ); + is( $e_us, $e_them ); # FIXME This is need adjustment, we want to throw a Koha::Exception + } + + { + + my $city = $builder->build_object({ class => 'Koha::Cities' }); + try{ + $schema->storage->txn_do(sub{ + my $c = Koha::Cities->find($city->cityid); + $r_us = $c->delete; + $c->update({force_fail=>'foo'}); + });}; + try{ + $schema->storage->txn_do(sub{ + my $c = $schema->resultset('City')->find($city->cityid); + $r_them = $c->delete; + $c->update({force_fail=>'foo'}); + });}; + is( $r_us, $r_them ); + } + }; + + subtest 'Overwritten Koha::Objects->delete - Koha::Patrons' => sub { + plan tests => 4; + + my ( $r_us, $e_us, $r_them, $e_them ); + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + my $patron_data = $patron->unblessed; + $patron->delete; + + { + my $p = Koha::Patron->new( $patron_data ); + try {$r_us = $p->delete;} catch { $e_us = ref($_) }; + + + $p = $schema->resultset('Borrower')->new( $patron_data ); + try {$r_them = $p->delete;} catch { $e_them = ref($_) }; + + is( $r_us, $r_them ); + is( $e_us, $e_them ); # FIXME This is need adjustment, we want to throw a Koha::Exception + } + + { + try { + $schema->storage->txn_do( + sub { + my $p = Koha::Patrons->find( $patron->borrowernumber ); + $r_us = $p->delete; + $p->update( { force_fail => 'foo' } ); + } + ); + }; + try { + $schema->storage->txn_do( + sub { + my $p = $schema->resultset('City')->find( $patron->borrowernumber ); + $r_them = $p->delete; + $p->update( { force_fail => 'foo' } ); + } + ); + }; + is( $r_us, $r_them ); + } + + # TODO Test value of Koha::Object->delete when the row cannot be deleted + + # TODO Add tests for Koha::Objects->delete + }; + + $schema->storage->txn_rollback; + + }; +}; -- 2.11.0