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

(-)a/t/db_dependent/Koha/Patron/Modifications.t (-27 / +51 lines)
Lines 53-58 subtest 'new() tests' => sub { Link Here
53
    # Create new pending modification
53
    # Create new pending modification
54
    Koha::Patron::Modification->new(
54
    Koha::Patron::Modification->new(
55
        {   verification_token => '1234567890',
55
        {   verification_token => '1234567890',
56
            changed_fields     => 'surname,firstname',
56
            surname            => 'Hall',
57
            surname            => 'Hall',
57
            firstname          => 'Kyle'
58
            firstname          => 'Kyle'
58
        }
59
        }
Lines 69-74 subtest 'new() tests' => sub { Link Here
69
    throws_ok {
70
    throws_ok {
70
        Koha::Patron::Modification->new(
71
        Koha::Patron::Modification->new(
71
            {   verification_token => '1234567890',
72
            {   verification_token => '1234567890',
73
                changed_fields     => 'surname,firstname',
72
                surname            => 'Hall',
74
                surname            => 'Hall',
73
                firstname          => 'Daria'
75
                firstname          => 'Daria'
74
            }
76
            }
Lines 100-105 subtest 'store( extended_attributes ) tests' => sub { Link Here
100
102
101
    Koha::Patron::Modification->new(
103
    Koha::Patron::Modification->new(
102
        {   verification_token  => $verification_token,
104
        {   verification_token  => $verification_token,
105
            changed_fields      => 'borrowernumber,surname,extended_attributes',
103
            borrowernumber      => $patron,
106
            borrowernumber      => $patron,
104
            surname             => 'Hall',
107
            surname             => 'Hall',
105
            extended_attributes => $valid_json_text
108
            extended_attributes => $valid_json_text
Lines 120-125 subtest 'store( extended_attributes ) tests' => sub { Link Here
120
    throws_ok {
123
    throws_ok {
121
        Koha::Patron::Modification->new(
124
        Koha::Patron::Modification->new(
122
            {   verification_token  => $verification_token,
125
            {   verification_token  => $verification_token,
126
                changed_fields      => 'borrowernumber,surname,extended_attributes',
123
                borrowernumber      => $patron,
127
                borrowernumber      => $patron,
124
                surname             => 'Hall',
128
                surname             => 'Hall',
125
                extended_attributes => $invalid_json_text
129
                extended_attributes => $invalid_json_text
Lines 153-161 subtest 'approve tests' => sub { Link Here
153
    my $valid_json_text
157
    my $valid_json_text
154
        = '[{"code":"CODE_1","value":"VALUE_1"},{"code":"CODE_2","value":0}]';
158
        = '[{"code":"CODE_1","value":"VALUE_1"},{"code":"CODE_2","value":0}]';
155
    my $patron_modification = Koha::Patron::Modification->new(
159
    my $patron_modification = Koha::Patron::Modification->new(
156
        {   borrowernumber      => $patron_hashref->{borrowernumber},
160
        {   verification_token  => $verification_token,
161
            changed_fields      => 'borrowernumber,firstname,extended_attributes',
162
            borrowernumber      => $patron_hashref->{borrowernumber},
157
            firstname           => 'Kyle',
163
            firstname           => 'Kyle',
158
            verification_token  => $verification_token,
159
            extended_attributes => $valid_json_text
164
            extended_attributes => $valid_json_text
160
        }
165
        }
161
    )->store();
166
    )->store();
Lines 183-191 subtest 'approve tests' => sub { Link Here
183
    # Create a new Koha::Patron::Modification, skip extended_attributes to
188
    # Create a new Koha::Patron::Modification, skip extended_attributes to
184
    # bypass checks
189
    # bypass checks
185
    $patron_modification = Koha::Patron::Modification->new(
190
    $patron_modification = Koha::Patron::Modification->new(
186
        {   borrowernumber     => $patron_hashref->{borrowernumber},
191
        {   verification_token => $verification_token,
187
            firstname          => 'Kylie',
192
            changed_fields     => 'borrowernumber,firstname',
188
            verification_token => $verification_token
193
            borrowernumber     => $patron_hashref->{borrowernumber},
194
            firstname          => 'Kylie'
189
        }
195
        }
190
    )->store();
196
    )->store();
191
197
Lines 205-213 subtest 'approve tests' => sub { Link Here
205
    $verification_token = md5_hex( time() . {} . rand() . {} . $$ );
211
    $verification_token = md5_hex( time() . {} . rand() . {} . $$ );
206
212
207
    $patron_modification = Koha::Patron::Modification->new(
213
    $patron_modification = Koha::Patron::Modification->new(
208
        {   borrowernumber      => $patron->borrowernumber,
214
        {   verification_token  => $verification_token,
209
            extended_attributes => $bigger_json,
215
            changed_fields      => 'borrowernumber,extended_attributes',
210
            verification_token  => $verification_token
216
            borrowernumber      => $patron->borrowernumber,
217
            extended_attributes => $bigger_json
211
        }
218
        }
212
    )->store();
219
    )->store();
213
    ok( $patron_modification->approve,
220
    ok( $patron_modification->approve,
Lines 236-244 subtest 'approve tests' => sub { Link Here
236
    $verification_token = md5_hex( time() . {} . rand() . {} . $$ );
243
    $verification_token = md5_hex( time() . {} . rand() . {} . $$ );
237
244
238
    $patron_modification = Koha::Patron::Modification->new(
245
    $patron_modification = Koha::Patron::Modification->new(
239
        {   borrowernumber      => $patron->borrowernumber,
246
        {   verification_token  => $verification_token,
240
            extended_attributes => $empty_code_json,
247
            changed_fields      => 'borrowernumber,extended_attributes',
241
            verification_token  => $verification_token
248
            borrowernumber      => $patron->borrowernumber,
249
            extended_attributes => $empty_code_json
242
        }
250
        }
243
    )->store();
251
    )->store();
244
    ok( $patron_modification->approve,
252
    ok( $patron_modification->approve,
Lines 291-300 subtest 'pending_count() and pending() tests' => sub { Link Here
291
    Koha::Patron::Attribute->new({ borrowernumber => $patron_2->borrowernumber, code => 'CODE_2', attribute => 'bye' } )->store();
299
    Koha::Patron::Attribute->new({ borrowernumber => $patron_2->borrowernumber, code => 'CODE_2', attribute => 'bye' } )->store();
292
300
293
    my $modification_1 = Koha::Patron::Modification->new(
301
    my $modification_1 = Koha::Patron::Modification->new(
294
        {   borrowernumber     => $patron_1->borrowernumber,
302
        {   verification_token => $verification_token_1,
303
            changed_fields     => 'borrowernumber,surname,firstname,extended_attributes',
304
            borrowernumber     => $patron_1->borrowernumber,
295
            surname            => 'Hall',
305
            surname            => 'Hall',
296
            firstname          => 'Kyle',
306
            firstname          => 'Kyle',
297
            verification_token => $verification_token_1,
298
            extended_attributes => '[{"code":"CODE_1","value":""}]'
307
            extended_attributes => '[{"code":"CODE_1","value":""}]'
299
        }
308
        }
300
    )->store();
309
    )->store();
Lines 303-321 subtest 'pending_count() and pending() tests' => sub { Link Here
303
        1, 'pending_count() correctly returns 1' );
312
        1, 'pending_count() correctly returns 1' );
304
313
305
    my $modification_2 = Koha::Patron::Modification->new(
314
    my $modification_2 = Koha::Patron::Modification->new(
306
        {   borrowernumber     => $patron_2->borrowernumber,
315
        {   verification_token => $verification_token_2,
316
            changed_fields     => 'borrowernumber,surname,firstname,extended_attributes',
317
            borrowernumber     => $patron_2->borrowernumber,
307
            surname            => 'Smith',
318
            surname            => 'Smith',
308
            firstname          => 'Sandy',
319
            firstname          => 'Sandy',
309
            verification_token => $verification_token_2,
310
            extended_attributes => '[{"code":"CODE_2","value":"año"},{"code":"CODE_2","value":"ciao"}]'
320
            extended_attributes => '[{"code":"CODE_2","value":"año"},{"code":"CODE_2","value":"ciao"}]'
311
        }
321
        }
312
    )->store();
322
    )->store();
313
323
314
    my $modification_3 = Koha::Patron::Modification->new(
324
    my $modification_3 = Koha::Patron::Modification->new(
315
        {   borrowernumber     => $patron_3->borrowernumber,
325
        {   verification_token => $verification_token_3,
326
            changed_fields     => 'borrowernumber,surname,firstname',
327
            borrowernumber     => $patron_3->borrowernumber,
316
            surname            => 'Smithy',
328
            surname            => 'Smithy',
317
            firstname          => 'Sandy',
329
            firstname          => 'Sandy'
318
            verification_token => $verification_token_3
319
        }
330
        }
320
    )->store();
331
    )->store();
321
332
Lines 380-387 subtest 'dateofbirth tests' => sub { Link Here
380
391
381
    # Cleaning the field
392
    # Cleaning the field
382
    my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { dateofbirth => '1980-01-01', surname => 'a_surname' } } );
393
    my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { dateofbirth => '1980-01-01', surname => 'a_surname' } } );
383
    my $patron_modification = Koha::Patron::Modification->new( { borrowernumber => $patron->borrowernumber, dateofbirth => undef }
394
    my $patron_modification = Koha::Patron::Modification->new( {
384
    )->store;
395
            changed_fields => 'borrowernumber,dateofbirth',
396
            borrowernumber => $patron->borrowernumber,
397
            dateofbirth => undef
398
    })->store;
385
    $patron_modification->approve;
399
    $patron_modification->approve;
386
400
387
    $patron->discard_changes;
401
    $patron->discard_changes;
Lines 391-398 subtest 'dateofbirth tests' => sub { Link Here
391
    Koha::Patron::Modifications->search({ borrowernumber => $patron->borrowernumber })->delete;
405
    Koha::Patron::Modifications->search({ borrowernumber => $patron->borrowernumber })->delete;
392
406
393
    # Adding a dateofbirth
407
    # Adding a dateofbirth
394
    $patron_modification = Koha::Patron::Modification->new( { borrowernumber => $patron->borrowernumber, dateofbirth => '1980-02-02' }
408
    $patron_modification = Koha::Patron::Modification->new( {
395
    )->store;
409
            changed_fields => 'borrowernumber,dateofbirth',
410
            borrowernumber => $patron->borrowernumber,
411
            dateofbirth => '1980-02-02'
412
    })->store;
396
    $patron_modification->approve;
413
    $patron_modification->approve;
397
414
398
    $patron->discard_changes;
415
    $patron->discard_changes;
Lines 403-410 subtest 'dateofbirth tests' => sub { Link Here
403
    Koha::Patron::Modifications->search({ borrowernumber => $patron->borrowernumber })->delete;
420
    Koha::Patron::Modifications->search({ borrowernumber => $patron->borrowernumber })->delete;
404
421
405
    # Modifying a dateofbirth
422
    # Modifying a dateofbirth
406
    $patron_modification = Koha::Patron::Modification->new( { borrowernumber => $patron->borrowernumber, dateofbirth => '1980-03-03', surname => undef }
423
    $patron_modification = Koha::Patron::Modification->new( {
407
    )->store;
424
            changed_fields => 'borrowernumber,dateofbirth',
425
            borrowernumber => $patron->borrowernumber,
426
            dateofbirth => '1980-03-03',
427
            surname => undef
428
    })->store;
408
    $patron_modification->approve;
429
    $patron_modification->approve;
409
430
410
    $patron->discard_changes;
431
    $patron->discard_changes;
Lines 415-422 subtest 'dateofbirth tests' => sub { Link Here
415
    Koha::Patron::Modifications->search({ borrowernumber => $patron->borrowernumber })->delete;
436
    Koha::Patron::Modifications->search({ borrowernumber => $patron->borrowernumber })->delete;
416
437
417
    # Modifying something else
438
    # Modifying something else
418
    $patron_modification = Koha::Patron::Modification->new( { borrowernumber => $patron->borrowernumber, surname => 'another_surname', dateofbirth => undef }
439
    $patron_modification = Koha::Patron::Modification->new( {
419
    )->store;
440
            changed_fields => 'borrowernumber,surname',
441
            borrowernumber => $patron->borrowernumber,
442
            surname => 'another_surname',
443
            dateofbirth => undef
444
    })->store;
420
    $patron_modification->approve;
445
    $patron_modification->approve;
421
446
422
    $patron->discard_changes;
447
    $patron->discard_changes;
423
- 

Return to bug 23151