root/branches/new-install-process/t/49_custom_header.t

Revision 1005, 1.7 kB (checked in by dom, 22 months ago)

Better fix for previous issue, to take account of distribution.

Line 
1use strict;
2use Cwd;
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More;
6
7eval { require DBD::SQLite; };
8if ( $@ ) {
9    my ($error) = $@ =~ /^(.*?)\n/;
10    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
11}
12
13eval { require Test::HTML::Content; };
14if ( $@ ) {
15    plan skip_all => "Test::HTML::Content not installed";
16    exit 0;
17}
18
19plan tests => 2;
20
21my $config = OpenGuides::Test->make_basic_config;
22$config->custom_template_path( cwd . "/t/templates/tmp/" );
23my $guide = OpenGuides->new( config => $config );
24my $wiki = $guide->wiki;
25
26# Clear out the database from any previous runs.
27foreach my $del_node ( $wiki->list_all_nodes ) {
28    print "# Deleting node $del_node\n";
29    $wiki->delete_node( $del_node ) or die "Can't delete $del_node";
30}
31
32# Make sure the tmp directory exists
33eval {
34    mkdir cwd . "/t/templates/tmp";
35};
36
37# Make sure we don't die if there's no custom header template.
38eval {
39    unlink cwd . "/t/templates/tmp/custom_header.tt";
40};
41eval {
42    $guide->display_node( id => $config->home_name, return_output => 1 );
43};
44ok( !$@, "node display OK if no custom header template" );
45
46# Write a custom template to add stuff to header.
47open( FILE, ">", cwd . "/t/templates/tmp/custom_header.tt" )
48  or die $!;
49print FILE <<EOF;
50<meta name="foo" content="bar" />
51EOF
52close FILE or die $!;
53
54# Check that the custom template was picked up.
55my $output = $guide->display_node(
56                                   id            => $config->home_name,
57                                   return_output => 1,
58                                 );
59$output =~ s/^Content-Type.*[\r\n]+//m;
60Test::HTML::Content::tag_ok( $output, "meta", { name => "foo" },
61                             "custom template included in header" );
Note: See TracBrowser for help on using the browser.