@@ -, +, @@ --- t/db_dependent/Template/Plugin/Branches.t | 35 +++++++++++++++++++++++++++++ t/db_dependent/Template/Plugin/Categories.t | 23 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 t/db_dependent/Template/Plugin/Branches.t create mode 100644 t/db_dependent/Template/Plugin/Categories.t --- a/t/db_dependent/Template/Plugin/Branches.t +++ a/t/db_dependent/Template/Plugin/Branches.t @@ -0,0 +1,35 @@ +use Modern::Perl; + +use Test::More tests => 5; + +use C4::Context; +use C4::Branch; +use Koha::Template::Plugin::Branches; + +my $dbh = C4::Context->dbh; +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +for my $i ( 1 .. 5 ) { + C4::Branch::ModBranch( +{ + branchcode => "test_br_$i", + branchname => "test_br_$i", + add => 1, +} + ); + +} + +my $branches = Koha::Template::Plugin::Branches->new->all; +my $test_branches = [ grep { $_->{branchcode} =~ m|^test_br_| } @$branches ]; +is( scalar( @$test_branches ), 5, 'Plugin Branches should return the branches' ); +my $selected_branches = [ grep { $_->{selected} } @$branches ]; +is( scalar( @$selected_branches ), 0, 'Plugin Branches should not select a branch if not needed' ); + +$branches = Koha::Template::Plugin::Branches->new->all({selected => 'test_br_3'}); +$test_branches = [ grep { $_->{branchcode} =~ m|^test_br_| } @$branches ]; +is( scalar( @$test_branches ), 5, 'Plugin Branches should return the branches if selected passed' ); +$selected_branches = [ grep { $_->{selected} } @$branches ]; +is( scalar( @$selected_branches ), 1, 'Plugin Branches should return only 1 selected if passed' ); +is( $selected_branches->[0]->{branchcode}, 'test_br_3', 'Plugin Branches should select the good one' ); --- a/t/db_dependent/Template/Plugin/Categories.t +++ a/t/db_dependent/Template/Plugin/Categories.t @@ -0,0 +1,23 @@ +use Modern::Perl; + +use Test::More tests => 5; + +use C4::Context; +use C4::Branch; +use Koha::Template::Plugin::Categories; + +my $dbh = C4::Context->dbh; +$dbh->{AutoCommit} = 0; +$dbh->{RaiseError} = 1; + +my @categories = Koha::Template::Plugin::Categories->new->all; +isnt( scalar( @categories ), 0, 'Plugin Categories should return categories' ); +my $selected_categories = [ grep { $_->{selected} } @categories ]; +is( scalar( @$selected_categories ), 0, 'Plugin Categories should not select one if not given' ); + +my $category = $categories[-1]; +@categories = Koha::Template::Plugin::Categories->new->all({selected => $category->{categorycode}}); +isnt( scalar( @categories ), 0, 'Plugin Categories should return categories if selected needed' ); +$selected_categories = [ grep { $_->{selected} } @categories ]; +is( scalar( @$selected_categories ), 1, 'Plugin Categories should select only 1 category' ); +is( $selected_categories->[0]->{categorycode}, $category->{categorycode}, 'Plugin Categories should select the good one' ); --