4 use Test::More; # tests => 25;
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 ok( $av1->id(), 'AV 1 is inserted' );
48 ok( $av2->id(), 'AV 2 is inserted' );
49 ok( $av3->id(), 'AV 3 is inserted' );
51 is( $av3->opac_description, 'opac display value 3', 'Got correction opac description if lib_opac is set' );
53 is( $av3->opac_description, 'display value 3', 'Got correction opac description if lib_opac is *not* set' );
55 my @authorised_values =
56 Koha::AuthorisedValues->new()->search( { category => 'av_for_testing' } );
57 is( @authorised_values, 3, "Get correct number of values" );
59 my $branches_rs = Koha::Database->new()->schema()->resultset('Branch')->search();
60 my $branch1 = $branches_rs->next();
61 my $branchcode1 = $branch1->branchcode();
62 my $branch2 = $branches_rs->next();
63 my $branchcode2 = $branch2->branchcode();
65 $av1->add_branch_limitation( $branchcode1 );
67 @authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode1 } );
68 is( @authorised_values, 3, "Search including value with a branch limit ( branch can use the limited value ) gives correct number of results" );
70 @authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } );
71 is( @authorised_values, 2, "Search including value with a branch limit ( branch *cannot* use the limited value ) gives correct number of results" );
73 $av1->del_branch_limitation( $branchcode1 );
74 @authorised_values = Koha::AuthorisedValues->new()->search( { category => 'av_for_testing', branchcode => $branchcode2 } );
75 is( @authorised_values, 3, "Branch limitation deleted successfully" );
77 $av1->add_branch_limitation( $branchcode1 );
78 $av1->branch_limitations( [ $branchcode1, $branchcode2 ] );
80 my $limits = $av1->branch_limitations;
81 is( @$limits, 2, 'branch_limitations functions correctly both as setter and getter' );