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 => 16; |
4 |
use Test::More tests => 17; |
5 |
|
5 |
|
6 |
use C4::Context; |
6 |
use C4::Context; |
7 |
use Koha::AuthorisedValue; |
7 |
use Koha::AuthorisedValue; |
Lines 20-25
$dbh->do("DELETE FROM authorised_value_categories");
Link Here
|
20 |
Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing' })->store; |
20 |
Koha::AuthorisedValueCategory->new({ category_name => 'av_for_testing' })->store; |
21 |
Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store; |
21 |
Koha::AuthorisedValueCategory->new({ category_name => 'aaav_for_testing' })->store; |
22 |
Koha::AuthorisedValueCategory->new({ category_name => 'restricted_for_testing' })->store; |
22 |
Koha::AuthorisedValueCategory->new({ category_name => 'restricted_for_testing' })->store; |
|
|
23 |
|
23 |
my $av1 = Koha::AuthorisedValue->new( |
24 |
my $av1 = Koha::AuthorisedValue->new( |
24 |
{ |
25 |
{ |
25 |
category => 'av_for_testing', |
26 |
category => 'av_for_testing', |
Lines 81-86
ok( $av2->id(), 'AV 2 is inserted' );
Link Here
|
81 |
ok( $av3->id(), 'AV 3 is inserted' ); |
82 |
ok( $av3->id(), 'AV 3 is inserted' ); |
82 |
ok( $av4->id(), 'AV 4 is inserted' ); |
83 |
ok( $av4->id(), 'AV 4 is inserted' ); |
83 |
|
84 |
|
|
|
85 |
sub GetAuthValues { |
86 |
require Test::More; |
87 |
my @Getauthorised_values = |
88 |
Koha::AuthorisedValues->new()->search({ |
89 |
category => 'av_for_testing', |
90 |
}, |
91 |
{ |
92 |
order_by => [qw/ lib /] |
93 |
}); |
94 |
}; |
95 |
my @Getauthorised_values = GetAuthValues(); |
96 |
is( @Getauthorised_values, 3, "Get correct number of values" ); |
97 |
|
98 |
sub GetDistinctCat { |
99 |
require Test::More; |
100 |
my @distinctauthorised_values = |
101 |
Koha::AuthorisedValues->new()->search({ |
102 |
category => { 'like','%a%'}, |
103 |
}); |
104 |
}; |
105 |
my @distinctauthorised_values = GetDistinctCat(); |
106 |
is( @distinctauthorised_values, 4, "Correct number of distinct values" ); |
107 |
|
108 |
|
109 |
|
84 |
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' ); |
85 |
$av3->lib_opac(''); |
111 |
$av3->lib_opac(''); |
86 |
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' ); |
Lines 225-262
subtest 'search_by_*_field + find_by_koha_field + get_description' => sub {
Link Here
|
225 |
); |
251 |
); |
226 |
}; |
252 |
}; |
227 |
}; |
253 |
}; |
228 |
sub GetAuthValues { |
|
|
229 |
require Test::More; |
230 |
my $dbh = C4::Context->dbh; |
231 |
my ($self, $authcat) = @_; |
232 |
my $query = qq{ SELECT * FROM authorised_values WHERE category=? order by lib }; |
233 |
my $sth = $dbh->prepare($query); |
234 |
$sth->execute($authcat); |
235 |
my $AuthValue = 0; |
236 |
if ($sth->rows > 0) { |
237 |
$AuthValue = 1; |
238 |
} |
239 |
return $AuthValue; |
240 |
}; |
241 |
my $AuthValues = GetAuthValues('av_for_testing'); |
242 |
is ( $AuthValues,0, 'Does not exist in the database: Test successful'); |
243 |
|
244 |
sub GetDistinctCat { |
245 |
require Test::More; |
246 |
my $dbh = C4::Context->dbh; |
247 |
my ($self, $dbh) = @_; |
248 |
my $sth = $dbh->prepare("select distinct category from authorised_values where category like 'A%' "); |
249 |
$sth->execute; |
250 |
return $sth; |
251 |
my $DistAuth = 0; |
252 |
if ($sth->rows > 0){ |
253 |
$DistAuth = 1; |
254 |
} |
255 |
return $DistAuth; |
256 |
}; |
257 |
my $DistAuth = GetDistinctCat(); |
258 |
is ( $DistAuth, 0, 'Does not exist in the database successful'); |
259 |
|
260 |
|
254 |
|
261 |
|
255 |
|
262 |
|
256 |
|