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

(-)a/t/db_dependent/TestBuilder.t (-5 / +48 lines)
Lines 33-44 BEGIN { Link Here
33
}
33
}
34
34
35
our $schema = Koha::Database->new->schema;
35
our $schema = Koha::Database->new->schema;
36
$schema->storage->txn_begin;
37
our $builder;
36
our $builder;
38
37
39
subtest 'Start with some trivial tests' => sub {
38
subtest 'Start with some trivial tests' => sub {
40
    plan tests => 7;
39
    plan tests => 7;
41
40
41
    $schema->storage->txn_begin;
42
42
    $builder = t::lib::TestBuilder->new;
43
    $builder = t::lib::TestBuilder->new;
43
    isnt( $builder, undef, 'We got a builder' );
44
    isnt( $builder, undef, 'We got a builder' );
44
45
Lines 61-72 subtest 'Start with some trivial tests' => sub { Link Here
61
    warning_like { $builder->build( $param ) }
62
    warning_like { $builder->build( $param ) }
62
        qr/Violation of unique constraint/,
63
        qr/Violation of unique constraint/,
63
        'Catch warn on adding existing record';
64
        'Catch warn on adding existing record';
65
66
    $schema->storage->txn_rollback;
64
};
67
};
65
68
66
69
67
subtest 'Build all sources' => sub {
70
subtest 'Build all sources' => sub {
68
    plan tests => 1;
71
    plan tests => 1;
69
72
73
    $schema->storage->txn_begin;
74
70
    my @sources = $builder->schema->sources;
75
    my @sources = $builder->schema->sources;
71
    my @source_in_failure;
76
    my @source_in_failure;
72
    for my $source ( @sources ) {
77
    for my $source ( @sources ) {
Lines 82-93 subtest 'Build all sources' => sub { Link Here
82
        diag( "The following sources have not been generated correctly: " .
87
        diag( "The following sources have not been generated correctly: " .
83
        join ', ', @source_in_failure );
88
        join ', ', @source_in_failure );
84
    }
89
    }
90
91
    $schema->storage->txn_rollback;
85
};
92
};
86
93
87
94
88
subtest 'Test length of some generated fields' => sub {
95
subtest 'Test length of some generated fields' => sub {
89
    plan tests => 3;
96
    plan tests => 3;
90
97
98
    $schema->storage->txn_begin;
99
91
    # Test the length of a returned character field
100
    # Test the length of a returned character field
92
    my $bookseller = $builder->build({ source  => 'Aqbookseller' });
101
    my $bookseller = $builder->build({ source  => 'Aqbookseller' });
93
    my $max = $schema->source('Aqbookseller')->column_info('phone')->{size};
102
    my $max = $schema->source('Aqbookseller')->column_info('phone')->{size};
Lines 98-109 subtest 'Test length of some generated fields' => sub { Link Here
98
107
99
    my $item = $builder->build({ source => 'Item' });
108
    my $item = $builder->build({ source => 'Item' });
100
    is( $item->{replacementprice}, sprintf("%.2f", $item->{replacementprice}), "The number of decimals for floats should not be more than 2" );
109
    is( $item->{replacementprice}, sprintf("%.2f", $item->{replacementprice}), "The number of decimals for floats should not be more than 2" );
110
111
    $schema->storage->txn_rollback;
101
};
112
};
102
113
103
114
104
subtest 'Test FKs in overduerules_transport_type' => sub {
115
subtest 'Test FKs in overduerules_transport_type' => sub {
105
    plan tests => 5;
116
    plan tests => 5;
106
117
118
    $schema->storage->txn_begin;
119
107
    my $my_overduerules_transport_type = {
120
    my $my_overduerules_transport_type = {
108
        message_transport_type => {
121
        message_transport_type => {
109
            message_transport_type => 'my msg_t_t',
122
            message_transport_type => 'my msg_t_t',
Lines 143-154 subtest 'Test FKs in overduerules_transport_type' => sub { Link Here
143
        undef,
156
        undef,
144
        'build generates values if they are not given'
157
        'build generates values if they are not given'
145
    );
158
    );
159
160
    $schema->storage->txn_rollback;
146
};
161
};
147
162
148
163
149
subtest 'Tests with composite FK in userpermission' => sub {
164
subtest 'Tests with composite FK in userpermission' => sub {
150
    plan tests => 9;
165
    plan tests => 9;
151
166
167
    $schema->storage->txn_begin;
168
152
    my $my_user_permission = default_userpermission();
169
    my $my_user_permission = default_userpermission();
153
    my $user_permission = $builder->build({
170
    my $user_permission = $builder->build({
154
        source => 'UserPermission',
171
        source => 'UserPermission',
Lines 206-211 subtest 'Tests with composite FK in userpermission' => sub { Link Here
206
        $my_user_permission->{code}->{description},
223
        $my_user_permission->{code}->{description},
207
        'build stored description correctly'
224
        'build stored description correctly'
208
    );
225
    );
226
227
    $schema->storage->txn_rollback;
209
};
228
};
210
229
211
sub default_userpermission {
230
sub default_userpermission {
Lines 238-243 sub default_userpermission { Link Here
238
subtest 'Test build with NULL values' => sub {
257
subtest 'Test build with NULL values' => sub {
239
    plan tests => 3;
258
    plan tests => 3;
240
259
260
    $schema->storage->txn_begin;
261
241
    # PK should not be null
262
    # PK should not be null
242
    my $params = { source => 'Branch', value => { branchcode => undef }};
263
    my $params = { source => 'Branch', value => { branchcode => undef }};
243
    warning_like { $builder->build( $params ) }
264
    warning_like { $builder->build( $params ) }
Lines 255-266 subtest 'Test build with NULL values' => sub { Link Here
255
    $info = $schema->source( 'Reserve' )->column_info( 'itemnumber' );
276
    $info = $schema->source( 'Reserve' )->column_info( 'itemnumber' );
256
    is( $reserve && $info->{is_nullable} && $info->{is_foreign_key} &&
277
    is( $reserve && $info->{is_nullable} && $info->{is_foreign_key} &&
257
        !defined( $reserve->{itemnumber} ), 1, 'Nullable FK' );
278
        !defined( $reserve->{itemnumber} ), 1, 'Nullable FK' );
279
280
    $schema->storage->txn_rollback;
258
};
281
};
259
282
260
283
261
subtest 'Tests for delete method' => sub {
284
subtest 'Tests for delete method' => sub {
262
    plan tests => 12;
285
    plan tests => 12;
263
286
287
    $schema->storage->txn_begin;
288
264
    # Test delete with single and multiple records
289
    # Test delete with single and multiple records
265
    my $basket1 = $builder->build({ source => 'Aqbasket' });
290
    my $basket1 = $builder->build({ source => 'Aqbasket' });
266
    my $basket2 = $builder->build({ source => 'Aqbasket' });
291
    my $basket2 = $builder->build({ source => 'Aqbasket' });
Lines 299-310 subtest 'Tests for delete method' => sub { Link Here
299
             code       => undef };
324
             code       => undef };
300
    is( $builder->delete({ source => 'Permission', records => $val }), 0,
325
    is( $builder->delete({ source => 'Permission', records => $val }), 0,
301
        'delete returns zero for an undef search with a composite PK' );
326
        'delete returns zero for an undef search with a composite PK' );
302
};
303
327
328
    $schema->storage->txn_rollback;
329
};
304
330
305
subtest 'Auto-increment values tests' => sub {
331
subtest 'Auto-increment values tests' => sub {
306
    plan tests => 3;
332
    plan tests => 3;
307
333
334
    $schema->storage->txn_begin;
335
308
    # Pick a table with AI PK
336
    # Pick a table with AI PK
309
    my $source  = 'Biblio'; # table
337
    my $source  = 'Biblio'; # table
310
    my $column  = 'biblionumber'; # ai column
338
    my $column  = 'biblionumber'; # ai column
Lines 328-348 subtest 'Auto-increment values tests' => sub { Link Here
328
            value  => { biblionumber => 123 },
356
            value  => { biblionumber => 123 },
329
        }) } qr/^Value not allowed for auto_incr/,
357
        }) } qr/^Value not allowed for auto_incr/,
330
        'Build should not overwrite an auto_incr column';
358
        'Build should not overwrite an auto_incr column';
359
360
    $schema->storage->txn_rollback;
331
};
361
};
332
362
333
subtest 'Date handling' => sub {
363
subtest 'Date handling' => sub {
334
    plan tests => 2;
364
    plan tests => 2;
335
365
366
    $schema->storage->txn_begin;
367
336
    $builder = t::lib::TestBuilder->new;
368
    $builder = t::lib::TestBuilder->new;
337
369
338
    my $patron = $builder->build( { source => 'Borrower' } );
370
    my $patron = $builder->build( { source => 'Borrower' } );
339
    is( length( $patron->{updated_on} ),  19, 'A timestamp column value should be YYYY-MM-DD HH:MM:SS' );
371
    is( length( $patron->{updated_on} ),  19, 'A timestamp column value should be YYYY-MM-DD HH:MM:SS' );
340
    is( length( $patron->{dateofbirth} ), 10, 'A date column value should be YYYY-MM-DD' );
372
    is( length( $patron->{dateofbirth} ), 10, 'A date column value should be YYYY-MM-DD' );
373
374
    $schema->storage->txn_rollback;
341
};
375
};
342
376
343
subtest 'Default values' => sub {
377
subtest 'Default values' => sub {
344
    plan tests => 3;
378
    plan tests => 3;
345
379
380
    $schema->storage->txn_begin;
381
346
    $builder = t::lib::TestBuilder->new;
382
    $builder = t::lib::TestBuilder->new;
347
    my $item = $builder->build( { source => 'Item' } );
383
    my $item = $builder->build( { source => 'Item' } );
348
    is( $item->{more_subfields_xml}, undef, 'This xml field should be undef' );
384
    is( $item->{more_subfields_xml}, undef, 'This xml field should be undef' );
Lines 358-369 subtest 'Default values' => sub { Link Here
358
        $patron = $builder->build_object({ class => 'Koha::Patrons', value => {categorycode => $patron_category_X->categorycode} });
394
        $patron = $builder->build_object({ class => 'Koha::Patrons', value => {categorycode => $patron_category_X->categorycode} });
359
        is( $patron->category->category_type, 'X', );
395
        is( $patron->category->category_type, 'X', );
360
    };
396
    };
397
398
    $schema->storage->txn_rollback;
361
};
399
};
362
400
363
subtest 'build_object() tests' => sub {
401
subtest 'build_object() tests' => sub {
364
402
365
    plan tests => 5;
403
    plan tests => 5;
366
404
405
    $schema->storage->txn_begin;
406
367
    $builder = t::lib::TestBuilder->new();
407
    $builder = t::lib::TestBuilder->new();
368
408
369
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
409
    my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
Lines 428-438 subtest 'build_object() tests' => sub { Link Here
428
                { class => 'Koha::Patrons', categorycode => 'foobar' } );
468
                { class => 'Koha::Patrons', categorycode => 'foobar' } );
429
        } qr{Unknown parameter\(s\): categorycode}, "Unknown parameter detected";
469
        } qr{Unknown parameter\(s\): categorycode}, "Unknown parameter detected";
430
    };
470
    };
471
472
    $schema->storage->txn_rollback;
431
};
473
};
432
474
433
subtest '->build parameter' => sub {
475
subtest '->build parameter' => sub {
434
    plan tests => 4;
476
    plan tests => 4;
435
477
478
    $schema->storage->txn_begin;
479
436
    # Test to make sure build() warns user of unknown parameters.
480
    # Test to make sure build() warns user of unknown parameters.
437
    warnings_are {
481
    warnings_are {
438
        $builder->build({
482
        $builder->build({
Lines 460-468 subtest '->build parameter' => sub { Link Here
460
        $builder->build(
504
        $builder->build(
461
            { source => 'Borrower', categorycode => 'foobar' } );
505
            { source => 'Borrower', categorycode => 'foobar' } );
462
    } qr{Unknown parameter\(s\): categorycode}, "Unkown parameter detected";
506
    } qr{Unknown parameter\(s\): categorycode}, "Unkown parameter detected";
463
};
464
507
465
$schema->storage->txn_rollback;
508
    $schema->storage->txn_rollback;
509
};
466
510
467
subtest 'build_sample_biblio() tests' => sub {
511
subtest 'build_sample_biblio() tests' => sub {
468
512
469
- 

Return to bug 29862