From b6de10944c768dcd80f85029c1a068d6b53a12f6 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 24 Jan 2017 10:48:31 -0300 Subject: [PATCH] Bug 17932: (followup) Tidy tests This patch makes the tests create its own data instead of searching the DB for a branchcode and a categorycode. It does so on each subtest, because there shouldn't be side effects between subtests. I also wrapped each subtest inside a transaction, for the same reason. To test: - Apply this patch - Run: $ prove t/db_dependent/Koha/Object.t => SUCCESS: Tests return green with this patch - Sign off :-D Signed-off-by: Nick Clemens Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall --- t/db_dependent/Koha/Object.t | 49 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/t/db_dependent/Koha/Object.t b/t/db_dependent/Koha/Object.t index fd5d89b0a3..d812d37a19 100755 --- a/t/db_dependent/Koha/Object.t +++ b/t/db_dependent/Koha/Object.t @@ -33,16 +33,17 @@ BEGIN { use_ok('Koha::Patron'); } -my $schema = Koha::Database->new->schema; -$schema->storage->txn_begin; - +my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new(); -my $categorycode = $schema->resultset('Category')->first()->categorycode(); -my $branchcode = $schema->resultset('Branch')->first()->branchcode(); - subtest 'is_changed' => sub { plan tests => 6; + + $schema->storage->txn_begin; + + my $categorycode = $builder->build({ source => 'Category' })->{categorycode}; + my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; + my $object = Koha::Patron->new(); $object->categorycode( $categorycode ); $object->branchcode( $branchcode ); @@ -61,10 +62,18 @@ subtest 'is_changed' => sub { is( $object->is_changed(), 1, "Object is changed after Set" ); $object->store(); is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" ); + + $schema->storage->txn_rollback; }; subtest 'in_storage' => sub { plan tests => 6; + + $schema->storage->txn_begin; + + my $categorycode = $builder->build({ source => 'Category' })->{categorycode}; + my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; + my $object = Koha::Patron->new(); is( $object->in_storage, 0, "Object is not in storage" ); $object->categorycode( $categorycode ); @@ -83,23 +92,43 @@ subtest 'in_storage' => sub { $patron = $schema->resultset('Borrower')->find( $borrowernumber ); ok( ! $patron, "Object no longer found in database" ); is( $object->in_storage, 0, "Object is not in storage" ); + + $schema->storage->txn_rollback; }; subtest 'id' => sub { plan tests => 1; + + $schema->storage->txn_begin; + + my $categorycode = $builder->build({ source => 'Category' })->{categorycode}; + my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; + my $patron = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode })->store; is( $patron->id, $patron->borrowernumber ); + + $schema->storage->txn_rollback; }; subtest 'get_column' => sub { plan tests => 1; + + $schema->storage->txn_begin; + + my $categorycode = $builder->build({ source => 'Category' })->{categorycode}; + my $branchcode = $builder->build({ source => 'Branch' })->{branchcode}; + my $patron = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode })->store; is( $patron->get_column('borrowernumber'), $patron->borrowernumber, 'get_column should retrieve the correct value' ); + + $schema->storage->txn_rollback; }; subtest 'discard_changes' => sub { plan tests => 1; - my $builder = t::lib::TestBuilder->new; + + $schema->storage->txn_begin; + my $patron = $builder->build( { source => 'Borrower' } ); $patron = Koha::Patrons->find( $patron->{borrowernumber} ); $patron->dateexpiry(dt_from_string); @@ -109,12 +138,16 @@ subtest 'discard_changes' => sub { dt_from_string->truncate( to => 'day' ), 'discard_changes should refresh the object' ); + + $schema->storage->txn_rollback; }; subtest 'TO_JSON tests' => sub { plan tests => 5; + $schema->storage->txn_begin; + my $borrowernumber = $builder->build( { source => 'Borrower', value => { lost => 1, @@ -131,6 +164,8 @@ subtest 'TO_JSON tests' => sub { is( $gonenoaddress, 0, 'Boolean attribute value is correct (false)' ); ok( !isvstring($patron->borrowernumber), 'Integer values are not coded as strings' ); + + $schema->storage->txn_rollback; }; -- 2.11.4.GIT