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

(-)a/t/db_dependent/Koha/Patrons.t (-6 / +54 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 46;
23
use Test::More tests => 47;
24
use Test::Warn;
24
use Test::Warn;
25
use Test::Exception;
25
use Test::Exception;
26
use Test::MockModule;
26
use Test::MockModule;
Lines 500-506 subtest 'renew_account' => sub { Link Here
500
            dt_from_string($retrieved_expiry_date), $a_year_later_minus_a_month,
500
            dt_from_string($retrieved_expiry_date), $a_year_later_minus_a_month,
501
            "$a_month_ago + 12 months must be $a_year_later_minus_a_month"
501
            "$a_month_ago + 12 months must be $a_year_later_minus_a_month"
502
        );
502
        );
503
        my $number_of_logs = $schema->resultset('ActionLog')
503
        my $number_of_logs =
504
            $schema->resultset('ActionLog')
504
            ->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count;
505
            ->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count;
505
        is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->renew_account should have logged' );
506
        is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->renew_account should have logged' );
506
507
Lines 515-521 subtest 'renew_account' => sub { Link Here
515
        );
516
        );
516
        $retrieved_expiry_date = $retrieved_patron->dateexpiry;
517
        $retrieved_expiry_date = $retrieved_patron->dateexpiry;
517
        is( dt_from_string($retrieved_expiry_date), $a_year_later, "today + 12 months must be $a_year_later" );
518
        is( dt_from_string($retrieved_expiry_date), $a_year_later, "today + 12 months must be $a_year_later" );
518
        $number_of_logs = $schema->resultset('ActionLog')
519
        $number_of_logs =
520
            $schema->resultset('ActionLog')
519
            ->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count;
521
            ->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count;
520
        is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->renew_account should not have logged' );
522
        is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->renew_account should not have logged' );
521
523
Lines 650-656 subtest "delete" => sub { Link Here
650
        q|Koha::Patron->delete should have deleted patron's modifications|
652
        q|Koha::Patron->delete should have deleted patron's modifications|
651
    );
653
    );
652
654
653
    my $number_of_logs = $schema->resultset('ActionLog')
655
    my $number_of_logs =
656
        $schema->resultset('ActionLog')
654
        ->search( { module => 'MEMBERS', action => 'DELETE', object => $patron->borrowernumber } )->count;
657
        ->search( { module => 'MEMBERS', action => 'DELETE', object => $patron->borrowernumber } )->count;
655
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' );
658
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->delete should have logged' );
656
659
Lines 2468-2474 subtest '->set_password' => sub { Link Here
2468
    ok( checkpw_hash( 'abcd   a', $patron->password ), 'Password hash is correct' );
2471
    ok( checkpw_hash( 'abcd   a', $patron->password ), 'Password hash is correct' );
2469
    is( $patron->login_attempts, 0, 'Login attempts have been reset' );
2472
    is( $patron->login_attempts, 0, 'Login attempts have been reset' );
2470
2473
2471
    my $number_of_logs = $schema->resultset('ActionLog')
2474
    my $number_of_logs =
2475
        $schema->resultset('ActionLog')
2472
        ->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count;
2476
        ->search( { module => 'MEMBERS', action => 'CHANGE PASS', object => $patron->borrowernumber } )->count;
2473
    is( $number_of_logs, 0, 'Without BorrowerLogs, Koha::Patron->set_password doesn\'t log password changes' );
2477
    is( $number_of_logs, 0, 'Without BorrowerLogs, Koha::Patron->set_password doesn\'t log password changes' );
2474
2478
Lines 3573-3576 subtest 'filter_by_expired_opac_registrations' => sub { Link Here
3573
    $schema->storage->txn_rollback;
3577
    $schema->storage->txn_rollback;
3574
};
3578
};
3575
3579
3580
subtest 'find_by_identifier() tests' => sub {
3581
3582
    plan tests => 7;
3583
3584
    $schema->storage->txn_begin;
3585
3586
    # Create test patrons with specific userid and cardnumber
3587
    my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } );
3588
    my $patron_2 = $builder->build_object( { class => 'Koha::Patrons' } );
3589
3590
    # Create a patron to delete to
3591
    my $to_delete     = $builder->build_object( { class => 'Koha::Patrons' } );
3592
    my $ne_userid     = $to_delete->userid;
3593
    my $ne_cardnumber = $to_delete->cardnumber;
3594
    $to_delete->delete();
3595
3596
    # Test finding by userid
3597
    my $found_patron = Koha::Patrons->find_by_identifier( $patron_1->userid );
3598
    is( $found_patron->id, $patron_1->id, 'Found patron by userid' );
3599
3600
    # Test finding by cardnumber
3601
    $found_patron = Koha::Patrons->find_by_identifier( $patron_1->cardnumber );
3602
    is( $found_patron->id, $patron_1->id, 'Found patron by cardnumber' );
3603
3604
    # Test finding by cardnumber when userid doesn't match
3605
    $found_patron = Koha::Patrons->find_by_identifier( $patron_2->cardnumber );
3606
    is( $found_patron->id, $patron_2->id, 'Found patron by cardnumber when userid differs' );
3607
3608
    # Test with non-existent identifiers
3609
    $found_patron = Koha::Patrons->find_by_identifier($ne_cardnumber);
3610
    is( $found_patron, undef, 'Returns undef for non-existent identifier' );
3611
    $found_patron = Koha::Patrons->find_by_identifier($ne_userid);
3612
    is( $found_patron, undef, 'Returns undef for non-existent identifier' );
3613
3614
    # Test with empty identifier
3615
    $found_patron = Koha::Patrons->find_by_identifier('');
3616
    is( $found_patron, undef, 'Returns undef for empty identifier' );
3617
3618
    # Test with undef identifier
3619
    $found_patron = Koha::Patrons->find_by_identifier(undef);
3620
    is( $found_patron, undef, 'Returns undef for undef identifier' );
3621
3622
    $schema->storage->txn_rollback;
3623
};
3624
3576
$schema->storage->txn_rollback;
3625
$schema->storage->txn_rollback;
3577
- 

Return to bug 40275