From 8a6dab79ea5361fa7a7beb60a1306ab65b687305 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Tue, 28 Mar 2023 22:52:08 -1000 Subject: [PATCH] Bug 32127: Add unit test Run prove t/db_dependent/Template/Plugin/Categories.t --- t/db_dependent/Template/Plugin/Categories.t | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/t/db_dependent/Template/Plugin/Categories.t b/t/db_dependent/Template/Plugin/Categories.t index c409ccf57f..04580d7912 100755 --- a/t/db_dependent/Template/Plugin/Categories.t +++ b/t/db_dependent/Template/Plugin/Categories.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 7; use t::lib::Mocks; use t::lib::TestBuilder; @@ -34,14 +34,27 @@ my $builder = t::lib::TestBuilder->new; my $nb_categories = Koha::Patron::Categories->count; # Create sample categories -my $category_1 = $builder->build_object( { class => 'Koha::Patron::Categories' } ); +my $category_1 = $builder->build_object( { class => 'Koha::Patron::Categories', value => { description => 'ZZZZZZ' } } ); my @categories = Koha::Template::Plugin::Categories->new->all->as_list; is( scalar(@categories), 1 + $nb_categories, '->all returns all defined categories' ); -my $category_2 = $builder->build_object( { class => 'Koha::Patron::Categories' } ); +my $category_2 = $builder->build_object( { class => 'Koha::Patron::Categories', value => { description => 'AAAAAA' } } ); @categories = Koha::Template::Plugin::Categories->new->all->as_list; is( scalar(@categories), 2 + $nb_categories, '->all returns all defined categories' ); +my $category_1_pos = 0; +my $category_2_pos = 0; +for ( my $i = 0 ; $i < scalar(@categories) ; $i++ ) { + my $idescription = $categories[$i]->description // ''; + if ( $idescription eq $category_1->description ) { + $category_1_pos = $i; + } + if ( $idescription eq $category_2->description ) { + $category_2_pos = $i; + } +} +ok( $category_1_pos > $category_2_pos, 'Categories are sorted by description' ); + is( Koha::Template::Plugin::Categories->GetName( $category_1->categorycode ), -- 2.39.0