|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use Modern::Perl; |
| 4 |
|
| 5 |
use C4::Context; |
| 6 |
use Koha::Database; |
| 7 |
use t::lib::TestBuilder; |
| 8 |
|
| 9 |
use Test::More tests => 6; |
| 10 |
|
| 11 |
my $schema = Koha::Database->new->schema; |
| 12 |
$schema->storage->txn_begin; |
| 13 |
my $dbh = C4::Context->dbh; |
| 14 |
my $builder = t::lib::TestBuilder->new; |
| 15 |
|
| 16 |
use_ok('Koha::RestrictionType'); |
| 17 |
use_ok('Koha::RestrictionTypes'); |
| 18 |
|
| 19 |
$dbh->do(q|DELETE FROM borrower_debarments|); |
| 20 |
Koha::RestrictionTypes->search->delete; |
| 21 |
|
| 22 |
$builder->build({ |
| 23 |
source => 'DebarmentType', |
| 24 |
value => { |
| 25 |
code => 'ONE', |
| 26 |
display_text => 'One', |
| 27 |
ronly => 1, |
| 28 |
dflt => 0 |
| 29 |
} |
| 30 |
}); |
| 31 |
$builder->build({ |
| 32 |
source => 'DebarmentType', |
| 33 |
value => { |
| 34 |
code => 'TWO', |
| 35 |
display_text => 'Two', |
| 36 |
ronly => 1, |
| 37 |
dflt => 1 |
| 38 |
} |
| 39 |
}); |
| 40 |
$builder->build({ |
| 41 |
source => 'DebarmentType', |
| 42 |
value => { |
| 43 |
code => 'THREE', |
| 44 |
display_text => 'Three', |
| 45 |
ronly => 1, |
| 46 |
dflt => 0 |
| 47 |
} |
| 48 |
}); |
| 49 |
$builder->build({ |
| 50 |
source => 'DebarmentType', |
| 51 |
value => { |
| 52 |
code => 'FOUR', |
| 53 |
display_text => 'Four', |
| 54 |
ronly => 0, |
| 55 |
dflt => 0 |
| 56 |
} |
| 57 |
}); |
| 58 |
$builder->build({ |
| 59 |
source => 'DebarmentType', |
| 60 |
value => { |
| 61 |
code => 'FIVE', |
| 62 |
display_text => 'Five', |
| 63 |
ronly => 0, |
| 64 |
dflt => 0 |
| 65 |
} |
| 66 |
}); |
| 67 |
|
| 68 |
# Can we create RestrictionTypes |
| 69 |
my $created = Koha::RestrictionTypes->find({ code => 'ONE' }); |
| 70 |
ok( $created->display_text eq 'One', 'Restrictions created'); |
| 71 |
|
| 72 |
# Can we delete RestrictionTypes, when appropriate |
| 73 |
my $deleted = Koha::RestrictionTypes->find({ code => 'FOUR' })->delete; |
| 74 |
ok( $deleted == 1, 'Restriction deleted'); |
| 75 |
my $not_deleted = Koha::RestrictionTypes->find({ code => 'TWO' })->delete; |
| 76 |
ok( $not_deleted == 0, 'Read only restriction not deleted'); |
| 77 |
|
| 78 |
|
| 79 |
# Add a patron with a debarment |
| 80 |
my $library = $builder->build({ source => 'Branch' }); |
| 81 |
|
| 82 |
my $patron_category = $builder->build({ source => 'Category' }); |
| 83 |
my $borrowernumber = Koha::Patron->new({ |
| 84 |
firstname => 'my firstname', |
| 85 |
surname => 'my surname', |
| 86 |
categorycode => $patron_category->{categorycode}, |
| 87 |
branchcode => $library->{branchcode}, |
| 88 |
})->store->borrowernumber; |
| 89 |
|
| 90 |
Koha::Patron::Debarments::AddDebarment({ |
| 91 |
borrowernumber => $borrowernumber, |
| 92 |
expiration => '9999-06-10', |
| 93 |
type => 'FIVE', |
| 94 |
comment => 'Test 1', |
| 95 |
}); |
| 96 |
|
| 97 |
# Now delete a code and check debarments using that code switch to |
| 98 |
# using the default |
| 99 |
my $to_delete = Koha::RestrictionTypes->find({ code => 'FIVE' })->delete; |
| 100 |
my $debarments = Koha::Patron::Debarments::GetDebarments({ |
| 101 |
borrowernumber => $borrowernumber |
| 102 |
}); |
| 103 |
is( $debarments->[0]->{type}, 'TWO', 'Debarments update with restrictions' ); |
| 104 |
|
| 105 |
$schema->storage->txn_rollback; |