Bug 37898: Wrap Relationships.t inside a transaction

This tests leave data on the DB and need to be fixed. This patch does
that.

To test:
1. Run:
   $ ktd --shell
  k$ echo "SELECT COUNT(*) FROM borrowers \G" | koha-mysql kohadev
  k$ echo "SELECT COUNT(*) FROM borrower_relationships \G" | koha-mysql kohadev
2. Run:
  k$ prove t/db_dependent/Patron/Relationships.t
=> SUCCESS: Tests pass
3. Repeat 1
=> FAIL: Numbers don't match the original ones!
4. Apply this patch
5. Repeat 2 and 3
=> SUCCESS: Tests still pass!
=> SUCCESS: Numbers match!
6. Sign off :-D

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomás Cohen Arazi 2024-09-11 12:55:40 -03:00 committed by Martin Renvoize
parent e052614d7f
commit be0931fdf7
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F

View file

@ -20,6 +20,7 @@ use Modern::Perl;
use Test::More tests => 54; use Test::More tests => 54;
use C4::Context; use C4::Context;
use Koha::Database;
use t::lib::TestBuilder; use t::lib::TestBuilder;
@ -30,57 +31,52 @@ BEGIN {
use_ok('Koha::Patron::Relationships'); use_ok('Koha::Patron::Relationships');
} }
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new(); my $builder = t::lib::TestBuilder->new();
$schema->storage->txn_begin;
# Father # Father
my $kyle = Koha::Patrons->find( my $kyle = $builder->build_object(
$builder->build( {
{ class => 'Koha::Patrons',
source => 'Borrower', value => {
value => { firstname => 'Kyle',
firstname => 'Kyle', surname => 'Hall',
surname => 'Hall',
}
} }
)->{borrowernumber} }
); );
# Mother # Mother
my $chelsea = Koha::Patrons->find( my $chelsea = $builder->build_object(
$builder->build( {
{ class => 'Koha::Patrons',
source => 'Borrower', value => {
value => { firstname => 'Chelsea',
firstname => 'Chelsea', surname => 'Hall',
surname => 'Hall',
}
} }
)->{borrowernumber} }
); );
# Children # Children
my $daria = Koha::Patrons->find( my $daria = $builder->build_object(
$builder->build( {
{ class => 'Koha::Patrons',
source => 'Borrower', value => {
value => { firstname => 'Daria',
firstname => 'Daria', surname => 'Hall',
surname => 'Hall',
}
} }
)->{borrowernumber} }
); );
my $kylie = Koha::Patrons->find( my $kylie = $builder->build_object(
$builder->build( {
{ class => 'Koha::Patrons',
source => 'Borrower', value => {
value => { firstname => 'Kylie',
firstname => 'Kylie', surname => 'Hall',
surname => 'Hall',
}
} }
)->{borrowernumber} }
); );
Koha::Patron::Relationship->new({ guarantor_id => $kyle->id, guarantee_id => $daria->id, relationship => 'father' })->store(); Koha::Patron::Relationship->new({ guarantor_id => $kyle->id, guarantee_id => $daria->id, relationship => 'father' })->store();
@ -152,4 +148,4 @@ is( $sibling->firstname, 'Kylie', 'Sibling from scalar first name matches correc
is( $sibling->surname, 'Hall', 'Sibling from scalar surname matches correctly' ); is( $sibling->surname, 'Hall', 'Sibling from scalar surname matches correctly' );
is( $sibling->id, $kylie->id, 'Sibling from scalar patron id matches correctly' ); is( $sibling->id, $kylie->id, 'Sibling from scalar patron id matches correctly' );
1; $schema->storage->txn_rollback;