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

(-)a/Koha/Exceptions/Patron/Attribute.pm (+11 lines)
Lines 7-12 use Exception::Class ( Link Here
7
    'Koha::Exceptions::Patron::Attribute' => {
7
    'Koha::Exceptions::Patron::Attribute' => {
8
        description => 'Something went wrong'
8
        description => 'Something went wrong'
9
    },
9
    },
10
    'Koha::Exceptions::Patron::Attribute::InvalidType' => {
11
        isa         => 'Koha::Exceptions::Patron::Attribute',
12
        description => "the passed type is invalid",
13
        fields      => [ "type" ]
14
    },
10
    'Koha::Exceptions::Patron::Attribute::NonRepeatable' => {
15
    'Koha::Exceptions::Patron::Attribute::NonRepeatable' => {
11
        isa         => 'Koha::Exceptions::Patron::Attribute',
16
        isa         => 'Koha::Exceptions::Patron::Attribute',
12
        description => "repeatable not set for attribute type and tried to add a new attribute for the same code",
17
        description => "repeatable not set for attribute type and tried to add a new attribute for the same code",
Lines 39-44 sub full_message { Link Here
39
                $self->attribute->attribute
44
                $self->attribute->attribute
40
            );
45
            );
41
        }
46
        }
47
        elsif ( $self->isa('Koha::Exceptions::Patron::Attribute::InvalidType') ) {
48
            $msg = sprintf(
49
                "Tried to use an invalid attribute type. type=%s",
50
                $self->type
51
            );
52
        }
42
    }
53
    }
43
54
44
    return $msg;
55
    return $msg;
(-)a/t/Koha/Exceptions.t (-4 / +62 lines)
Lines 200-206 subtest 'Koha::Exceptions::Object::NotInstantiated tests' => sub { Link Here
200
200
201
subtest 'Koha::Exceptions::Patron::Attribute::* tests' => sub {
201
subtest 'Koha::Exceptions::Patron::Attribute::* tests' => sub {
202
202
203
    plan tests => 5;
203
    plan tests => 13;
204
204
205
    use_ok("Koha::Exceptions::Patron::Attribute");
205
    use_ok("Koha::Exceptions::Patron::Attribute");
206
206
Lines 218-228 subtest 'Koha::Exceptions::Patron::Attribute::* tests' => sub { Link Here
218
        'Exception is thrown :-D';
218
        'Exception is thrown :-D';
219
219
220
    # stringify the exception
220
    # stringify the exception
221
    is( "$@", "Tried to add more than one non-repeatable attributes. code=$code attribute=$attribute", 'Exception stringified correctly' );
221
    is(
222
        "$@",
223
        "Tried to add more than one non-repeatable attributes. code=$code attribute=$attribute",
224
        'Exception stringified correctly'
225
    );
222
226
223
    throws_ok
227
    throws_ok
224
        { Koha::Exceptions::Patron::Attribute::NonRepeatable->throw( "Manual message exception" ) }
228
        { Koha::Exceptions::Patron::Attribute::NonRepeatable->throw( "Manual message exception" ) }
225
        'Koha::Exceptions::Patron::Attribute::NonRepeatable',
229
        'Koha::Exceptions::Patron::Attribute::NonRepeatable',
226
        'Exception is thrown :-D';
230
        'Exception is thrown :-D';
227
    is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
231
232
    is(
233
        "$@",
234
        'Manual message exception',
235
        'Exception not stringified if manually passed'
236
    );
237
238
    throws_ok
239
        { Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw(
240
            attribute => $mocked_attribute ); }
241
        'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint',
242
        'Exception is thrown :-D';
243
244
    # stringify the exception
245
    is(
246
        "$@",
247
        "Your action breaks a unique constraint on the attribute. code=$code attribute=$attribute",
248
        'Exception stringified correctly'
249
    );
250
251
    throws_ok
252
        { Koha::Exceptions::Patron::Attribute::UniqueIDConstraint->throw( "Manual message exception" ) }
253
        'Koha::Exceptions::Patron::Attribute::UniqueIDConstraint',
254
        'Exception is thrown :-D';
255
 
256
    is(
257
        "$@",
258
        'Manual message exception',
259
        'Exception not stringified if manually passed'
260
    );
261
262
    my $type = "SOME_TYPE";
263
264
    throws_ok
265
        { Koha::Exceptions::Patron::Attribute::InvalidType->throw(
266
            type => $type ); }
267
        'Koha::Exceptions::Patron::Attribute::InvalidType',
268
        'Exception is thrown :-D';
269
270
    # stringify the exception
271
    is(
272
        "$@",
273
        "Tried to use an invalid attribute type. type=$type",
274
        'Exception stringified correctly'
275
    );
276
277
    throws_ok
278
        { Koha::Exceptions::Patron::Attribute::InvalidType->throw( "Manual message exception" ) }
279
        'Koha::Exceptions::Patron::Attribute::InvalidType',
280
        'Exception is thrown :-D';
281
282
    is(
283
        "$@",
284
        'Manual message exception',
285
        'Exception not stringified if manually passed'
286
    );
228
};
287
};
229
- 

Return to bug 27833