source: trunk/t/51_display_node.t @ 1269

Last change on this file since 1269 was 1269, checked in by Dominic Hargreaves, 13 years ago

Don't display revision info for nodes that don't exist (fixes #193)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides::Config;
4use OpenGuides;
5use OpenGuides::Test;
6use Test::More;
7
8eval { require DBD::SQLite; };
9my $have_sqlite = $@ ? 0 : 1;
10
11if ( $@ ) {
12    my ($error) = $@ =~ /^(.*?)\n/;
13    plan skip_all => "DBD::SQLite could not be used - no database to test with ($error)";
14}
15
16plan tests => 18;
17
18Wiki::Toolkit::Setup::SQLite::cleardb( { dbname => "t/node.db" } );
19Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
20my $config = OpenGuides::Config->new(
21       vars => {
22                 dbtype             => "sqlite",
23                 dbname             => "t/node.db",
24                 indexing_directory => "t/indexes",
25                 script_name        => "wiki.cgi",
26                 script_url         => "http://example.com/",
27                 site_name          => "Test Site",
28                 template_path      => "./templates",
29                 home_name          => "Home",
30                 admin_pass         => "password",
31               }
32);
33eval { require Wiki::Toolkit::Search::Plucene; };
34if ( $@ ) { $config->use_plucene ( 0 ) };
35
36my $guide = OpenGuides->new( config => $config );
37isa_ok( $guide, "OpenGuides" );
38my $wiki = $guide->wiki;
39isa_ok( $wiki, "Wiki::Toolkit" );
40$wiki->write_node( "Test Page", "foo", undef, { source => "alternate.cgi?Test_Page" } );
41my $output = eval {
42    $guide->display_node( id => "Test Page", return_output => 1 );
43};
44is( $@, "", "->display_node doesn't die" );
45
46like( $output, qr{\<a.*?\Qhref="alternate.cgi?id=Test_Page;action=edit"\E>Edit\s+this\s+page</a>}, "...and edit link is redirected to source URL" );
47$config->home_name( "My Home Page" );
48$output = $guide->display_node( return_output => 1 );
49like( $output, qr/My\s+Home\s+Page/, "...and defaults to the home node, and takes notice of what we want to call it" );
50like( $output, qr{\Q<a href="wiki.cgi?action=edit;id=My_Home_Page"\E>Edit\s+this\s+page</a>}, "...and home page has an edit link" );
51my %tt_vars = $guide->display_node( return_tt_vars => 1 );
52ok( defined $tt_vars{recent_changes}, "...and recent_changes is set for the home node even if we have changed its name" );
53
54$wiki->write_node( 'Redirect Test', '#REDIRECT Test Page', undef );
55
56$output = $guide->display_node( id => 'Redirect Test',
57                                return_output => 1,
58                                intercept_redirect => 1 );
59
60like( $output, qr{^\QLocation: http://example.com/wiki.cgi?id=Test_Page;oldid=Redirect_Test}ms,
61      '#REDIRECT redirects correctly' );
62
63$output = $guide->display_node( id => 'Redirect Test', return_output => 1, redirect => 0 );
64
65unlike( $output, qr{^\QLocation: }ms, '...but not with redirect=0' );
66
67# Write a node, then delete one each of its categories and locales.
68OpenGuides::Test->write_data(
69                              guide => $guide,
70                              node => "Non-existent categories and locales",
71                              categories => "Does Not Exist\r\nDoes Exist",
72                              locales => "Does Not Exist\r\nDoes Exist",
73                              return_output => 1,
74                            );
75foreach my $id ( ( "Category Does Not Exist", "Locale Does Not Exist" ) ) {
76    $guide->delete_node(
77                         id => $id,
78                         password => "password",
79                         return_output => 1,
80                       );
81}
82
83# Check the display comes up right for the existent and nonexistent.
84$output = $guide->display_node( id => 'Non-existent categories and locales',
85                                return_output => 1
86                              );
87
88unlike( $output, qr{\Q<a href="wiki.cgi?Category_Does_Not_Exist"},
89    "category name not linked if category does not exist" );
90like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"},
91    "...but does when it does exist" );
92unlike( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Not_Exist"},
93    "locale name not linked if category does not exist" );
94like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"},
95    "...but does when it does exist" );
96
97# Check it works when the case is different too.
98OpenGuides::Test->write_data(
99                              guide => $guide,
100                              node => "Existent categories and locales",
101                              categories => "does exist",
102                              locales => "does exist",
103                              return_output => 1,
104                            );
105
106$output = $guide->display_node( id => "Existent categories and locales",
107                                return_output => 1
108                              );
109like( $output, qr{\Q<a href="wiki.cgi?Category_Does_Exist"},
110    "wrongly-cased categories are linked as they should be" );
111like( $output, qr{\Q<a href="wiki.cgi?Locale_Does_Exist"},
112    "wrongly-cased locales are linked as they should be" );
113
114$output = $guide->display_node( id => "Does not exist",
115                                return_output => 1
116                              );
117like( $output, qr{\QWe don't have a node called "Does not exist".},
118    "not found message shows up" );
119unlike( $output, qr{\QRevision 0},
120    "bogus revision number doesn't show up" );
121unlike( $output, qr{\QLast edited},
122    "bogus last edited doesn't show up" );
Note: See TracBrowser for help on using the repository browser.