Bug 15629: Koha::Libraries - Remove ModBranch
[koha.git] / t / db_dependent / Template / Plugin / Branches.t
1 use Modern::Perl;
2
3 use Test::More tests => 5;
4
5 use C4::Context;
6 use Koha::Library;
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     Koha::Library->new(
15 {
16         branchcode     => "test_br_$i",
17         branchname     => "test_br_$i",
18 }
19     )->store;
20
21 }
22
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' );
28
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' );