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

(-)a/Koha/Patron.pm (-5 / +1 lines)
Lines 584-590 sub housebound_role { Link Here
584
584
585
=head3 siblings
585
=head3 siblings
586
586
587
Returns the siblings of this patron.
587
Returns the siblings of this patron as a C<Koha::Patrons> object
588
588
589
=cut
589
=cut
590
590
Lines 593-605 sub siblings { Link Here
593
593
594
    my @guarantors = $self->guarantor_relationships()->guarantors()->as_list;
594
    my @guarantors = $self->guarantor_relationships()->guarantors()->as_list;
595
595
596
    return unless @guarantors;
597
598
    my @siblings =
596
    my @siblings =
599
      map { $_->guarantee_relationships()->guarantees()->as_list } @guarantors;
597
      map { $_->guarantee_relationships()->guarantees()->as_list } @guarantors;
600
598
601
    return unless @siblings;
602
603
    my %seen;
599
    my %seen;
604
    @siblings =
600
    @siblings =
605
      grep { !$seen{ $_->id }++ && ( $_->id != $self->id ) } @siblings;
601
      grep { !$seen{ $_->id }++ && ( $_->id != $self->id ) } @siblings;
(-)a/t/db_dependent/Koha/Patron/siblings.t (-1 / +42 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use String::Random;
6
use Test::More tests => 1;
7
8
use Koha::Database;
9
use Koha::Patrons;
10
11
my $schema = Koha::Database->schema;
12
13
subtest 'Koha::Patrons::siblings should return a Koha::Patrons object even if patron has no guarantor' => sub {
14
    plan tests => 2;
15
    $schema->txn_begin;
16
17
    my $random = String::Random->new;
18
19
    my $categorycode = $random->randpattern('CCCCCCCCCC');
20
    my $branchcode   = $random->randpattern('CCCCCCCCCC');
21
22
    my $category = $schema->resultset('Category')->create( { categorycode => $categorycode } );
23
    my $branch   = $schema->resultset('Branch')->create(
24
        {
25
            branchcode => $branchcode,
26
            branchname => 'Test branch for Koha::Patron::siblings tests',
27
        }
28
    );
29
    my $borrower = $schema->resultset('Borrower')->create(
30
        {
31
            categorycode => $categorycode,
32
            branchcode   => $branchcode,
33
        }
34
    );
35
    my $patron = Koha::Patrons->find( $borrower->borrowernumber );
36
37
    my $siblings = $patron->siblings;
38
    isa_ok( $siblings, 'Koha::Patrons' );
39
    is( $siblings->count, 0 );
40
41
    $schema->txn_rollback;
42
};

Return to bug 32980