| 
      
            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 => 161;  | 
              21 | 
              use Test::More tests => 173;  | 
            
        
          | 22 | 
          use Test::Warn;  | 
          22 | 
          use Test::Warn;  | 
        
        
          | 23 | 
          use Test::Exception;  | 
          23 | 
          use Test::Exception;  | 
        
        
          | 24 | 
          use Encode qw( encode_utf8 );  | 
          24 | 
          use Encode qw( encode_utf8 );  | 
        
  
    | 
      
            Lines 93-98
          my $csv_headers  = 'cardnumber,surname,firstname,title,othernames,initials,stree
      
      
        Link Here
      
     | 
  
        
          | 93 | 
          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 $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';  | 
        
        
          | 94 | 
          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';  | 
          94 | 
          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';  | 
        
        
          | 95 | 
          my $csv_one_line_a = '1001,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';  | 
          95 | 
          my $csv_one_line_a = '1001,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';  | 
        
            
               | 
               | 
              96 | 
              my $csv_one_line_b = '1000,Nancy2,Jenkins2,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';  | 
            
        
          | 96 | 
           | 
          97 | 
           | 
        
        
          | 97 | 
          my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_one_line);  | 
          98 | 
          my $filename_1 = make_csv($temp_dir, $csv_headers, $csv_one_line);  | 
        
        
          | 98 | 
          open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!";  | 
          99 | 
          open(my $handle_1, "<", $filename_1) or die "cannot open < $filename_1: $!";  | 
        
  
    | 
      
            Lines 184-189
          is($result_3a->{imported}, 0, 'Got the expected 0 imported result from import_pa
      
      
        Link Here
      
     | 
  
        
          | 184 | 
          is($result_3a->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons'); | 
          185 | 
          is($result_3a->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons'); | 
        
        
          | 185 | 
          is($result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched'); | 
          186 | 
          is($result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched'); | 
        
        
          | 186 | 
           | 
          187 | 
           | 
        
            
               | 
               | 
              188 | 
              # Given ... valid file handle, good matchpoint that matches should overwrite when set, surname is protected from  | 
            
            
              | 189 | 
              # overwrite but firstname is not  | 
            
            
              | 190 | 
              my $filename_3c = make_csv($temp_dir, $csv_headers, $csv_one_line_b);  | 
            
            
              | 191 | 
              open(my $handle_3c, "<", $filename_3c) or die "cannot open < $filename_3: $!";  | 
            
            
              | 192 | 
              my $params_3c = { file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ] }; | 
            
            
              | 193 | 
               | 
            
            
              | 194 | 
              # When ...  | 
            
            
              | 195 | 
              my $result_3c;  | 
            
            
              | 196 | 
              warning_is { $result_3c = $patrons_import->import_patrons($params_3c) } | 
            
            
              | 197 | 
                  undef,  | 
            
            
              | 198 | 
                  "No warning raised by import_patrons";  | 
            
            
              | 199 | 
               | 
            
            
              | 200 | 
              # Then ...  | 
            
            
              | 201 | 
              is($result_3c->{already_in_db}, 0, 'Got the expected 0 already_in_db from import_patrons when matched and overwrite set'); | 
            
            
              | 202 | 
              is($result_3c->{errors}->[0]->{duplicate_userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)'); | 
            
            
              | 203 | 
              is($result_3c->{errors}->[0]->{userid}, undef, 'No duplicate userid error from import patrons with duplicate userid (it is our own)'); | 
            
            
              | 204 | 
               | 
            
            
              | 205 | 
              is($result_3c->{feedback}->[0]->{feedback}, 1, 'Got 1 expected feedback from import_patrons that matched and overwritten'); | 
            
            
              | 206 | 
              is($result_3c->{feedback}->[0]->{name}, 'headerrow', 'Got the expected header row name from import_patrons with duplicate userid'); | 
            
            
              | 207 | 
              is($result_3c->{feedback}->[0]->{value}, $res_header, 'Got the expected header row value from import_patrons with duplicate userid'); | 
            
            
              | 208 | 
               | 
            
            
              | 209 | 
              is($result_3c->{imported}, 0, 'Got the expected 0 imported result from import_patrons'); | 
            
            
              | 210 | 
              is($result_3c->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons'); | 
            
            
              | 211 | 
              is($result_3c->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched'); | 
            
            
              | 212 | 
               | 
            
            
              | 213 | 
              my $patron_3c = Koha::Patrons->find({ cardnumber => '1000' }); | 
            
            
              | 214 | 
              is( $patron_3c->surname, "Nancy2", "Surname field is preserved from original" );  | 
            
            
              | 215 | 
              is( $patron_3c->firstname, "Jenkins", "Firstname field is overwritten" );  | 
            
            
              | 216 | 
               | 
            
        
          | 187 | 
          # Given ... valid file handle, good matchpoint that does not match and conflicting userid.  | 
          217 | 
          # Given ... valid file handle, good matchpoint that does not match and conflicting userid.  | 
        
        
          | 188 | 
          my $filename_3b = make_csv($temp_dir, $csv_headers, $csv_one_line_a);  | 
          218 | 
          my $filename_3b = make_csv($temp_dir, $csv_headers, $csv_one_line_a);  | 
        
        
          | 189 | 
          open(my $handle_3b, "<", $filename_3b) or die "cannot open < $filename_3: $!";  | 
          219 | 
          open(my $handle_3b, "<", $filename_3b) or die "cannot open < $filename_3: $!";  |