|
Lines 1-11
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
|
|
3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 3 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 4 |
use Test::More tests => 10; |
19 |
|
| 5 |
use Try::Tiny; |
20 |
use Test::More tests => 11; |
|
|
21 |
use Test::Exception; |
| 6 |
|
22 |
|
| 7 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
| 8 |
|
24 |
|
|
|
25 |
use String::Random qw( random_string ); |
| 26 |
use Try::Tiny; |
| 27 |
|
| 9 |
use C4::Context; |
28 |
use C4::Context; |
| 10 |
use C4::Members; |
29 |
use C4::Members; |
| 11 |
|
30 |
|
|
Lines 14-20
BEGIN {
Link Here
|
| 14 |
use_ok('Koha::Patron::Modifications'); |
33 |
use_ok('Koha::Patron::Modifications'); |
| 15 |
} |
34 |
} |
| 16 |
|
35 |
|
| 17 |
my $schema = Koha::Database->new->schema; |
36 |
my $schema = Koha::Database->new->schema; |
|
|
37 |
my $builder = t::lib::TestBuilder->new; |
| 38 |
|
| 39 |
|
| 40 |
subtest 'store( extended_attributes ) tests' => sub { |
| 41 |
|
| 42 |
plan tests => 4; |
| 43 |
|
| 44 |
$schema->storage->txn_begin; |
| 45 |
|
| 46 |
Koha::Patron::Modifications->search->delete; |
| 47 |
|
| 48 |
my $patron |
| 49 |
= $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
| 50 |
my $verification_token = random_string(".........."); |
| 51 |
my $valid_json_text = '[{"code":"CODE","value":"VALUE"}]'; |
| 52 |
my $invalid_json_text = '[{'; |
| 53 |
|
| 54 |
Koha::Patron::Modification->new( |
| 55 |
{ verification_token => $verification_token, |
| 56 |
borrowernumber => $patron, |
| 57 |
surname => 'Hall', |
| 58 |
extended_attributes => $valid_json_text |
| 59 |
} |
| 60 |
)->store(); |
| 61 |
|
| 62 |
my $patron_modification |
| 63 |
= Koha::Patron::Modifications->search( { borrowernumber => $patron } ) |
| 64 |
->next; |
| 65 |
|
| 66 |
is( $patron_modification->surname, |
| 67 |
'Hall', 'Patron modification correctly stored with valid JSON data' ); |
| 68 |
is( $patron_modification->extended_attributes, |
| 69 |
$valid_json_text, |
| 70 |
'Patron modification correctly stored with valid JSON data' ); |
| 71 |
|
| 72 |
$verification_token = random_string(".........."); |
| 73 |
throws_ok { |
| 74 |
Koha::Patron::Modification->new( |
| 75 |
{ verification_token => $verification_token, |
| 76 |
borrowernumber => $patron, |
| 77 |
surname => 'Hall', |
| 78 |
extended_attributes => $invalid_json_text |
| 79 |
} |
| 80 |
)->store(); |
| 81 |
} |
| 82 |
'Koha::Exceptions::Patron::Modification::InvalidData', |
| 83 |
'Trying to store invalid JSON in extended_attributes field raises exception'; |
| 84 |
|
| 85 |
is( $@, 'The passed extended_attributes is not valid JSON' ); |
| 86 |
|
| 87 |
$schema->storage->txn_rollback; |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 18 |
$schema->storage->txn_begin; |
91 |
$schema->storage->txn_begin; |
| 19 |
|
92 |
|
| 20 |
my $dbh = C4::Context->dbh; |
93 |
my $dbh = C4::Context->dbh; |
|
Lines 52-58
my $borrower =
Link Here
|
| 52 |
is( $borrower->surname, 'Hall', 'Found modification has matching surname' ); |
125 |
is( $borrower->surname, 'Hall', 'Found modification has matching surname' ); |
| 53 |
|
126 |
|
| 54 |
## Create new pending modification for a patron |
127 |
## Create new pending modification for a patron |
| 55 |
my $builder = t::lib::TestBuilder->new; |
|
|
| 56 |
my $borr1 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
128 |
my $borr1 = $builder->build( { source => 'Borrower' } )->{borrowernumber}; |
| 57 |
|
129 |
|
| 58 |
my $m1 = Koha::Patron::Modification->new( |
130 |
my $m1 = Koha::Patron::Modification->new( |
|
Lines 106-109
my $new_borrower = GetMember( borrowernumber => $borr1 );
Link Here
|
| 106 |
ok( $new_borrower->{'surname'} eq 'Hall', |
178 |
ok( $new_borrower->{'surname'} eq 'Hall', |
| 107 |
'Test approve() applies modification to borrower' ); |
179 |
'Test approve() applies modification to borrower' ); |
| 108 |
|
180 |
|
| 109 |
$dbh->rollback(); |
181 |
$schema->storage->txn_rollback; |
|
|
182 |
|
| 183 |
1; |
| 110 |
- |
|
|