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

(-)a/Koha/Exceptions/Object.pm (+8 lines)
Lines 23-28 use Exception::Class ( Link Here
23
    'Koha::Exceptions::Object' => {
23
    'Koha::Exceptions::Object' => {
24
        isa         => 'Koha::Exceptions::Exception',
24
        isa         => 'Koha::Exceptions::Exception',
25
    },
25
    },
26
    'Koha::Exceptions::Object::CannotBeDeleted' => {
27
        isa         => 'Koha::Exceptions::Object',
28
        description => 'The object cannot be deleted',
29
        fields      => ['object', 'reason'],
30
    },
26
    'Koha::Exceptions::Object::DuplicateID' => {
31
    'Koha::Exceptions::Object::DuplicateID' => {
27
        isa         => 'Koha::Exceptions::Object',
32
        isa         => 'Koha::Exceptions::Object',
28
        description => "Duplicate ID passed",
33
        description => "Duplicate ID passed",
Lines 84-89 sub full_message { Link Here
84
        elsif ( $self->isa('Koha::Exceptions::Object::NotInstantiated') ) {
89
        elsif ( $self->isa('Koha::Exceptions::Object::NotInstantiated') ) {
85
            $msg = sprintf("Tried to access the '%s' method, but %s is not instantiated", $self->method, $self->class );
90
            $msg = sprintf("Tried to access the '%s' method, but %s is not instantiated", $self->method, $self->class );
86
        }
91
        }
92
        elsif ( $self->isa('Koha::Exceptions::Object::CannotBeDeleted') ) {
93
            $msg = sprintf("Cannot delete %s object (id=%s). Reason: %s", $self->object->_get_object_class, $self->object->id, $self->reason );
94
        }
87
    }
95
    }
88
96
89
    return $msg;
97
    return $msg;
(-)a/t/Koha/Exceptions.t (-2 / +23 lines)
Lines 17-26 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 6;
20
use Test::More tests => 7;
21
use Test::MockObject;
21
use Test::MockObject;
22
use Test::Exception;
22
use Test::Exception;
23
23
24
use Koha::Items;
25
24
subtest 'Koha::Exceptions::Hold tests' => sub {
26
subtest 'Koha::Exceptions::Hold tests' => sub {
25
27
26
    plan tests => 5;
28
    plan tests => 5;
Lines 196-198 subtest 'Koha::Exceptions::Object::NotInstantiated tests' => sub { Link Here
196
        'Exception is thrown :-D';
198
        'Exception is thrown :-D';
197
    is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
199
    is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
198
};
200
};
199
- 
201
202
subtest 'Koha::Exceptions::Object::CannotBeDeleted tests' => sub {
203
204
    plan tests => 4;
205
206
    throws_ok
207
        { Koha::Exceptions::Object::CannotBeDeleted->throw(
208
            object => Koha::Item->new({ itemnumber => 1234 }), reason => 'Some reason' ); }
209
        'Koha::Exceptions::Object::CannotBeDeleted',
210
        'Exception is thrown :-D';
211
212
    # stringify the exception
213
    like( "$@", qr/Cannot delete Koha::Item=HASH\(.*\) object \(id=1234\). Reason: Some reason/ );
214
215
    throws_ok
216
        { Koha::Exceptions::Object::CannotBeDeleted->throw( "Manual message exception" ) }
217
        'Koha::Exceptions::Object::CannotBeDeleted',
218
        'Exception is thrown :-D';
219
    is( "$@", 'Manual message exception', 'Exception not stringified if manually passed' );
220
};

Return to bug 26509