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

(-)a/t/db_dependent/TestBuilder.t (-1 / +35 lines)
Lines 19-29 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 11;
22
use Test::More tests => 12;
23
use Test::Warn;
23
use Test::Warn;
24
use Data::Dumper qw(Dumper);
24
use Data::Dumper qw(Dumper);
25
25
26
use Koha::Database;
26
use Koha::Database;
27
use Koha::Patrons;
27
28
28
BEGIN {
29
BEGIN {
29
    use_ok('t::lib::TestBuilder');
30
    use_ok('t::lib::TestBuilder');
Lines 343-346 subtest 'Default values' => sub { Link Here
343
344
344
$schema->storage->txn_rollback;
345
$schema->storage->txn_rollback;
345
346
347
subtest 'build_object() tests' => sub {
348
349
    plan tests => 7;
350
351
    $schema->storage->txn_begin;
352
353
    $builder = t::lib::TestBuilder->new();
354
    my $patron = $builder->build_object(
355
        {   class => 'Koha::Patrons',
356
            id    => 'borrowernumber',
357
            value => { firstname => 'Tomasito', surname => 'None' }
358
        }
359
    );
360
361
    is( ref($patron),       'Koha::Patron', 'Type is correct' );
362
    is( $patron->firstname, 'Tomasito',     'Firstname correctly set' );
363
    is( $patron->surname,   'None',         'Firstname correctly set' );
364
365
    warning_is
366
        { $patron = $builder->build_object({ class => 'Koha::Patrons' }); }
367
        { carped => 'Missing id param' },
368
        'The id parameter is mandatory, raises a warning if absent';
369
    is( $patron, undef, 'If the id parameter is missing, undef is returned' );
370
371
    warning_is
372
        { $patron = $builder->build_object({ id => 'borrowernumber' }); }
373
        { carped => 'Missing class param' },
374
        'The class parameter is mandatory, raises a warning if absent';
375
    is( $patron, undef, 'If the class parameter is missing, undef is returned' );
376
377
    $schema->storage->txn_rollback;
378
};
379
346
1;
380
1;
(-)a/t/lib/TestBuilder.pm (-1 / +30 lines)
Lines 1-7 Link Here
1
package t::lib::TestBuilder;
1
package t::lib::TestBuilder;
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
use Koha::Database;
5
use Koha::Database;
6
7
use Carp;
8
use Module::Load;
5
use String::Random;
9
use String::Random;
6
10
7
sub new {
11
sub new {
Lines 51-56 sub delete { Link Here
51
    return $rv;
55
    return $rv;
52
}
56
}
53
57
58
sub build_object {
59
    my ( $self, $params ) = @_;
60
61
    my $class = $params->{class};
62
    my $id    = $params->{id};
63
    my $value = $params->{value};
64
65
    if ( not defined $class ) {
66
        carp "Missing class param";
67
        return;
68
    }
69
70
    if ( not defined $id ) {
71
        carp "Missing id param";
72
        return;
73
    }
74
75
    load $class;
76
    my $source = $class->_type;
77
78
    my $hashref = $self->build({ source => $source, value => $value });
79
    my $object = $class->find( $hashref->{$id} );
80
81
    return $object;
82
}
83
54
sub build {
84
sub build {
55
# build returns a hash of column values for a created record, or undef
85
# build returns a hash of column values for a created record, or undef
56
# build does NOT update a record, or pass back values of an existing record
86
# build does NOT update a record, or pass back values of an existing record
57
- 

Return to bug 18182