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 );
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 );
$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);
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,
is( $gonenoaddress, 0, 'Boolean attribute value is correct (false)' );
ok( !isvstring($patron->borrowernumber), 'Integer values are not coded as strings' );
+
+ $schema->storage->txn_rollback;
};