Line 0
Link Here
|
|
|
1 |
use Modern::Perl; |
2 |
|
3 |
use Test::More tests => 5; |
4 |
|
5 |
use C4::Context; |
6 |
use C4::Branch; |
7 |
use Koha::Template::Plugin::Branches; |
8 |
|
9 |
my $dbh = C4::Context->dbh; |
10 |
$dbh->{AutoCommit} = 0; |
11 |
$dbh->{RaiseError} = 1; |
12 |
|
13 |
for my $i ( 1 .. 5 ) { |
14 |
C4::Branch::ModBranch( |
15 |
{ |
16 |
branchcode => "test_br_$i", |
17 |
branchname => "test_br_$i", |
18 |
add => 1, |
19 |
} |
20 |
); |
21 |
|
22 |
} |
23 |
|
24 |
my $branches = Koha::Template::Plugin::Branches->new->all; |
25 |
my $test_branches = [ grep { $_->{branchcode} =~ m|^test_br_| } @$branches ]; |
26 |
is( scalar( @$test_branches ), 5, 'Plugin Branches should return the branches' ); |
27 |
my $selected_branches = [ grep { $_->{selected} } @$branches ]; |
28 |
is( scalar( @$selected_branches ), 0, 'Plugin Branches should not select a branch if not needed' ); |
29 |
|
30 |
$branches = Koha::Template::Plugin::Branches->new->all({selected => 'test_br_3'}); |
31 |
$test_branches = [ grep { $_->{branchcode} =~ m|^test_br_| } @$branches ]; |
32 |
is( scalar( @$test_branches ), 5, 'Plugin Branches should return the branches if selected passed' ); |
33 |
$selected_branches = [ grep { $_->{selected} } @$branches ]; |
34 |
is( scalar( @$selected_branches ), 1, 'Plugin Branches should return only 1 selected if passed' ); |
35 |
is( $selected_branches->[0]->{branchcode}, 'test_br_3', 'Plugin Branches should select the good one' ); |