|
Lines 1-12
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 => 14; |
4 |
use Test::More tests => 15; |
| 5 |
|
5 |
|
| 6 |
use C4::Context; |
6 |
use C4::Context; |
| 7 |
use Koha::AuthorisedValue; |
7 |
use Koha::AuthorisedValue; |
| 8 |
use Koha::AuthorisedValues; |
8 |
use Koha::AuthorisedValues; |
| 9 |
use Koha::AuthorisedValueCategories; |
9 |
use Koha::AuthorisedValueCategories; |
|
|
10 |
use Koha::MarcSubfieldStructures; |
| 10 |
|
11 |
|
| 11 |
my $dbh = C4::Context->dbh; |
12 |
my $dbh = C4::Context->dbh; |
| 12 |
$dbh->{AutoCommit} = 0; |
13 |
$dbh->{AutoCommit} = 0; |
|
Lines 99-101
my @categories = Koha::AuthorisedValues->new->categories;
Link Here
|
| 99 |
is( @categories, 2, 'There should have 2 categories inserted' ); |
100 |
is( @categories, 2, 'There should have 2 categories inserted' ); |
| 100 |
is( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' ); |
101 |
is( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' ); |
| 101 |
is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' ); |
102 |
is( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' ); |
| 102 |
- |
103 |
|
|
|
104 |
subtest 'search_by_*_field' => sub { |
| 105 |
plan tests => 1; |
| 106 |
my $loc_cat = Koha::AuthorisedValueCategories->find('LOC'); |
| 107 |
$loc_cat->delete if $loc_cat; |
| 108 |
my $mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => 'c', frameworkcode => '' } ); |
| 109 |
$mss->delete if $mss; |
| 110 |
$mss = Koha::MarcSubfieldStructures->search( { tagfield => 952, tagsubfield => 'd', frameworkcode => '' } ); |
| 111 |
$mss->delete if $mss; |
| 112 |
Koha::AuthorisedValueCategory->new( { category_name => 'LOC' } )->store; |
| 113 |
Koha::AuthorisedValueCategory->new( { category_name => 'ANOTHER_4_TESTS' } )->store; |
| 114 |
Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => '', authorised_value => 'LOC', kohafield => 'items.location' } )->store; |
| 115 |
Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'c', frameworkcode => 'ACQ', authorised_value => 'LOC', kohafield => 'items.location' } )->store; |
| 116 |
Koha::MarcSubfieldStructure->new( { tagfield => 952, tagsubfield => 'd', frameworkcode => '', authorised_value => 'ANOTHER_4_TESTS', kohafield => 'items.another_field' } )->store; |
| 117 |
Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_1' } )->store; |
| 118 |
Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_2' } )->store; |
| 119 |
Koha::AuthorisedValue->new( { category => 'LOC', authorised_value => 'location_3' } )->store; |
| 120 |
Koha::AuthorisedValue->new( { category => 'ANOTHER_4_TESTS', authorised_value => 'an_av' } )->store; |
| 121 |
Koha::AuthorisedValue->new( { category => 'ANOTHER_4_TESTS', authorised_value => 'another_av' } )->store; |
| 122 |
subtest 'search_by_marc_field' => sub { |
| 123 |
plan tests => 4; |
| 124 |
my $avs; |
| 125 |
$avs = Koha::AuthorisedValues->search_by_marc_field(); |
| 126 |
is ( $avs, undef ); |
| 127 |
$avs = Koha::AuthorisedValues->search_by_marc_field({ frameworkcode => '' }); |
| 128 |
is ( $avs, undef ); |
| 129 |
$avs = Koha::AuthorisedValues->search_by_marc_field({ tagfield => 952, tagsubfield => 'c'}); |
| 130 |
is( $avs->count, 3, 'default fk'); |
| 131 |
is( $avs->next->authorised_value, 'location_1', ); |
| 132 |
}; |
| 133 |
}; |