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

(-)a/t/db_dependent/Koha/AdditionalField.pm (-1 / +82 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 2;
6
use String::Random qw(random_string);
7
8
use Koha::AuthorisedValueCategory;
9
10
BEGIN {
11
    use_ok('Koha::AdditionalField');
12
}
13
14
my $schema = Koha::Database->schema;
15
16
subtest 'effective_authorised_value_category' => sub {
17
    plan tests => 4;
18
19
    $schema->txn_begin;
20
21
    my $av_category_name = random_string('C' x 32);
22
    my $av_category = Koha::AuthorisedValueCategory->new({ category_name => $av_category_name });
23
    $av_category->store()->discard_changes();
24
25
    my $field = Koha::AdditionalField->new(
26
        {
27
            tablename => random_string('c' x 100),
28
            name => random_string('c' x 100),
29
        }
30
    );
31
    $field->store()->discard_changes();
32
33
    is($field->effective_authorised_value_category, '', 'no default category');
34
35
    $field = Koha::AdditionalField->new(
36
        {
37
            tablename => random_string('c' x 100),
38
            name => random_string('c' x 100),
39
            authorised_value_category => $av_category_name,
40
        }
41
    );
42
    $field->store()->discard_changes();
43
44
    is($field->effective_authorised_value_category, $av_category_name, 'returns authorised_value_category if set');
45
46
    my $mss = Koha::MarcSubfieldStructure->new(
47
        {
48
            frameworkcode => '',
49
            tagfield => '999',
50
            tagsubfield => 'Z',
51
            authorised_value => $av_category_name,
52
        }
53
    );
54
    $mss->store();
55
    $field = Koha::AdditionalField->new(
56
        {
57
            tablename => random_string('c' x 100),
58
            name => random_string('c' x 100),
59
            marcfield => '999$Z',
60
        }
61
    );
62
    $field->store()->discard_changes();
63
64
    is($field->effective_authorised_value_category, $av_category_name, 'returns MARC subfield authorised value category if set');
65
66
    my $av2_category_name = random_string('C' x 32);
67
    my $av2_category = Koha::AuthorisedValueCategory->new({ category_name => $av2_category_name });
68
    $av2_category->store()->discard_changes();
69
    $field = Koha::AdditionalField->new(
70
        {
71
            tablename => random_string('c' x 100),
72
            name => random_string('c' x 100),
73
            authorised_value_category => $av2_category_name,
74
            marcfield => '999$Z',
75
        }
76
    );
77
    $field->store()->discard_changes();
78
79
    is($field->effective_authorised_value_category, $av2_category_name, 'returns authorised_value_category if both authorised_value_category and marcfield are set');
80
81
    $schema->txn_rollback;
82
};

Return to bug 11844