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

(-)a/t/db_dependent/Koha/Patrons.t (-1 / +60 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 23;
22
use Test::More tests => 24;
23
use Test::Warn;
23
use Test::Warn;
24
use Time::Fake;
24
use Time::Fake;
25
use DateTime;
25
use DateTime;
Lines 955-960 subtest 'account_locked' => sub { Link Here
955
    $patron->delete;
955
    $patron->delete;
956
};
956
};
957
957
958
subtest 'userid_is_valid' => sub {
959
    plan tests => 9;
960
961
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
962
    my $patron_category = $builder->build_object(
963
        {
964
            class => 'Koha::Patron::Categories',
965
            value => { category_type => 'P', enrolmentfee => 0 }
966
        }
967
    );
968
    my %data = (
969
        cardnumber   => "123456789",
970
        firstname    => "Tomasito",
971
        surname      => "None",
972
        categorycode => $patron_category->categorycode,
973
        branchcode   => $library->branchcode,
974
    );
975
976
    my $borrowernumber = AddMember(%data);
977
    my $patron_1       = Koha::Patrons->find($borrowernumber);
978
979
    is( Check_Userid( 'tomasito.non', $patron_1->borrowernumber ),
980
        1, 'recently created userid -> unique (borrowernumber passed)' );
981
    is( Check_Userid( 'tomasitoxxx', $patron_1->borrowernumber ),
982
        1, 'non-existent userid -> unique (borrowernumber passed)' );
983
    is( Check_Userid( 'tomasito.none', '' ),
984
        0, 'userid exists (blank borrowernumber)' );
985
    is( Check_Userid( 'tomasitoxxx', '' ),
986
        1, 'non-existent userid -> unique (blank borrowernumber)' );
987
988
    # Regression tests for BZ12226
989
    is( Check_Userid( C4::Context->config('user'), '' ),
990
        0, 'Check_Userid should return 0 for the DB user (Bug 12226)' );
991
992
    # Add a new borrower with the same userid but different cardnumber
993
    $data{cardnumber} = "987654321";
994
    my $new_borrowernumber = AddMember(%data);
995
    is( Check_Userid( 'tomasito.none', '' ),
996
        0, 'userid not unique (blank borrowernumber)' );
997
    is( Check_Userid( 'tomasito.none', $new_borrowernumber ),
998
        0, 'userid not unique (second borrowernumber passed)' );
999
    my $patron_2 = Koha::Patrons->find($new_borrowernumber);
1000
    ok( $patron_2->userid ne 'tomasito',
1001
        "Borrower with duplicate userid has new userid generated" );
1002
1003
    my $new_userid = 'a_user_id';
1004
    $data{cardnumber} = "234567890";
1005
    $data{userid}     = 'a_user_id';
1006
    $borrowernumber   = AddMember(%data);
1007
    my $patron_3 = Koha::Patrons->find($borrowernumber);
1008
    is( $patron_3->userid, $new_userid,
1009
        'AddMember should insert the given userid' );
1010
1011
    # Cleanup
1012
    $patron_1->delete;
1013
    $patron_2->delete;
1014
    $patron_3->delete;
1015
};
1016
958
$retrieved_patron_1->delete;
1017
$retrieved_patron_1->delete;
959
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
1018
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
960
1019
(-)a/t/db_dependent/Members.t (-33 / +8 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 62;
20
use Test::More tests => 53;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Exception;
22
use Test::Exception;
23
23
Lines 139-145 $checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); Link Here
139
is ($checkcardnum, "2", "Card number is too long");
139
is ($checkcardnum, "2", "Card number is too long");
140
140
141
141
142
# Check_Userid tests
142
# Add a new borrower
143
%data = (
143
%data = (
144
    cardnumber   => "123456789",
144
    cardnumber   => "123456789",
145
    firstname    => "Tomasito",
145
    firstname    => "Tomasito",
Lines 151-167 is ($checkcardnum, "2", "Card number is too long"); Link Here
151
    dateexpiry   => '',
151
    dateexpiry   => '',
152
    dateenrolled => '',
152
    dateenrolled => '',
153
);
153
);
154
# Add a new borrower
155
my $borrowernumber = AddMember( %data );
154
my $borrowernumber = AddMember( %data );
156
is( Check_Userid( 'tomasito.non', $borrowernumber ), 1,
157
    'recently created userid -> unique (borrowernumber passed)' );
