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

(-)a/t/db_dependent/Koha/Patrons/Import.t (-5 / +62 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 => 176;
21
use Test::More tests => 177;
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 186-200 is($result_3a->{imported}, 0, 'Got the expected 0 imported result from import_pa Link Here
186
is($result_3a->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons');
186
is($result_3a->{invalid}, 0, 'Got the expected 0 invalid result from import_patrons');
187
is($result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched');
187
is($result_3a->{overwritten}, 1, 'Got the expected 1 overwritten result from import_patrons that matched');
188
188
189
my $patron_3 = Koha::Patrons->find({ cardnumber => '1000' });
190
is( $patron_3->dateexpiry, '2015-07-01', "Expiration date is correct with update_dateexpiry = false" );
191
189
# Given ... valid file handle, good matchpoint that matches should overwrite when set, surname is protected from
192
# Given ... valid file handle, good matchpoint that matches should overwrite when set, surname is protected from
190
# overwrite but firstname is not
193
# overwrite but firstname is not
191
my $filename_3c = make_csv($temp_dir, $csv_headers, $csv_one_line_b);
194
my $filename_3c = make_csv($temp_dir, $csv_headers, $csv_one_line_b);
192
open(my $handle_3c, "<", $filename_3c) or die "cannot open < $filename_3: $!";
195
open(my $handle_3c, "<", $filename_3c) or die "cannot open < $filename_3: $!";
193
my $params_3c = { file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ], update_dateexpiry => 1, update_dateexpiry_from_today => 1 };
196
my $params_3c = { file => $handle_3c, matchpoint => 'cardnumber', overwrite_cardnumber => 1, preserve_fields => [ 'firstname' ], update_dateexpiry => 1, update_dateexpiry_from_today => 1 };
194
197
195
my $patron_3 = Koha::Patrons->find({ cardnumber => '1000' });
196
is( $patron_3->dateexpiry, '2015-07-01', "Expiration date is correct with update_dateexpiry = false" );
197
198
# When ...
198
# When ...
199
my $result_3c;
199
my $result_3c;
200
warning_is { $result_3c = $patrons_import->import_patrons($params_3c) }
200
warning_is { $result_3c = $patrons_import->import_patrons($params_3c) }
Lines 1175-1180 subtest 'welcome_email' => sub { Link Here
1175
    is($notices->count, 1, 'Notice was queued');
1175
    is($notices->count, 1, 'Notice was queued');
1176
};
1176
};
1177
1177
1178
subtest 'test update_dateexpiry when no dateexpiry in file' => sub {
1179
1180
    # Normally, imports on ly update included columns, however, if we are asking Koha
1181
    # to calculate expiration dates
1182
1183
    plan tests => 3;
1184
1185
    my $csv_headers = 'cardnumber,surname,branchcode,categorycode,dateenrolled';
1186
    my $patron      = $builder->build_object( { class => 'Koha::Patrons' } );
1187
    $patron->dateexpiry( dt_from_string() );
1188
    $patron->dateenrolled( dt_from_string->add( months => '-24', end_of_month => 'limit' ) )->store;
1189
    my $csv_values = join(
1190
        ',', $patron->cardnumber, $patron->surname, $patron->branchcode, $patron->categorycode,
1191
        $patron->dateenrolled
1192
    );
1193
    $patron->category->enrolmentperiod(42)->enrolmentperioddate(undef)->store();
1194
1195
    my $filename_1 = make_csv( $temp_dir, $csv_headers, $csv_values );
1196
    open( my $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!";
1197
    my $params = { file => $handle_1, matchpoint => 'cardnumber', overwrite_cardnumber => 1, update_dateexpiry => 1 };
1198
    my $result = $patrons_import->import_patrons( $params, {} );
1199
1200
    $patron->discard_changes();
1201
1202
    is(
1203
        $patron->dateexpiry, dt_from_string->add( months => 18, end_of_month => 'limit' )->ymd,
1204
        "Expiration date is correct with update_dateexpiry = true no dateexpiry in file and update_datexpiryfromtoday false (i.e. use passed dateenrolled) "
1205
    );
1206
1207
    $filename_1 = make_csv( $temp_dir, $csv_headers, $csv_values );
1208
    open( $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!";
1209
    $params = {
1210
        file => $handle_1, matchpoint => 'cardnumber', overwrite_cardnumber => 1, update_dateexpiry => 1,
1211
        update_dateexpiry_from_today => 1
1212
    };
1213
    $result = $patrons_import->import_patrons( $params, {} );
1214
    $patron->discard_changes();
1215
    is(
1216
        $patron->dateexpiry, dt_from_string->add( months => 42, end_of_month => 'limit' )->ymd,
1217
        "Expiration date is correct with update_dateexpiry = true no dateexpiry in file and update_datexpiryfromtoday true "
1218
    );
1219
1220
    $csv_headers = 'cardnumber,surname,branchcode,categorycode';
1221
    $csv_values  = join( ',', $patron->cardnumber, $patron->surname, $patron->branchcode, $patron->categorycode );
1222
    $filename_1  = make_csv( $temp_dir, $csv_headers, $csv_values );
1223
    open( $handle_1, "<", $filename_1 ) or die "cannot open < $filename_1: $!";
1224
    $patron->dateexpiry( dt_from_string() );
1225
    $patron->dateenrolled( dt_from_string->add( months => '-24', end_of_month => 'limit' ) )->store;
1226
    $params = { file => $handle_1, matchpoint => 'cardnumber', overwrite_cardnumber => 1, update_dateexpiry => 1 };
1227
    $result = $patrons_import->import_patrons( $params, {} );
1228
    $patron->discard_changes();
1229
    is(
1230
        $patron->dateexpiry, dt_from_string->add( months => 42, end_of_month => 'limit' )->ymd,
1231
        "Expiration date is correct with update_dateexpiry = true no dateexpiry in file and update_datexpiryfromtoday false but no dateenrolled in file (today is used) "
1232
    );
1233
1234
};
1235
1178
# got is { code => $code, attribute => $attribute }
1236
# got is { code => $code, attribute => $attribute }
1179
# expected is { $code => \@attributes }
1237
# expected is { $code => \@attributes }
1180
sub compare_patron_attributes {
1238
sub compare_patron_attributes {
1181
- 

Return to bug 34617