3 use Test::More tests => 5;
7 use Koha::Template::Plugin::Branches;
9 my $dbh = C4::Context->dbh;
10 $dbh->{AutoCommit} = 0;
11 $dbh->{RaiseError} = 1;
13 for my $i ( 1 .. 5 ) {
16 branchcode => "test_br_$i",
17 branchname => "test_br_$i",
23 my $branches = Koha::Template::Plugin::Branches->new->all;
24 my $test_branches = [ grep { $_->{branchcode} =~ m|^test_br_| } @$branches ];
25 is( scalar( @$test_branches ), 5, 'Plugin Branches should return the branches' );
26 my $selected_branches = [ grep { $_->{selected} } @$branches ];
27 is( scalar( @$selected_branches ), 0, 'Plugin Branches should not select a branch if not needed' );
29 $branches = Koha::Template::Plugin::Branches->new->all({selected => 'test_br_3'});
30 $test_branches = [ grep { $_->{branchcode} =~ m|^test_br_| } @$branches ];
31 is( scalar( @$test_branches ), 5, 'Plugin Branches should return the branches if selected passed' );
32 $selected_branches = [ grep { $_->{selected} } @$branches ];
33 is( scalar( @$selected_branches ), 1, 'Plugin Branches should return only 1 selected if passed' );
34 is( $selected_branches->[0]->{branchcode}, 'test_br_3', 'Plugin Branches should select the good one' );