4 use Test
::More tests
=> 14;
7 use Koha
::AuthorisedValue
;
8 use Koha
::AuthorisedValues
;
10 my $dbh = C4
::Context
->dbh;
11 $dbh->{AutoCommit
} = 0;
12 $dbh->{RaiseError
} = 1;
14 $dbh->do("DELETE FROM authorised_values");
17 my $av1 = Koha
::AuthorisedValue
->new(
19 category
=> 'av_for_testing',
20 authorised_value
=> 'value 1',
21 lib
=> 'display value 1',
22 lib_opac
=> 'opac display value 1',
23 imageurl
=> 'image1.png',
27 my $av2 = Koha
::AuthorisedValue
->new(
29 category
=> 'av_for_testing',
30 authorised_value
=> 'value 2',
31 lib
=> 'display value 2',
32 lib_opac
=> 'opac display value 2',
33 imageurl
=> 'image2.png',
37 my $av3 = Koha
::AuthorisedValue
->new(
39 category
=> 'av_for_testing',
40 authorised_value
=> 'value 3',
41 lib
=> 'display value 3',
42 lib_opac
=> 'opac display value 3',
43 imageurl
=> 'image2.png',
47 my $av4 = Koha
::AuthorisedValue
->new(
49 category
=> 'aaav_for_testing',
50 authorised_value
=> 'value 4',
51 lib
=> 'display value 4',
52 lib_opac
=> 'opac display value 4',
53 imageurl
=> 'image4.png',
57 ok
( $av1->id(), 'AV 1 is inserted' );
58 ok
( $av2->id(), 'AV 2 is inserted' );
59 ok
( $av3->id(), 'AV 3 is inserted' );
60 ok
( $av4->id(), 'AV 4 is inserted' );
62 is
( $av3->opac_description, 'opac display value 3', 'Got correction opac description if lib_opac is set' );
64 is
( $av3->opac_description, 'display value 3', 'Got correction opac description if lib_opac is *not* set' );
66 my @authorised_values =
67 Koha
::AuthorisedValues
->new()->search( { category
=> 'av_for_testing' } );
68 is
( @authorised_values, 3, "Get correct number of values" );
70 my $branches_rs = Koha
::Database
->new()->schema()->resultset('Branch')->search();
71 my $branch1 = $branches_rs->next();
72 my $branchcode1 = $branch1->branchcode();
73 my $branch2 = $branches_rs->next();
74 my $branchcode2 = $branch2->branchcode();
76 $av1->add_branch_limitation( $branchcode1 );
78 @authorised_values = Koha
::AuthorisedValues
->new()->search( { category
=> 'av_for_testing', branchcode
=> $branchcode1 } );
79 is
( @authorised_values, 3, "Search including value with a branch limit ( branch can use the limited value ) gives correct number of results" );
81 @authorised_values = Koha
::AuthorisedValues
->new()->search( { category
=> 'av_for_testing', branchcode
=> $branchcode2 } );
82 is
( @authorised_values, 2, "Search including value with a branch limit ( branch *cannot* use the limited value ) gives correct number of results" );
84 $av1->del_branch_limitation( $branchcode1 );
85 @authorised_values = Koha
::AuthorisedValues
->new()->search( { category
=> 'av_for_testing', branchcode
=> $branchcode2 } );
86 is
( @authorised_values, 3, "Branch limitation deleted successfully" );
88 $av1->add_branch_limitation( $branchcode1 );
89 $av1->branch_limitations( [ $branchcode1, $branchcode2 ] );
91 my $limits = $av1->branch_limitations;
92 is
( @
$limits, 2, 'branch_limitations functions correctly both as setter and getter' );
94 my @categories = Koha
::AuthorisedValues
->new->categories;
95 is
( @categories, 2, 'There should have 2 categories inserted' );
96 is
( $categories[0], $av4->category, 'The first category should be correct (ordered by category name)' );
97 is
( $categories[1], $av1->category, 'The second category should be correct (ordered by category name)' );