root/trunk/t/12_macros.t

Revision 1027, 8.9 kB (checked in by kake, 21 months ago)

Added category and locale parameters to action=random and made a new macro to go with it.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1use strict;
2use Wiki::Toolkit::Setup::SQLite;
3use OpenGuides;
4use OpenGuides::Test;
5use Test::More;
6
7eval { require DBD::SQLite; };
8
9if ( $@ ) {
10    my ($error) = $@ =~ /^(.*?)\n/;
11    plan skip_all => "DBD::SQLite could not be used - no database to test with. ($error)";
12}
13
14plan tests => 15;
15
16SKIP: {
17    # Clear out the database from any previous runs.
18    unlink "t/node.db";
19    unlink <t/indexes/*>;
20    Wiki::Toolkit::Setup::SQLite::setup( { dbname => "t/node.db" } );
21
22    my $config = OpenGuides::Test->make_basic_config;
23    my $guide = OpenGuides->new( config => $config );
24    my $wiki = $guide->wiki;
25
26    # Test @INDEX_LINK
27    $wiki->write_node( "Test 1", "\@INDEX_LINK [[Category Foo]]" )
28      or die "Can't write node";
29    $wiki->write_node( "Test 2", "\@INDEX_LINK [[Category Bar|Bars]]" )
30      or die "Can't write node";
31
32    my $output;
33    $output = $guide->display_node(
34                                    return_output => 1,
35                                    id            => "Test 1",
36                                  );
37    like( $output, qr/View all pages in Category Foo/,
38          "\@INDEX_LINK has right default link text" );
39    $output = $guide->display_node(
40                                    return_output => 1,
41                                    id            => "Test 2",
42                                  );
43    like( $output, qr/>Bars<\/a>/, "...and can be overridden" );
44
45    # Test @INDEX_LIST
46    $wiki->write_node( "Test 3", "\@INDEX_LIST [[Category Foo]]" )
47      or die "Can't write node";
48    $wiki->write_node( "Test 4", "\@INDEX_LIST [[Locale Bar]]" )
49      or die "Can't write node";
50    $wiki->write_node( "Test 5", "\@INDEX_LIST [[Category Nonexistent]]" )
51      or die "Can't write node";
52    $wiki->write_node( "Test 6", "\@INDEX_LIST [[Locale Nonexistent]]" )
53      or die "Can't write node";
54    $wiki->write_node( "Wibble", "wibble", undef,
55                       {
56                         category => "foo",
57                         locale   => "bar",
58                       }
59                     )
60      or die "Can't write node";
61    $output = $guide->display_node(
62                                    return_output => 1,
63                                    id            => "Test 3",
64                                  );
65    like ( $output, qr|<a href=".*">Wibble</a>|,
66           '@INDEX_LIST works for categories' );
67    $output = $guide->display_node(
68                                    return_output => 1,
69                                    id            => "Test 5",
70                                  );
71    like ( $output, qr|No pages currently in category|,
72           "...and fails nicely if no pages in category" );
73    $output = $guide->display_node(
74                                    return_output => 1,
75                                    id            => "Test 4",
76                                  );
77    like ( $output, qr|<a href=".*">Wibble</a>|,
78           '@INDEX_LIST works for locales' );
79    $output = $guide->display_node(
80                                    return_output => 1,
81                                    id            => "Test 6",
82                                  );
83    like ( $output, qr|No pages currently in locale|,
84           "...and fails nicely if no pages in locale" );
85
86    # Test @MAP_LINK
87    OpenGuides::Test->write_data(
88                                  guide   => $guide,
89                                  node    => "Test 1",
90                                  content => "\@MAP_LINK [[Category Foo]]",
91                                  return_output => 1,
92                                );
93    OpenGuides::Test->write_data(
94                                  guide   => $guide,
95                                  node    => "Test 2",
96                                  content => "\@MAP_LINK [[Category Foo|Map]]",
97                                  return_output => 1,
98                                );
99    $output = $guide->display_node(
100                                    return_output => 1,
101                                    id            => "Test 1",
102                                  );
103    like( $output, qr/View map of pages in Category Foo/,
104          "\@MAP_LINK has right default link text" );
105    $output = $guide->display_node(
106                                    return_output => 1,
107                                    id            => "Test 2",
108                                  );
109    like( $output, qr/>Map<\/a>/, "...and can be overridden" );
110
111    # Test @RANDOM_PAGE_LINK
112    OpenGuides::Test->write_data(
113                                  guide   => $guide,
114                                  node    => "Test Random",
115                                  content => "\@RANDOM_PAGE_LINK",
116                                  return_output => 1,
117                                );
118    $output = $guide->display_node(
119                                    return_output => 1,
120                                    id            => "Test Random",
121                                  );
122    like( $output, qr/View a random page on this guide/,
123          "\@RANDOM_PAGE_LINK has right default link text" );
124
125    # Not sure yet how to let people override link text in the above.  TODO.
126
127    OpenGuides::Test->write_data(
128                                  guide   => $guide,
129                                  node    => "Test Random",
130                                  content => "\@RANDOM_PAGE_LINK "
131                                             . "[[Category Pubs]]",
132                                  return_output => 1,
133                                );
134    $output = $guide->display_node(
135                                    return_output => 1,
136                                    id            => "Test Random",
137                                  );
138    like( $output, qr/View a random page in Category Pubs/,
139          "\@RANDOM_PAGE_LINK has right default link text for categories" );
140    OpenGuides::Test->write_data(
141                                  guide   => $guide,
142                                  node    => "Test Random",
143                                  content => "\@RANDOM_PAGE_LINK "
144                                             . "[[Category Pubs|Random pub]]",
145                                  return_output => 1,
146                                );
147    $output = $guide->display_node(
148                                    return_output => 1,
149                                    id            => "Test Random",
150                                  );
151    like( $output, qr/>Random pub<\/a>/, "...and can be overridden" );
152
153    OpenGuides::Test->write_data(
154                                  guide   => $guide,
155                                  node    => "Test Random",
156                                  content => "\@RANDOM_PAGE_LINK "
157                                             . "[[Locale Fulham]]",
158                                  return_output => 1,
159                                );
160    $output = $guide->display_node(
161                                    return_output => 1,
162                                    id            => "Test Random",
163                                  );
164    like( $output, qr/View a random page in Locale Fulham/,
165          "\@RANDOM_PAGE_LINK has right default link text for categories" );
166    OpenGuides::Test->write_data(
167                                  guide   => $guide,
168                                  node    => "Test Random",
169                                  content => "\@RANDOM_PAGE_LINK "
170                                             . "[[Locale Fulham|"
171                                             . "Random thing in Fulham]]",
172                                  return_output => 1,
173                                );
174    $output = $guide->display_node(
175                                    return_output => 1,
176                                    id            => "Test Random",
177                                  );
178    like( $output, qr/>Random thing in Fulham<\/a>/,
179          "...and can be overridden" );
180
181    # Test @INCLUDE_NODE
182    OpenGuides::Test->write_data(
183                                  guide   => $guide,
184                                  node    => "Test 1",
185                                  content => "Hello, I am Test 1!\r\n"
186                                             . "\@INCLUDE_NODE [[Test 2]]",
187                                  return_output => 1,
188                                );
189    OpenGuides::Test->write_data(
190                                  guide   => $guide,
191                                  node    => "Test 2",
192                                  content => "Hello, I am Test 2!",
193                                  return_output => 1,
194                                );
195    $output = $guide->display_node(
196                                    return_output => 1,
197                                    id            => "Test 1",
198                                  );
199    like( $output, qr/Hello, I am Test 1!/,
200          "Node with \@INCLUDE_NODE has its own content" );
201    like( $output, qr/Hello, I am Test 2!/,
202          "...and the included content" );
203}
Note: See TracBrowser for help on using the browser.