| 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 | plan tests => 4; |
|---|
| 14 | |
|---|
| 15 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 16 | $config->custom_template_path( cwd . "/t/templates/" ); |
|---|
| 17 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 18 | my $wiki = $guide->wiki; |
|---|
| 19 | |
|---|
| 20 | # Clear out the database from any previous runs. |
|---|
| 21 | foreach my $del_node ( $wiki->list_all_nodes ) { |
|---|
| 22 | print "# Deleting node $del_node\n"; |
|---|
| 23 | $wiki->delete_node( $del_node ) or die "Can't delete $del_node"; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | # Write a custom template to autofill content in autocreated nodes. |
|---|
| 27 | eval { |
|---|
| 28 | unlink cwd . "/t/templates/custom_autocreate_content.tt"; |
|---|
| 29 | }; |
|---|
| 30 | open( FILE, ">", cwd . "/t/templates/custom_autocreate_content.tt" ) |
|---|
| 31 | or die $!; |
|---|
| 32 | print FILE <<EOF; |
|---|
| 33 | Auto-generated list of places in |
|---|
| 34 | [% IF index_type == "Category" %]this category[% ELSE %][% index_value %][% END %]: |
|---|
| 35 | \@INDEX_LIST [[[% node_name %]]] |
|---|
| 36 | EOF |
|---|
| 37 | close FILE or die $!; |
|---|
| 38 | |
|---|
| 39 | # Check that autocapitalisation works correctly in categories with hyphens. |
|---|
| 40 | OpenGuides::Test->write_data( |
|---|
| 41 | guide => $guide, |
|---|
| 42 | node => "Vivat Bacchus", |
|---|
| 43 | categories => "Restaurants\r\nVegan-friendly", |
|---|
| 44 | locales => "Farringdon", |
|---|
| 45 | ); |
|---|
| 46 | |
|---|
| 47 | ok( $wiki->node_exists( "Category Vegan-Friendly" ), |
|---|
| 48 | "Categories with hyphens in are auto-created correctly." ); |
|---|
| 49 | |
|---|
| 50 | # Check that the custom autocreate template was picked up. |
|---|
| 51 | my $content = $wiki->retrieve_node( "Category Vegan-Friendly" ); |
|---|
| 52 | $content =~ s/\s+$//s; |
|---|
| 53 | $content =~ s/\s+/ /gs; |
|---|
| 54 | is( $content, "Auto-generated list of places in this category: " |
|---|
| 55 | . "\@INDEX_LIST [[Category Vegan-Friendly]]", |
|---|
| 56 | "Custom autocreate template works properly for categories" ); |
|---|
| 57 | |
|---|
| 58 | $content = $wiki->retrieve_node( "Locale Farringdon" ); |
|---|
| 59 | $content =~ s/\s+$//s; |
|---|
| 60 | $content =~ s/\s+/ /gs; |
|---|
| 61 | is( $content, "Auto-generated list of places in Farringdon: " |
|---|
| 62 | . "\@INDEX_LIST [[Locale Farringdon]]", |
|---|
| 63 | "...and locales" ); |
|---|
| 64 | |
|---|
| 65 | # Now make sure that we have a fallback if there's no autocreate template. |
|---|
| 66 | unlink cwd . "/t/templates/custom_autocreate_content.tt"; |
|---|
| 67 | |
|---|
| 68 | OpenGuides::Test->write_data( |
|---|
| 69 | guide => $guide, |
|---|
| 70 | node => "Bleeding Heart", |
|---|
| 71 | categories => "Pubs", |
|---|
| 72 | ); |
|---|
| 73 | $content = $wiki->retrieve_node( "Category Pubs" ); |
|---|
| 74 | $content =~ s/\s+$//s; |
|---|
| 75 | $content =~ s/\s+/ /gs; |
|---|
| 76 | is( $content, "\@INDEX_LINK [[Category Pubs]]", |
|---|
| 77 | "Default content is picked up if autocreate template doesn't exist" ); |
|---|