root/tags/rel0_59/t/19_autocreate.t

Revision 956, 2.7 kB (checked in by earle, 22 months ago)

Complete transition to using skip_all (remove old SKIP blocks).
More verbose reporting for error "require"ing DBD::SQLite.

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
13plan tests => 4;
14
15my $config = OpenGuides::Test->make_basic_config;
16$config->custom_template_path( cwd . "/t/templates/" );
17my $guide = OpenGuides->new( config => $config );
18my $wiki = $guide->wiki;
19
20# Clear out the database from any previous runs.
21foreach 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.
27eval {
28    unlink cwd . "/t/templates/custom_autocreate_content.tt";
29};
30open( FILE, ">", cwd . "/t/templates/custom_autocreate_content.tt" )
31  or die $!;
32print FILE <<EOF;
33Auto-generated list of places in
34[% IF index_type == "Category" %]this category[% ELSE %][% index_value %][% END %]:
35\@INDEX_LIST [[[% node_name %]]]
36EOF
37close FILE or die $!;
38
39# Check that autocapitalisation works correctly in categories with hyphens.
40OpenGuides::Test->write_data(
41                              guide => $guide,
42                              node  => "Vivat Bacchus",
43                              categories => "Restaurants\r\nVegan-friendly",
44                              locales => "Farringdon",
45                            );
46
47ok( $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.
51my $content = $wiki->retrieve_node( "Category Vegan-Friendly" );
52$content =~ s/\s+$//s;
53$content =~ s/\s+/ /gs;
54is( $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;
61is( $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.
66unlink cwd . "/t/templates/custom_autocreate_content.tt";
67
68OpenGuides::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;
76is( $content, "\@INDEX_LINK [[Category Pubs]]",
77    "Default content is picked up if autocreate template doesn't exist" );
Note: See TracBrowser for help on using the browser.