|
Lines 37-43
use Koha::Patrons;
Link Here
|
| 37 |
use Koha::Library::Groups; |
37 |
use Koha::Library::Groups; |
| 38 |
|
38 |
|
| 39 |
use JSON; |
39 |
use JSON; |
| 40 |
use Scalar::Util qw( isvstring ); |
40 |
use Scalar::Util qw( isvstring refaddr ); |
| 41 |
use Try::Tiny; |
41 |
use Try::Tiny; |
| 42 |
|
42 |
|
| 43 |
use t::lib::TestBuilder; |
43 |
use t::lib::TestBuilder; |
|
Lines 152-182
subtest 'get_column' => sub {
Link Here
|
| 152 |
$schema->storage->txn_rollback; |
152 |
$schema->storage->txn_rollback; |
| 153 |
}; |
153 |
}; |
| 154 |
|
154 |
|
| 155 |
subtest 'discard_changes' => sub { |
155 |
subtest 'discard_changes() tests' => sub { |
|
|
156 |
|
| 156 |
plan tests => 3; |
157 |
plan tests => 3; |
| 157 |
|
158 |
|
| 158 |
$schema->storage->txn_begin; |
159 |
$schema->storage->txn_begin; |
| 159 |
|
160 |
|
| 160 |
my $patron = $builder->build( { source => 'Borrower' } ); |
161 |
my $date_expiry = dt_from_string->add( days => 30 ); |
| 161 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
162 |
|
|
|
163 |
my $patron = $builder->build_object( |
| 164 |
{ |
| 165 |
class => 'Koha::Patrons', |
| 166 |
value => { dateexpiry => $date_expiry } |
| 167 |
} |
| 168 |
); |
| 162 |
$patron->dateexpiry(dt_from_string); |
169 |
$patron->dateexpiry(dt_from_string); |
| 163 |
$patron->discard_changes; |
170 |
my $ret = $patron->discard_changes; |
| 164 |
is( |
171 |
is( |
| 165 |
dt_from_string( $patron->dateexpiry ), |
172 |
dt_from_string( $patron->dateexpiry ), |
| 166 |
dt_from_string->truncate( to => 'day' ), |
173 |
$date_expiry->truncate( to => 'day' ), |
| 167 |
'discard_changes should refresh the object' |
174 |
'discard_changes should refresh the object' |
| 168 |
); |
175 |
); |
| 169 |
my $cardnumber = $patron->cardnumber; |
176 |
is( ref($ret), 'Koha::Patron', 'discard_changes should return a Koha::Object object' ); |
| 170 |
my $categorycode = $patron->categorycode; |
177 |
is( refaddr($ret), refaddr($patron), 'Same object referenced' ); |
| 171 |
my $branchcode = $patron->branchcode; |
|
|
| 172 |
$patron->delete; |
| 173 |
|
| 174 |
$patron = |
| 175 |
Koha::Patron->new( { cardnumber => $cardnumber, categorycode => $categorycode, branchcode => $branchcode } ) |
| 176 |
->store->discard_changes; |
| 177 |
|
| 178 |
is( ref($patron), 'Koha::Patron', 'discard_changes should return a Koha::Object object' ); |
| 179 |
isnt( $patron->updated_on, undef, 'discard_changes should have fetched the row from the DB' ); |
| 180 |
|
178 |
|
| 181 |
$schema->storage->txn_rollback; |
179 |
$schema->storage->txn_rollback; |
| 182 |
}; |
180 |
}; |
| 183 |
- |
|
|