| 1 | use strict; |
|---|
| 2 | use OpenGuides; |
|---|
| 3 | use OpenGuides::Test; |
|---|
| 4 | use Test::More; |
|---|
| 5 | use Wiki::Toolkit::Setup::SQLite; |
|---|
| 6 | |
|---|
| 7 | eval { require DBD::SQLite; }; |
|---|
| 8 | if ( $@ ) { |
|---|
| 9 | plan skip_all => "DBD::SQLite not installed - no database to test with"; |
|---|
| 10 | exit 0; |
|---|
| 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 => 12; |
|---|
| 20 | |
|---|
| 21 | # NB These tests don't actually test the placement - but they do test that |
|---|
| 22 | # we get at least one navbar where appropriate. Better tests would be better. |
|---|
| 23 | |
|---|
| 24 | my ( $config, $guide, $wiki, $cookie, $output ); |
|---|
| 25 | |
|---|
| 26 | # Clear out the database from any previous runs. |
|---|
| 27 | unlink "t/node.db"; |
|---|
| 28 | unlink <t/indexes/*>; |
|---|
| 29 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 30 | |
|---|
| 31 | # Make a guide. |
|---|
| 32 | $config = OpenGuides::Test->make_basic_config; |
|---|
| 33 | $guide = OpenGuides->new( config => $config ); |
|---|
| 34 | |
|---|
| 35 | # Write a node. |
|---|
| 36 | OpenGuides::Test->write_data( |
|---|
| 37 | guide => $guide, |
|---|
| 38 | node => "Red Lion", |
|---|
| 39 | ); |
|---|
| 40 | |
|---|
| 41 | # Make sure navbar shows up on node display. |
|---|
| 42 | $output = $guide->display_node( |
|---|
| 43 | id => "Red Lion", |
|---|
| 44 | return_output => 1, |
|---|
| 45 | ); |
|---|
| 46 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 47 | Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, |
|---|
| 48 | "navbar included on node display" ); |
|---|
| 49 | |
|---|
| 50 | $config->content_above_navbar_in_html( 0 ); |
|---|
| 51 | $output = $guide->display_node( |
|---|
| 52 | id => "Red Lion", |
|---|
| 53 | return_output => 1, |
|---|
| 54 | ); |
|---|
| 55 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 56 | Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, |
|---|
| 57 | "...ditto if content_above_navbar_in_html set to 0" ); |
|---|
| 58 | |
|---|
| 59 | $config->content_above_navbar_in_html( 1 ); |
|---|
| 60 | $output = $guide->display_node( |
|---|
| 61 | id => "Red Lion", |
|---|
| 62 | return_output => 1, |
|---|
| 63 | ); |
|---|
| 64 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 65 | Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, |
|---|
| 66 | "...ditto if content_above_navbar_in_html set to 1" ); |
|---|
| 67 | |
|---|
| 68 | # And on home node, if it's switched on. |
|---|
| 69 | $config = OpenGuides::Test->make_basic_config; # get a fresh config |
|---|
| 70 | $guide = OpenGuides->new( config => $config ); # make sure the guide sees it |
|---|
| 71 | $config->navbar_on_home_page( 1 ); |
|---|
| 72 | $output = $guide->display_node( |
|---|
| 73 | id => $config->home_name, |
|---|
| 74 | return_output => 1, |
|---|
| 75 | ); |
|---|
| 76 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 77 | Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, |
|---|
| 78 | "navbar included on home node when navbar_on_home_page switched on" ); |
|---|
| 79 | |
|---|
| 80 | $config->content_above_navbar_in_html( 0 ); |
|---|
| 81 | $output = $guide->display_node( |
|---|
| 82 | id => $config->home_name, |
|---|
| 83 | return_output => 1, |
|---|
| 84 | ); |
|---|
| 85 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 86 | Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, |
|---|
| 87 | "...ditto if content_above_navbar_in_html set to 0" ); |
|---|
| 88 | |
|---|
| 89 | $config->content_above_navbar_in_html( 1 ); |
|---|
| 90 | $output = $guide->display_node( |
|---|
| 91 | id => $config->home_name, |
|---|
| 92 | return_output => 1, |
|---|
| 93 | ); |
|---|
| 94 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 95 | Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, |
|---|
| 96 | "...ditto if content_above_navbar_in_html set to 1" ); |
|---|
| 97 | |
|---|
| 98 | # But not on home node, if it's switched off. |
|---|
| 99 | $config = OpenGuides::Test->make_basic_config; # get a fresh config |
|---|
| 100 | $guide = OpenGuides->new( config => $config ); # make sure the guide sees it |
|---|
| 101 | $config->navbar_on_home_page( 0 ); |
|---|
| 102 | $output = $guide->display_node( |
|---|
| 103 | id => $config->home_name, |
|---|
| 104 | return_output => 1, |
|---|
| 105 | ); |
|---|
| 106 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 107 | Test::HTML::Content::no_tag( $output, "div", { id => "navbar" }, |
|---|
| 108 | "navbar excluded from home node when navbar_on_home_page switched off" ); |
|---|
| 109 | |
|---|
| 110 | $config->content_above_navbar_in_html( 0 ); |
|---|
| 111 | $output = $guide->display_node( |
|---|
| 112 | id => $config->home_name, |
|---|
| 113 | return_output => 1, |
|---|
| 114 | ); |
|---|
| 115 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 116 | Test::HTML::Content::no_tag( $output, "div", { id => "navbar" }, |
|---|
| 117 | "...ditto if content_above_navbar_in_html set to 0" ); |
|---|
| 118 | |
|---|
| 119 | $config->content_above_navbar_in_html( 1 ); |
|---|
| 120 | $output = $guide->display_node( |
|---|
| 121 | id => $config->home_name, |
|---|
| 122 | return_output => 1, |
|---|
| 123 | ); |
|---|
| 124 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 125 | Test::HTML::Content::no_tag( $output, "div", { id => "navbar" }, |
|---|
| 126 | "...ditto if content_above_navbar_in_html set to 1" ); |
|---|
| 127 | |
|---|
| 128 | # Make sure navbar appears on recent changes. |
|---|
| 129 | $config = OpenGuides::Test->make_basic_config; # get a fresh config |
|---|
| 130 | $guide = OpenGuides->new( config => $config ); # make sure the guide sees it |
|---|
| 131 | $output = $guide->display_recent_changes( |
|---|
| 132 | return_output => 1, |
|---|
| 133 | ); |
|---|
| 134 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 135 | Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, |
|---|
| 136 | "navbar appears on recent changes" ); |
|---|
| 137 | |
|---|
| 138 | $config->content_above_navbar_in_html( 0 ); |
|---|
| 139 | $output = $guide->display_recent_changes( |
|---|
| 140 | return_output => 1, |
|---|
| 141 | ); |
|---|
| 142 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 143 | Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, |
|---|
| 144 | "...ditto if content_above_navbar_in_html set to 0" ); |
|---|
| 145 | |
|---|
| 146 | $config->content_above_navbar_in_html( 1 ); |
|---|
| 147 | $output = $guide->display_recent_changes( |
|---|
| 148 | return_output => 1, |
|---|
| 149 | ); |
|---|
| 150 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 151 | Test::HTML::Content::tag_ok( $output, "div", { id => "navbar" }, |
|---|
| 152 | "...ditto if content_above_navbar_in_html set to 1" ); |
|---|