From dc2f137d02bf0f67430e9640423e801d000e9982 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 27 Mar 2018 15:56:41 -0300 Subject: [PATCH] Bug 19223: Unit tests for output and output_html methods Signed-off-by: Katrin Fischer Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- t/Koha/Plugin/Test.pm | 10 ++++++++++ t/db_dependent/Plugins.t | 30 +++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/t/Koha/Plugin/Test.pm b/t/Koha/Plugin/Test.pm index 636554d1de..0f51f73a6b 100644 --- a/t/Koha/Plugin/Test.pm +++ b/t/Koha/Plugin/Test.pm @@ -72,3 +72,13 @@ sub uninstall { my ( $self, $args ) = @_; return "Koha::Plugin::Test::uninstall"; } + +sub test_output { + my ( $self ) = @_; + $self->output( '¡Hola output!', 'json' ); +} + +sub test_output_html { + my ( $self ) = @_; + $self->output_html( '¡Hola output_html!' ); +} diff --git a/t/db_dependent/Plugins.t b/t/db_dependent/Plugins.t index 4fa327f47d..106eb9148e 100755 --- a/t/db_dependent/Plugins.t +++ b/t/db_dependent/Plugins.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 32; +use Test::More tests => 33; use CGI; use File::Basename; use File::Spec; @@ -121,3 +121,31 @@ for my $pass ( 1 .. 2 ) { is( @$info, 0, "Table $table does no longer exist" ); ok( !( -f $full_pm_path ), "Koha::Plugins::Handler::delete works correctly." ); } + +subtest 'output and output_html tests' => sub { + + plan tests => 6; + + # Trick stdout to be able to test + local *STDOUT; + my $stdout; + open STDOUT, '>', \$stdout; + + my $plugin = Koha::Plugin::Test->new({ enable_plugins => 1, cgi => CGI->new }); + $plugin->test_output; + + like($stdout, qr/Cache-control: no-cache/, 'force_no_caching sets Cache-control as desired'); + like($stdout, qr{Content-Type: application/json; charset=UTF-8}, 'Correct content-type'); + like($stdout, qr{¡Hola output!}, 'Correct data'); + + # reset the stdout buffer + $stdout = ''; + close STDOUT; + open STDOUT, '>', \$stdout; + + $plugin->test_output_html; + + like($stdout, qr/Cache-control: no-cache/, 'force_no_caching sets Cache-control as desired'); + like($stdout, qr{Content-Type: text/html; charset=UTF-8}, 'Correct content-type'); + like($stdout, qr{¡Hola output_html!}, 'Correct data'); +}; -- 2.39.5