From c0d25d0a921edfe533f350d2bd9d257498e5c90b Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 25 Apr 2024 16:33:25 +0100 Subject: [PATCH] Bug 35628: Add unit tests for Koha::Ticket addition We add a strings_map method to Koha::Ticket and thus need to have corresponding unit tests. Signed-off-by: Marcel de Rooy --- t/db_dependent/Koha/Ticket.t | 41 +++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Ticket.t b/t/db_dependent/Koha/Ticket.t index e5dfb7af907..51c862ff772 100755 --- a/t/db_dependent/Koha/Ticket.t +++ b/t/db_dependent/Koha/Ticket.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 7; use t::lib::TestBuilder; use t::lib::Mocks; @@ -227,3 +227,42 @@ subtest 'store() tests' => sub { $schema->storage->txn_rollback; }; }; + +subtest 'strings_map() tests' => sub { + plan tests => 8; + + $schema->storage->txn_begin; + + my $status_av = $builder->build_object( + { + class => 'Koha::AuthorisedValues', + value => { + authorised_value => 'TEST', + category => 'TICKET_STATUS', + lib => 'internal description', + lib_opac => 'public description', + } + } + ); + + my $ticket = $builder->build_object( + { + class => 'Koha::Tickets', + value => { status => 'TEST' } + } + ); + + my $strings = $ticket->strings_map(); + ok( exists $strings->{status}, "'status' entry exists" ); + is( $strings->{status}->{str}, $status_av->lib, "'str' set to av->lib" ); + is( $strings->{status}->{type}, 'av', "'type' is 'av'" ); + is( $strings->{status}->{category}, 'TICKET_STATUS', "'category' exists and set to 'TICKET_STATUS'" ); + + $strings = $ticket->strings_map( { public => 1 } ); + ok( exists $strings->{status}, "'status' entry exists when called in public" ); + is( $strings->{status}->{str}, $status_av->lib_opac, "'str' set to av->lib_opac when called in public" ); + is( $strings->{status}->{type}, 'av', "'type' is 'av'" ); + is( $strings->{status}->{category}, 'TICKET_STATUS', "'category' exists and set to 'TICKET_STATUS'" ); + + $schema->storage->txn_rollback; +}; -- 2.44.0