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

(-)a/Koha/AuthorisedValueCategories.pm (+20 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Carp;
20
use Carp;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Exceptions::CannotDeleteDefault;
23
24
24
use Koha::AuthorisedValueCategory;
25
use Koha::AuthorisedValueCategory;
25
26
Lines 35-40 Koha::AuthorisedValueCategories - Koha AuthorisedValueCategory Object set class Link Here
35
36
36
=cut
37
=cut
37
38
39
=head3 delete
40
41
Overridden delete method to prevent system default deletions
42
43
=cut
44
45
sub delete {
46
    my ($self) = @_;
47
48
    my @set = $self->as_list;
49
    for my $type (@set) {
50
        if ( $type->is_system ) {
51
            Koha::Exceptions::CannotDeleteDefault->throw;
52
        }
53
    }
54
55
    return $self->SUPER::delete;
56
}
57
38
=head3 type
58
=head3 type
39
59
40
=cut
60
=cut
(-)a/Koha/AuthorisedValueCategory.pm (+15 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Carp;
20
use Carp;
21
21
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Exceptions::CannotDeleteDefault;
23
24
24
use base qw(Koha::Object);
25
use base qw(Koha::Object);
25
26
Lines 33-38 Koha::AuthorisedValueCategory - Koha AuthorisedValueCategory Object class Link Here
33
34
34
=cut
35
=cut
35
36
37
=head3 delete
38
39
Overridden delete method to prevent system default deletions
40
41
=cut
42
43
sub delete {
44
    my ($self) = @_;
45
46
    Koha::Exceptions::CannotDeleteDefault->throw if $self->is_system;
47
48
    return $self->SUPER::delete;
49
}
50
36
=head3 type
51
=head3 type
37
52
38
=cut
53
=cut
(-)a/t/db_dependent/AuthorisedValues.t (-3 / +25 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 15;
4
use Test::More tests => 17;
5
use Try::Tiny;
5
6
6
use t::lib::TestBuilder;
7
use t::lib::TestBuilder;
7
8
Lines 20-26 Koha::AuthorisedValues->delete; Link Here
20
Koha::AuthorisedValueCategories->delete;
21
Koha::AuthorisedValueCategories->delete;
21
22
22
# insert
23
# insert
23
Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing' })->store;
24
Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing', is_system => 1 })->store;
24
Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store;
25
Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store;
25
Koha::AuthorisedValueCategory->new({ category_name => 'restricted_for_testing' })->store;
26
Koha::AuthorisedValueCategory->new({ category_name => 'restricted_for_testing' })->store;
26
my $av1 = Koha::AuthorisedValue->new(
27
my $av1 = Koha::AuthorisedValue->new(
Lines 84-89 ok( $av2->id(), 'AV 2 is inserted' ); Link Here
84
ok( $av3->id(), 'AV 3 is inserted' );
85
ok( $av3->id(), 'AV 3 is inserted' );
85
ok( $av4->id(), 'AV 4 is inserted' );
86
ok( $av4->id(), 'AV 4 is inserted' );
86
87
88
{ # delete is_system AV categories
89
    try {
90
        Koha::AuthorisedValueCategories->find('av_for_testing')->delete
91
    }
92
    catch {
93
        ok(
94
            $_->isa('Koha::Exceptions::CannotDeleteDefault'),
95
            'A system AV category cannot be deleted'
96
        );
97
    };
98
99
    try {
100
        Koha::AuthorisedValueCategories->search->delete
101
    }
102
    catch {
103
        ok(
104
            $_->isa('Koha::Exceptions::CannotDeleteDefault'),
105
            'system AV categories cannot be deleted'
106
        );
107
    };
108
}
109
87
is( $av3->opac_description, 'opac display value 3', 'Got correction opac description if lib_opac is set' );
110
is( $av3->opac_description, 'opac display value 3', 'Got correction opac description if lib_opac is set' );
88
$av3->lib_opac('');
111
$av3->lib_opac('');
89
is( $av3->opac_description, 'display value 3', 'Got correction opac description if lib_opac is *not* set' );
112
is( $av3->opac_description, 'display value 3', 'Got correction opac description if lib_opac is *not* set' );
90
- 

Return to bug 17355