| 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 | sub get_recent_changes { |
|---|
| 20 | my ($guide) = @_; |
|---|
| 21 | |
|---|
| 22 | my $output = $guide->display_recent_changes( return_output => 1 ); |
|---|
| 23 | $output =~ s/^Content-Type.*[\r\n]+//m; |
|---|
| 24 | |
|---|
| 25 | return $output; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | sub get_preferences { |
|---|
| 29 | my ($guide) = @_; |
|---|
| 30 | |
|---|
| 31 | return OpenGuides::Template->output( |
|---|
| 32 | wiki => $guide->wiki, |
|---|
| 33 | config => $guide->config, |
|---|
| 34 | template => "preferences.tt", |
|---|
| 35 | noheaders => 1, |
|---|
| 36 | vars => { |
|---|
| 37 | not_editable => 1, |
|---|
| 38 | show_form => 1 |
|---|
| 39 | }, |
|---|
| 40 | ); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | my %pages = ( |
|---|
| 44 | recent_changes => \&get_recent_changes, |
|---|
| 45 | preferences => \&get_preferences, |
|---|
| 46 | ); |
|---|
| 47 | |
|---|
| 48 | plan tests => 4 * keys %pages; |
|---|
| 49 | |
|---|
| 50 | my ( $config, $guide, $wiki, $output ); |
|---|
| 51 | |
|---|
| 52 | # Clear out the database from any previous runs. |
|---|
| 53 | unlink "t/node.db"; |
|---|
| 54 | unlink <t/indexes/*>; |
|---|
| 55 | Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } ); |
|---|
| 56 | |
|---|
| 57 | while (my ($page, $get_content) = each %pages) { |
|---|
| 58 | |
|---|
| 59 | # Make a guide with common categories and locales enabled. |
|---|
| 60 | $config = OpenGuides::Test->make_basic_config; |
|---|
| 61 | $config->enable_common_categories( 1 ); |
|---|
| 62 | $config->enable_common_locales( 1 ); |
|---|
| 63 | $guide = OpenGuides->new( config => $config ); |
|---|
| 64 | |
|---|
| 65 | # Make sure common categories and locales show up. |
|---|
| 66 | $output = $get_content->($guide); |
|---|
| 67 | |
|---|
| 68 | Test::HTML::Content::tag_ok( $output, "div", { id => "navbar_categories" }, |
|---|
| 69 | "common categories in $page navbar" ); |
|---|
| 70 | Test::HTML::Content::tag_ok( $output, "div", { id => "navbar_locales" }, |
|---|
| 71 | "...common locales too" ); |
|---|
| 72 | |
|---|
| 73 | # Now make a guide with common categories and locales disabled. |
|---|
| 74 | $config = OpenGuides::Test->make_basic_config; |
|---|
| 75 | $guide = OpenGuides->new( config => $config ); |
|---|
| 76 | |
|---|
| 77 | # Make sure common categories/locales are omitted. |
|---|
| 78 | $output = $get_content->($guide); |
|---|
| 79 | |
|---|
| 80 | Test::HTML::Content::no_tag( $output, "div", { id => "navbar_categories" }, |
|---|
| 81 | "common categories in $page navbar" ); |
|---|
| 82 | Test::HTML::Content::no_tag( $output, "div", { id => "navbar_locales" }, |
|---|
| 83 | "...common locales too" ); |
|---|
| 84 | } |
|---|