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

(-)a/Koha/Patron.pm (+2 lines)
Lines 2677-2682 sub _anonymize_column { Link Here
2677
        $val = $nullable ? undef : 0;
2677
        $val = $nullable ? undef : 0;
2678
    } elsif ( $type =~ /date|time/ ) {
2678
    } elsif ( $type =~ /date|time/ ) {
2679
        $val = $nullable ? undef : dt_from_string;
2679
        $val = $nullable ? undef : dt_from_string;
2680
    } elsif ( $type eq 'enum' ) {
2681
        $val = $nullable ? undef : $col_info->{default_value};
2680
    }
2682
    }
2681
    $self->$col($val);
2683
    $self->$col($val);
2682
}
2684
}
(-)a/t/db_dependent/Koha/Patrons.t (-9 / +9 lines)
Lines 2675-2684 subtest 'lock' => sub { Link Here
2675
};
2675
};
2676
2676
2677
subtest 'anonymize' => sub {
2677
subtest 'anonymize' => sub {
2678
    plan tests => 10;
2678
    plan tests => 11;
2679
2679
2680
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons' } );
2680
    my $patron1 = $builder->build_object( { class => 'Koha::Patrons' } )->store;
2681
    my $patron2 = $builder->build_object( { class => 'Koha::Patrons' } );
2681
    my $patron2 = $builder->build_object( { class => 'Koha::Patrons' } )->store;
2682
2682
2683
    # First try patron with issues
2683
    # First try patron with issues
2684
    my $issue = $builder->build_object(
2684
    my $issue = $builder->build_object(
Lines 2696-2711 subtest 'anonymize' => sub { Link Here
2696
    is( $patron1->firstname,   undef, 'First name cleared' );
2696
    is( $patron1->firstname,   undef, 'First name cleared' );
2697
    isnt( $patron1->surname, $surname, 'Surname changed' );
2697
    isnt( $patron1->surname, $surname, 'Surname changed' );
2698
    ok( $patron1->surname =~ /^\w{10}$/, 'Mandatory surname randomized' );
2698
    ok( $patron1->surname =~ /^\w{10}$/, 'Mandatory surname randomized' );
2699
    is( $patron1->branchcode, $branchcode, 'Branch code skipped' );
2699
    is( $patron1->branchcode,        $branchcode, 'Branch code skipped' );
2700
    is( $patron1->email,      undef,       'Email was mandatory, must be cleared' );
2700
    is( $patron1->email,             undef,       'Email was mandatory, must be cleared' );
2701
    is( $patron1->checkprevcheckout, 'inherit',   'Enum checkprevcheckout is reset to the default value' );
2701
2702
2702
    # Test wrapper in Koha::Patrons
2703
    # Test wrapper in Koha::Patrons
2703
    $patron1->surname($surname)->store;       # restore
2704
    $patron1->surname($surname)->store;    # restore
2704
    my $rs = Koha::Patrons->search( { borrowernumber => [ $patron1->borrowernumber, $patron2->borrowernumber ] } )
2705
    my $rs = Koha::Patrons->search( { borrowernumber => [ $patron1->borrowernumber, $patron2->borrowernumber ] } )
2705
        ->anonymize;
2706
        ->anonymize;
2706
    $patron1->discard_changes;                # refresh
2707
    $patron1->discard_changes;             # refresh
2707
    isnt( $patron1->surname, $surname, 'Surname patron1 changed again' );
2708
    isnt( $patron1->surname, $surname, 'Surname patron1 changed again' );
2708
    $patron2->discard_changes;                # refresh
2709
    $patron2->discard_changes;             # refresh
2709
    is( $patron2->firstname, undef, 'First name patron2 cleared' );
2710
    is( $patron2->firstname, undef, 'First name patron2 cleared' );
2710
};
2711
};
2711
2712
2712
- 

Return to bug 40337