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 |
- |
|
|