Bugzilla – Attachment 172362 Details for
Bug 38043
KohaTimes filter is missing tests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38043: Add unit tests for KohaTimes TT filter
Bug-38043-Add-unit-tests-for-KohaTimes-TT-filter.patch (text/plain), 2.62 KB, created by
CJ Lynce
on 2024-10-03 15:24:34 UTC
(
hide
)
Description:
Bug 38043: Add unit tests for KohaTimes TT filter
Filename:
MIME Type:
Creator:
CJ Lynce
Created:
2024-10-03 15:24:34 UTC
Size:
2.62 KB
patch
obsolete
>From 9de435772fab9c0180ddf7573efb9164595a52e3 Mon Sep 17 00:00:00 2001 >From: CJ Lynce <cj.lynce@westlakelibrary.org> >Date: Thu, 3 Oct 2024 14:24:31 +0000 >Subject: [PATCH] Bug 38043: Add unit tests for KohaTimes TT filter > >This adds units tests for the new KohaTimes TT filter. >This also corrects a minor issue with a wrong comparitor operation in > KohaTimes.pm causing a WARN to be thrown. > >To test >1. Apply patch >2. prove t/db_dependent/Template/Plugin/KohaTimes.t >3. Verify 5 Tests PASS >--- > Koha/Template/Plugin/KohaTimes.pm | 2 +- > t/db_dependent/Template/Plugin/KohaTimes.t | 38 ++++++++++++++++++++++ > 2 files changed, 39 insertions(+), 1 deletion(-) > create mode 100755 t/db_dependent/Template/Plugin/KohaTimes.t > >diff --git a/Koha/Template/Plugin/KohaTimes.pm b/Koha/Template/Plugin/KohaTimes.pm >index c65c68eaf6..3e383e327f 100644 >--- a/Koha/Template/Plugin/KohaTimes.pm >+++ b/Koha/Template/Plugin/KohaTimes.pm >@@ -26,7 +26,7 @@ sub filter { > return "" unless $text; > > my ( $hours, $minutes, $seconds ) = split( ':', $text ); >- if ( C4::Context->preference('TimeFormat') == "12hr" ) { >+ if ( C4::Context->preference('TimeFormat') eq "12hr" ) { > my $ampm = ( $hours >= 12 ) ? 'pm' : 'am'; > $hours = ( $hours == 0 ) ? "12" : $hours; > $hours = ( $hours > 12 ) ? ( $hours - 12 ) : $hours; >diff --git a/t/db_dependent/Template/Plugin/KohaTimes.t b/t/db_dependent/Template/Plugin/KohaTimes.t >new file mode 100755 >index 0000000000..4a35f018f8 >--- /dev/null >+++ b/t/db_dependent/Template/Plugin/KohaTimes.t >@@ -0,0 +1,38 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use C4::Context; >+ >+use Test::MockModule; >+use Test::More tests => 5; >+use t::lib::Mocks; >+ >+BEGIN { >+ use_ok('Koha::Template::Plugin::KohaTimes'); >+} >+ >+my $module_context = Test::MockModule->new('C4::Context'); >+ >+my $test_time = "21:45:32"; >+my $test_midnight = "00:00:00"; >+ >+my $context = C4::Context->new(); >+ >+my $filter = Koha::Template::Plugin::KohaTimes->new(); >+ok( $filter, "new()" ); >+ >+t::lib::Mocks::mock_preference( "TimeFormat", '24hr' ); >+$context->clear_syspref_cache(); >+ >+my $filtered_time = $filter->filter($test_time); >+is( $filtered_time, "21:45", "24-hour conversion" ) or diag("24-hour conversion failed"); >+ >+t::lib::Mocks::mock_preference( "TimeFormat", '12hr' ); >+$context->clear_syspref_cache(); >+ >+$filtered_time = $filter->filter($test_time); >+is( $filtered_time, "09:45 pm", "12-hour conversion" ) or diag("12-hour conversion failed"); >+ >+$filtered_time = $filter->filter($test_midnight); >+is( $filtered_time, "12:00 am", "12-hour midnight/AM conversion" ) or diag("12-hour midnight/AM conversion failed"); >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 38043
:
172362
|
172387
|
172497