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