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

(-)a/t/db_dependent/Koha/Patron/Attributes.t (-2 / +66 lines)
Lines 19-34 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 2;
22
use Test::More tests => 3;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use Test::Exception;
25
26
26
use Koha::Database;
27
use Koha::Database;
27
use Koha::Patron::Attribute;
28
use Koha::Patron::Attribute;
29
use Koha::Patron::Attributes;
28
30
29
my $schema  = Koha::Database->new->schema;
31
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
32
my $builder = t::lib::TestBuilder->new;
31
33
34
subtest 'store() tests' => sub {
35
36
    plan tests => 4;
37
38
    $schema->storage->txn_begin;
39
40
    my $patron
41
        = $builder->build( { source => 'Borrower' } )->{borrowernumber};
42
    my $attribute_type_1 = $builder->build(
43
        {   source => 'BorrowerAttributeType',
44
            value  => { unique_id => 0 }
45
        }
46
    );
47
    Koha::Patron::Attribute->new(
48
        {   borrowernumber => $patron,
49
            code           => $attribute_type_1->{code},
50
            attribute      => 'Foo'
51
        }
52
    )->store;
53
    Koha::Patron::Attribute->new(
54
        {   borrowernumber => $patron,
55
            code           => $attribute_type_1->{code},
56
            attribute      => 'Bar'
57
        }
58
    )->store;
59
    my $attr_count
60
        = Koha::Patron::Attributes->search(
61
        { borrowernumber => $patron, code => $attribute_type_1->{code} } )
62
        ->count;
63
    is( $attr_count, 2,
64
        '2 non-unique attributes stored and retrieved correcctly' );
65
66
    my $attribute_type_2 = $builder->build(
67
        {   source => 'BorrowerAttributeType',
68
            value  => { unique_id => 1 }
69
        }
70
    );
71
72
    Koha::Patron::Attribute->new(
73
        {   borrowernumber => $patron,
74
            code           => $attribute_type_2->{code},
75
            attribute      => 'Foo'
76
        }
77
    )->store;
78
    throws_ok {
79
        Koha::Patron::Attribute->new(
80
            {   borrowernumber => $patron,
81
                code           => $attribute_type_2->{code},
82
                attribute      => 'Bar'
83
            }
84
        )->store;
85
    }
86
    'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint',
87
        'Exception thrown trying to store more than one unique attribute';
88
    my $attributes = Koha::Patron::Attributes->search(
89
        { borrowernumber => $patron, code => $attribute_type_2->{code} } );
90
    is( $attributes->count, 1, '1 Unique attribute stored' );
91
    is( $attributes->next->attribute,
92
        'Foo', 'Unique attribute remains unchanged' );
93
94
    $schema->storage->txn_rollback;
95
};
96
32
subtest 'opac_display() tests' => sub {
97
subtest 'opac_display() tests' => sub {
33
98
34
    plan tests => 2;
99
    plan tests => 2;
35
- 

Return to bug 17828