158
is( Check_Userid( 'tomasitoxxx', $borrowernumber ), 1,
159
    'non-existent userid -> unique (borrowernumber passed)' );
160
is( Check_Userid( 'tomasito.none', '' ), 0,
161
    'userid exists (blank borrowernumber)' );
162
is( Check_Userid( 'tomasitoxxx', '' ), 1,
163
    'non-existent userid -> unique (blank borrowernumber)' );
164
165
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
155
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
166
is( $borrower->{dateofbirth}, undef, 'AddMember should undef dateofbirth if empty string is given');
156
is( $borrower->{dateofbirth}, undef, 'AddMember should undef dateofbirth if empty string is given');
167
is( $borrower->{debarred}, undef, 'AddMember should undef debarred if empty string is given');
157
is( $borrower->{debarred}, undef, 'AddMember should undef debarred if empty string is given');
Lines 182-205 is( $borrower->{debarred}, '2042-01-01', 'ModMember should correctly set debarre Link Here
182
is( $borrower->{dateexpiry}, '9999-12-31', 'ModMember should correctly set dateexpiry if a valid date is given');
172
is( $borrower->{dateexpiry}, '9999-12-31', 'ModMember should correctly set dateexpiry if a valid date is given');
183
is( $borrower->{dateenrolled}, '2015-09-06', 'ModMember should correctly set dateenrolled if a valid date is given');
173
is( $borrower->{dateenrolled}, '2015-09-06', 'ModMember should correctly set dateenrolled if a valid date is given');
184
174
185
# Add a new borrower with the same userid but different cardnumber
186
$data{ cardnumber } = "987654321";
187
my $new_borrowernumber = AddMember( %data );
188
is( Check_Userid( 'tomasito.none', '' ), 0,
189
    'userid not unique (blank borrowernumber)' );
190
is( Check_Userid( 'tomasito.none', $new_borrowernumber ), 0,
191
    'userid not unique (second borrowernumber passed)' );
192
$borrower = Koha::Patrons->find( $new_borrowernumber )->unblessed;
193
ok( $borrower->{userid} ne 'tomasito', "Borrower with duplicate userid has new userid generated" );
194
195
$data{ cardnumber } = "234567890";
196
$data{userid} = 'a_user_id';
197
$borrowernumber = AddMember( %data );
198
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
199
is( $borrower->{userid}, $data{userid}, 'AddMember should insert the given userid' );
200
201
subtest 'ModMember should not update userid if not true' => sub {
175
subtest 'ModMember should not update userid if not true' => sub {
202
    plan tests => 3;
176
    plan tests => 3;
177
178
    $data{ cardnumber } = "234567890";
179
    $data{userid} = 'a_user_id';
180
    $borrowernumber = AddMember( %data );
181
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
182
203
    ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => '' );
183
    ModMember( borrowernumber => $borrowernumber, firstname => 'Tomas', userid => '' );
204
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
184
    $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
205
    is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an empty string' );
185
    is ( $borrower->{userid}, $data{userid}, 'ModMember should not update the userid with an empty string' );
Lines 369-378 ok( $borrowernumber > 0, 'AddMember should have inserted the patron even if no u Link Here
369
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
349
$borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
370
ok( $borrower->{userid},  'A userid should have been generated correctly' );
350
ok( $borrower->{userid},  'A userid should have been generated correctly' );
371
351
372
# Regression tests for BZ12226
373
is( Check_Userid( C4::Context->config('user'), '' ), 0,
374
    'Check_Userid should return 0 for the DB user (Bug 12226)');
375
376
subtest 'GetMemberAccountRecords' => sub {
352
subtest 'GetMemberAccountRecords' => sub {
377
353
378
    plan tests => 2;
354
    plan tests => 2;
379
- 

Return to bug 19936