View | Details | Raw Unified | Return to bug 31503
Collapse All | Expand All

(-)a/Koha/Patron.pm (+23 lines)
Lines 43-48 use Koha::CurbsidePickups; Link Here
43
use Koha::Old::Checkouts;
43
use Koha::Old::Checkouts;
44
use Koha::Patron::Attributes;
44
use Koha::Patron::Attributes;
45
use Koha::Patron::Categories;
45
use Koha::Patron::Categories;
46
use Koha::Patron::Consents;
46
use Koha::Patron::Debarments;
47
use Koha::Patron::Debarments;
47
use Koha::Patron::HouseboundProfile;
48
use Koha::Patron::HouseboundProfile;
48
use Koha::Patron::HouseboundRole;
49
use Koha::Patron::HouseboundRole;
Lines 2196-2201 sub virtualshelves { Link Here
2196
    return Koha::Virtualshelves->_new_from_dbic( scalar $self->_result->virtualshelves );
2197
    return Koha::Virtualshelves->_new_from_dbic( scalar $self->_result->virtualshelves );
2197
}
2198
}
2198
2199
2200
=head3 consent
2201
2202
    my $consent = $patron->consent(TYPE);
2203
2204
    Returns the first consent of type TYPE (there should be only one) or a new instance
2205
    of Koha::Patron::Consent.
2206
2207
=cut
2208
2209
sub consent {
2210
    my ( $self, $type ) = @_;
2211
    Koha::Exceptions::MissingParameter->throw('Missing consent type')
2212
        if !$type;
2213
    my $consents = Koha::Patron::Consents->search({
2214
        borrowernumber => $self->borrowernumber,
2215
        type => $type,
2216
    });
2217
    return $consents && $consents->count
2218
        ? $consents->next
2219
        : Koha::Patron::Consent->new({ borrowernumber => $self->borrowernumber, type => $type });
2220
}
2221
2199
=head2 Internal methods
2222
=head2 Internal methods
2200
2223
2201
=head3 _type
2224
=head3 _type
(-)a/t/db_dependent/Koha/Patron.t (-2 / +20 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 18;
22
use Test::More tests => 19;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::Warn;
24
use Test::Warn;
25
25
Lines 28-33 use Koha::Database; Link Here
28
use Koha::DateUtils qw(dt_from_string);
28
use Koha::DateUtils qw(dt_from_string);
29
use Koha::ArticleRequests;
29
use Koha::ArticleRequests;
30
use Koha::Patrons;
30
use Koha::Patrons;
31
use Koha::Patron::Consents;
31
use Koha::Patron::Relationships;
32
use Koha::Patron::Relationships;
32
33
33
use t::lib::TestBuilder;
34
use t::lib::TestBuilder;
Lines 1292-1294 subtest 'encode_secret and decoded_secret' => sub { Link Here
1292
1293
1293
    $schema->storage->txn_rollback;
1294
    $schema->storage->txn_rollback;
1294
};
1295
};
1295
- 
1296
1297
subtest 'test patron_consent' => sub {
1298
    plan tests => 4;
1299
    $schema->storage->txn_begin;
1300
1301
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
1302
    throws_ok { $patron->consent } 'Koha::Exceptions::MissingParameter', 'missing type';
1303
1304
    my $consent = $patron->consent('GDPR_PROCESSING');
1305
    is( ref $consent, 'Koha::Patron::Consent', 'return type check' );
1306
    $consent->given_on( '2021-02-03' )->store;
1307
    undef $consent;
1308
    is( $patron->consent('GDPR_PROCESSING')->given_on, '2021-02-03 00:00:00', 'check date' );
1309
1310
    is( $patron->consent('NOT_EXIST')->refused_on, undef, 'New empty object for new type' );
1311
1312
    $schema->storage->txn_rollback;
1313
};

Return to bug 31503