View | Details | Raw Unified | Return to bug 35681
Collapse All | Expand All

(-)a/Koha/Installer/Output.pm (+98 lines)
Line 0 Link Here
1
package Koha::Installer::Output;
2
3
# Copyright 2024 Koha Development Team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Exporter        qw(import);
23
use Term::ANSIColor qw(:constants);
24
25
our @EXPORT_OK = qw(say_warning say_failure say_success say_info);
26
27
=head1 NAME
28
29
Koha::Installer::Output - Module to provide colored output for Koha installer
30
31
=head1 SYNOPSIS
32
33
  use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
34
35
  # Output messages with appropriate colors
36
  say_warning($fh, "This is a warning message");
37
  say_failure($fh, "This is a failure message");
38
  say_success($fh, "This is a success message");
39
  say_info($fh, "This is an info message");
40
41
=head1 DESCRIPTION
42
43
This module provides methods to output messages with appropriate colors for different types of messages:
44
warnings, failures, successes, and informational messages.
45
46
=head1 EXPORTS
47
48
The following functions can be exported upon request:
49
50
=over 4
51
52
=item * say_warning($fh, $msg)
53
54
Output a warning message in yellow.
55
56
=item * say_failure($fh, $msg)
57
58
Output a failure message in red.
59
60
=item * say_success($fh, $msg)
61
62
Output a success message in green.
63
64
=item * say_info($fh, $msg)
65
66
Output an informational message in blue.
67
68
=back
69
70
=cut
71
72
sub say_warning {
73
    my ( $fh, $msg ) = @_;
74
    say $fh YELLOW, "$msg", RESET;
75
}
76
77
sub say_failure {
78
    my ( $fh, $msg ) = @_;
79
    say $fh RED, "$msg", RESET;
80
}
81
82
sub say_success {
83
    my ( $fh, $msg ) = @_;
84
    say $fh GREEN, "$msg", RESET;
85
}
86
87
sub say_info {
88
    my ( $fh, $msg ) = @_;
89
    say $fh BLUE, "$msg", RESET;
90
}
91
92
=head1 AUTHORS
93
94
Martin Renvoize <martin.renvoize@ptfs-europe.com>
95
96
=cut
97
98
1;
(-)a/t/Koha/Installer/Output.t (-1 / +55 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 4;
21
22
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
23
24
# Set up a temporary file for testing output
25
my $temp_file = "test_output.log";
26
open my $fh, '>', $temp_file or die "Cannot open $temp_file: $!";
27
28
# Redirect output to the temporary file
29
my $old_fh = select $fh;
30
31
# Test the output functions
32
say_warning( $fh, "Testing warning message" );
33
say_failure( $fh, "Testing failure message" );
34
say_success( $fh, "Testing success message" );
35
say_info( $fh, "Testing info message" );
36
37
# Restore the previous output filehandle
38
select $old_fh;
39
40
# Close the temporary file
41
close $fh;
42
43
# Read the contents of the temporary file for testing
44
open my $test_fh, '<', $temp_file or die "Cannot open $temp_file: $!";
45
my @lines = <$test_fh>;
46
close $test_fh;
47
48
# Test the output content
49
like( $lines[0], qr/\e\[\d+mTesting warning message\e\[0m/, "Warning message output with ANSI color code" );
50
like( $lines[1], qr/\e\[\d+mTesting failure message\e\[0m/, "Failure message output with ANSI color code" );
51
like( $lines[2], qr/\e\[\d+mTesting success message\e\[0m/, "Success message output with ANSI color code" );
52
like( $lines[3], qr/\e\[\d+mTesting info message\e\[0m/,    "Info message output with ANSI color code" );
53
54
# Remove the temporary file
55
unlink $temp_file;

Return to bug 35681