From dba514bd4f5a26b730f5513099c234714fc5f504 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 12 Sep 2024 17:35:15 +0000 Subject: [PATCH] Bug 37398: Add a unit test --- t/db_dependent/Koha/UI/Form/Builder/Item.t | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/UI/Form/Builder/Item.t b/t/db_dependent/Koha/UI/Form/Builder/Item.t index de82c7741cf..4e2881e0ca3 100755 --- a/t/db_dependent/Koha/UI/Form/Builder/Item.t +++ b/t/db_dependent/Koha/UI/Form/Builder/Item.t @@ -16,7 +16,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 9; +use Test::More tests => 10; use Test::MockModule; use Data::Dumper qw( Dumper ); use utf8; @@ -238,6 +238,33 @@ subtest 'default_branches_empty' => sub { is( $subfield->{marc_value}->{values}->[0], "", 'empty option for branches if default_branches_empty passed' ); }; +subtest 'kohafields_to_add_datepicker' => sub { + plan tests => 5; + + my $biblio = + $builder->build_sample_biblio( { value => { frameworkcode => '' } } ); + my $subfields = + Koha::UI::Form::Builder::Item->new( + { biblionumber => $biblio->biblionumber } )->edit_form; + + my @itemfield_test_cases = ( + { kohafield => 'items.dateaccessioned', expected_type => 'date' }, + { kohafield => 'items.replacementpricedate', expected_type => 'date' }, + { kohafield => 'items.datelastborrowed', expected_type => 'date' }, + { kohafield => 'items.onloan', expected_type => 'date' }, + { kohafield => 'items.datelastseen', expected_type => 'datetime' }, + ); + + foreach my $itemfield_test_case (@itemfield_test_cases) { + my ( $subfield ) = grep { $_->{kohafield} eq $itemfield_test_case->{kohafield} } @$subfields; + if ( $subfield ) { + is( $subfield->{datetype}, $itemfield_test_case->{expected_type}, "Correct datetype for $itemfield_test_case->{kohafield}" ); + } else { + ok( 0, "Subfield for $itemfield_test_case->{kohafield} not found" ); + } + } +}; + subtest 'kohafields_to_ignore' => sub { plan tests => 2; -- 2.39.2