From 64e9a1df2a7767d26ec9b69e29dd5da85a4d4d4c Mon Sep 17 00:00:00 2001 From: Nigel Horne Date: Thu, 21 Nov 2024 21:13:14 -0500 Subject: [PATCH] Added t/display.t --- Changes | 2 +- MANIFEST | 1 + Makefile.PL | 2 ++ t/display.t | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 t/display.t diff --git a/Changes b/Changes index 92a3188..8f03068 100644 --- a/Changes +++ b/Changes @@ -2,7 +2,7 @@ Revision history for Geo-Coder-Free 0.38 Latest as_string return code from VWF - Added t/config.t + Added t/config.t, t/utils.t and t/display.t 0.37 Wed Oct 23 10:09:54 EDT 2024 Allow new() to take HASH ref diff --git a/MANIFEST b/MANIFEST index 0d316c6..46860d1 100644 --- a/MANIFEST +++ b/MANIFEST @@ -44,6 +44,7 @@ t/cities.t t/comment-spelling.t t/config.t t/critic.t +t/display.t t/dr5hn.t t/eof.t t/eol.t diff --git a/Makefile.PL b/Makefile.PL index fd3b3c7..8d3a4b1 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -329,6 +329,8 @@ WriteMakefile( PREREQ_PM => { 'Carp' => 0, # 'BerkeleyDB' => 0, + 'Cwd' => 0, + 'Data::Validate::URI' => 0, 'DB_File' => 0, 'DBI' => 0, 'Digest::MD5' => 0, diff --git a/t/display.t b/t/display.t new file mode 100644 index 0000000..0e7db4b --- /dev/null +++ b/t/display.t @@ -0,0 +1,57 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Cwd; +use Test::Most tests => 8; +use Data::Validate::URI; + +BEGIN { use_ok('Geo::Coder::Free::Display') } + +# Simulate environment variables +local %ENV = ( + HTTP_REFERER => 'http://example.com', + REMOTE_ADDR => '127.0.0.1', + CONFIG_DIR => undef, + DOCUMENT_ROOT => '/var/www', + HOME => '/home/user', + GATEWAY_INTERFACE => 'CGI/1.1', + REQUEST_METHOD => 'GET', + QUERY_STRING => 'foo=bar&baz=qux', + SCRIPT_URI => 'http://localhost', +); + +# Create an instance of the module +my $display = Geo::Coder::Free::Display->new( + config => { root_dir => Cwd::getcwd() } +); + +# Test object creation +isa_ok($display, 'Geo::Coder::Free::Display', 'Object creation'); + +# Test retrieving the template path +ok($display->get_template_path({ modulepath => 'Geo/Coder/Free/Display/index' }), 'Template path retrieval'); + +# Test setting cookies +$display->set_cookie({ test_cookie => 'cookie_value' }); +is_deeply( + $display->{_cookies}, + { test_cookie => 'cookie_value' }, + 'Set cookie successfully' +); + +# Test generating HTTP headers +like($display->http(), qr/Content-Type: text\/html; charset=UTF-8/, 'HTTP headers generation'); + +like($display->html(), qr/as_string(), qr/html>/i, 'as_string'); + +# Simulate HTML generation (assuming template exists) +sub mock_template { + return "Test Page"; +} +{ + no warnings 'redefine'; + *Geo::Coder::Free::Display::html = \&mock_template; +} +like($display->as_string({}), qr/Test Page/, 'HTML generation overriding html()');