From 8fcd160e8644fc31bd57fb089d9ba45b9cddf21e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 Feb 2016 15:20:18 +0000 Subject: [PATCH] Bug 15758: Koha::Libraries - Add tests for the Branches TT plugin --- t/db_dependent/Koha_template_plugin_Branches.t | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha_template_plugin_Branches.t b/t/db_dependent/Koha_template_plugin_Branches.t index af055ad..2241c3a 100644 --- a/t/db_dependent/Koha_template_plugin_Branches.t +++ b/t/db_dependent/Koha_template_plugin_Branches.t @@ -18,7 +18,7 @@ use Modern::Perl; -use Test::More tests => 7; +use Test::More tests => 14; use C4::Context; use Koha::Database; @@ -34,6 +34,15 @@ $schema->storage->txn_begin; my $builder = t::lib::TestBuilder->new; my $library = $builder->build({ source => 'Branch', + value => { + branchcode => 'MYLIBRARY', + } +}); +my $another_library = $builder->build({ + source => 'Branch', + value => { + branchcode => 'ANOTHERLIB', + } }); my $plugin = Koha::Template::Plugin::Branches->new(); @@ -55,3 +64,18 @@ C4::Context->_new_userenv('DUMMY_SESSION_ID'); C4::Context->set_userenv(123, 'userid', 'usercnum', 'First name', 'Surname', 'MYLIBRARY', 'My Library', 0); $library = $plugin->GetLoggedInBranchcode(); is($library, 'MYLIBRARY', 'GetLoggedInBranchcode() returns active library'); + +C4::Context->set_preference( 'IndependentBranches', 0 ); +my $libraries = $plugin->all(); +ok( scalar(@$libraries) > 1, 'If IndependentBranches is not set, all libraries should be returned' ); +is( grep ( { $_->{branchcode} eq 'MYLIBRARY' and $_->{selected} == 1 } @$libraries ), 1, 'Without selected parameter, my library should be preselected' ); +is( grep ( { $_->{branchcode} eq 'ANOTHERLIB' and not exists $_->{selected} } @$libraries ), 1, 'Without selected parameter, other library should not be preselected' ); +$libraries = $plugin->all( { selected => 'ANOTHERLIB' } ); +is( grep ( { $_->{branchcode} eq 'MYLIBRARY' and not exists $_->{selected} } @$libraries ), 1, 'With selected parameter, my library should not be preselected' ); +is( grep ( { $_->{branchcode} eq 'ANOTHERLIB' and $_->{selected} == 1 } @$libraries ), 1, 'With selected parameter, other library should be preselected' ); + +C4::Context->set_preference( 'IndependentBranches', 1 ); +$libraries = $plugin->all(); +is( scalar(@$libraries), 1, 'If IndependentBranches is set, only 1 library should be returned' ); +$libraries = $plugin->all( { unfiltered => 1 } ); +ok( scalar(@$libraries) > 1, 'If IndependentBranches is set, all libraries should be returned if the unfiltered flag is set' ); -- 2.1.0