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

(-)a/t/db_dependent/Koha/Patrons/Import.t (-5 / +39 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 159;
21
use Test::More tests => 160;
22
use Test::Warn;
22
use Test::Warn;
23
use Encode qw( encode_utf8 );
23
use Encode qw( encode_utf8 );
24
use utf8;
24
use utf8;
Lines 26-31 use utf8; Link Here
26
# To be replaced by t::lib::Mock
26
# To be replaced by t::lib::Mock
27
use Test::MockModule;
27
use Test::MockModule;
28
use Koha::Database;
28
use Koha::Database;
29
use Koha::Patron::Relationships;
29
30
30
use File::Temp qw(tempfile tempdir);
31
use File::Temp qw(tempfile tempdir);
31
my $temp_dir = tempdir('Koha_patrons_import_test_XXXX', CLEANUP => 1, TMPDIR => 1);
32
my $temp_dir = tempdir('Koha_patrons_import_test_XXXX', CLEANUP => 1, TMPDIR => 1);
Lines 87-93 is($result_0, undef, 'Got the expected undef from import_patrons with no file ha Link Here
87
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 0);
88
t::lib::Mocks::mock_preference('ExtendedPatronAttributes', 0);
88
t::lib::Mocks::mock_preference('dateformat', 'us');
89
t::lib::Mocks::mock_preference('dateformat', 'us');
89
90
90
91
my $csv_headers  = 'cardnumber,surname,firstname,title,othernames,initials,streetnumber,streettype,address,address2,city,state,zipcode,country,email,phone,mobile,fax,dateofbirth,branchcode,categorycode,dateenrolled,dateexpiry,userid,password';
91
my $csv_headers  = 'cardnumber,surname,firstname,title,othernames,initials,streetnumber,streettype,address,address2,city,state,zipcode,country,email,phone,mobile,fax,dateofbirth,branchcode,categorycode,dateenrolled,dateexpiry,userid,password';
92
my $res_header   = 'cardnumber, surname, firstname, title, othernames, initials, streetnumber, streettype, address, address2, city, state, zipcode, country, email, phone, mobile, fax, dateofbirth, branchcode, categorycode, dateenrolled, dateexpiry, userid, password';
92
my $res_header   = 'cardnumber, surname, firstname, title, othernames, initials, streetnumber, streettype, address, address2, city, state, zipcode, country, email, phone, mobile, fax, dateofbirth, branchcode, categorycode, dateenrolled, dateexpiry, userid, password';
93
my $csv_one_line = '1000,Nancy,Jenkins,Dr,,NJ,78,Circle,Bunting,El Paso,Henderson,Texas,79984,United States,ajenkins0@sourceforge.net,7-(388)559-6763,3-(373)151-4471,8-(509)286-4001,10/16/1965,CPL,PT,12/28/2014,07/01/2015,jjenkins0,DPQILy';
93
my $csv_one_line = '1000,Nancy,Jenkins,Dr,,NJ,78,Circle,Bunting,El Paso,Henderson,Texas,79984,United States,ajenkins0@sourceforge.net,7-(388)559-6763,3-(373)151-4471,8-(509)286-4001,10/16/1965,CPL,PT,12/28/2014,07/01/2015,jjenkins0,DPQILy';
Lines 434-439 subtest 'test_import_with_cardnumber_0' => sub { Link Here
434
434
435
};
435
};
436
436
437
subtest 'Import patron with guarantor' => sub {
438
    plan tests => 4;
439
    t::lib::Mocks::mock_preference( 'borrowerRelationship', 'guarantor' );
440
441
    my $category = $builder->build( { source => 'Category' } )->{categorycode};
442
    my $branch = $builder->build( { source => 'Branch' } )->{branchcode};
443
    my $guarantor = Koha::Patron->new(
444
        {
445
            surname      => 'Guarantor',
446
            branchcode   => $branch,
447
            categorycode => $category,
448
        }
449
    )->store();
450
    my $guarantor_id = $guarantor->id;
451
452
    my $branchcode = $builder->build( { source => "Branch" } )->{branchcode};
453
    my $categorycode = $builder->build( { source => "Category" } )->{categorycode};
454
    my $csv_headers = 'cardnumber,surname, branchcode, categorycode, guarantor_id, guarantor_relationship';
455
    my $csv_nocard_1 = "kylemhall,Hall,$branchcode,$categorycode,$guarantor_id,guarantor";
456
457
    my $filename_1 = make_csv( $temp_dir, $csv_headers, $csv_nocard_1 );
458
    open( my $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!";
459
    my $params_1 = { file => $handle_1, };
460
461
    my $result = $patrons_import->import_patrons( $params_1 );
462
    like( $result->{feedback}->[1]->{value}, qr/^Hall \/ \d+/, 'First borrower imported as expected' );
463
    my $patron = Koha::Patrons->find( { cardnumber => 'kylemhall' } );
464
    is( $patron->surname, "Hall", "Patron was created" );
465
466
    my $r = Koha::Patron::Relationships->find( { guarantor_id => $guarantor_id } );
467
    ok( $r, 'Found relationship' );
468
    is( $r->guarantee->cardnumber, 'kylemhall', 'Found the correct guarantee' );
469
};
470
437
subtest 'test_import_with_password_overwrite' => sub {
471
subtest 'test_import_with_password_overwrite' => sub {
438
    plan tests => 8;
472
    plan tests => 8;
439
473
Lines 584-597 subtest 'test_set_column_keys' => sub { Link Here
584
    # When ... Then ...
618
    # When ... Then ...
585
    my @columnkeys_0 = $patrons_import->set_column_keys(undef);
619
    my @columnkeys_0 = $patrons_import->set_column_keys(undef);
586
    # -1 because we do not want the borrowernumber column
620
    # -1 because we do not want the borrowernumber column
587
    is(scalar @columnkeys_0, @columns - 1, 'Got the expected array size from set column keys with undef extended');
621
    # +2 for guarantor id and guarantor relationship
622
    is(scalar @columnkeys_0, @columns - 1 + 2, 'Got the expected array size from set column keys with undef extended');
588
623
589
    # Given ... extended.
624
    # Given ... extended.
590
    my $extended = 1;
625
    my $extended = 1;
591
626
592
    # When ... Then ...
627
    # When ... Then ...
593
    my @columnkeys_1 = $patrons_import->set_column_keys($extended);
628
    my @columnkeys_1 = $patrons_import->set_column_keys($extended);
594
    is(scalar @columnkeys_1, @columns - 1 + $extended, 'Got the expected array size from set column keys with extended');
629
    is(scalar @columnkeys_1, @columns - 1 + 2 + $extended, 'Got the expected array size from set column keys with extended');
595
};
630
};
596
631
597
subtest 'test_generate_patron_attributes' => sub {
632
subtest 'test_generate_patron_attributes' => sub {
598
- 

Return to bug 26059