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

(-)a/Koha/AuthorisedValueCategories.pm (-7 / +10 lines)
Lines 49-61 sub find_by_koha_field { Link Here
49
49
50
    $frameworkcode //= '';
50
    $frameworkcode //= '';
51
51
52
    my ($subfield) = Koha::MarcSubfieldStructures->search({
52
    my $avc = $class->SUPER::search(
53
        frameworkcode => $frameworkcode,
53
        {   'marc_subfield_structures.frameworkcode'    => $frameworkcode,
54
        kohafield => $kohafield,
54
            'marc_subfield_structures.kohafield'        => $kohafield,
55
        authorised_value => { not => undef },
55
            'marc_subfield_structures.authorised_value' => { not => undef },
56
    });
56
        },
57
57
        {   join     => 'marc_subfield_structures',
58
    return $subfield ? $class->find($subfield->authorised_value) : undef;
58
            distinct => 1,
59
        }
60
    );
61
    return $avc->count ? $avc->next : undef;
59
}
62
}
60
63
61
=head3 type
64
=head3 type
(-)a/t/db_dependent/Koha/AuthorisedValueCategories.t (-20 / +25 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 2;
23
23
24
use Koha::MarcSubfieldStructures;
24
use Koha::MarcSubfieldStructures;
25
use Koha::Database;
25
use Koha::Database;
Lines 33-59 BEGIN { Link Here
33
my $schema = Koha::Database->new->schema;
33
my $schema = Koha::Database->new->schema;
34
$schema->storage->txn_begin;
34
$schema->storage->txn_begin;
35
35
36
my $category = Koha::AuthorisedValueCategories->find_or_create({
36
subtest '->find_by_koha_field' => sub {
37
    category_name => 'TEST',
37
    plan tests => 3;
38
});
38
    my $category = Koha::AuthorisedValueCategories->find_or_create({
39
        category_name => 'TEST',
40
    });
39
41
40
Koha::MarcSubfieldStructures->search({
42
    Koha::MarcSubfieldStructures->search({
41
    frameworkcode => '',
43
        frameworkcode => '',
42
    kohafield => 'items.notforloan',
44
        kohafield => 'items.notforloan',
43
})->delete();
45
    })->delete();
44
46
45
my $subfield = Koha::MarcSubfieldStructures->find_or_create({
47
    my $avc = Koha::AuthorisedValueCategories->find_by_koha_field('items.notforloan');
46
    frameworkcode => '',
48
    is($avc, undef, '->find_by_koha_field should return undef if no category is linked to this field');
47
    tagfield => 999,
48
    tagsubfield => 9,
49
});
50
$subfield->authorised_value($category->category_name)
51
    ->kohafield('items.notforloan')
52
    ->store();
53
49
54
my $result = Koha::AuthorisedValueCategories->find_by_koha_field('items.notforloan');
50
    my $subfield = Koha::MarcSubfieldStructures->find_or_create({
51
        frameworkcode => '',
52
        tagfield => 999,
53
        tagsubfield => 9,
54
    });
55
    $subfield->authorised_value($category->category_name)
56
        ->kohafield('items.notforloan')
57
        ->store();
55
58
56
isa_ok($result, 'Koha::AuthorisedValueCategory', 'Result found');
59
    $avc = Koha::AuthorisedValueCategories->find_by_koha_field('items.notforloan');
57
is($result->category_name, $category->category_name, 'Result is correct');
60
61
    isa_ok($avc, 'Koha::AuthorisedValueCategory', '->find_by_koha_field should return a Koha::AuthorisedValueCategory');
62
    is($avc->category_name, $avc->category_name, '->find_by_koha_field should return the correct category');
63
};
58
64
59
$schema->storage->txn_rollback;
65
$schema->storage->txn_rollback;
60
- 

Return to bug 18433