source: trunk/UnitTestContrib/test/unit/Fn_INCLUDE.pm @ 14649

Revision 14649, 22.2 KB checked in by SvenDowideit, 13 months ago (diff)

Item11783: INCLUDE supports a list of topics to try to include

  • Property svn:keywords set to Revision Date
Line 
1use strict;
2
3# tests for the correct expansion of INCLUDE
4
5package Fn_INCLUDE;
6
7use FoswikiFnTestCase;
8our @ISA = qw( FoswikiFnTestCase );
9
10use Foswiki;
11use Error qw( :try );
12
13sub new {
14    my $self = shift()->SUPER::new( 'INCLUDE', @_ );
15    return $self;
16}
17
18sub set_up {
19    my $this = shift;
20    $this->SUPER::set_up();
21    $this->{other_web} = "$this->{test_web}other";
22    my $webObject = $this->populateNewWeb( $this->{other_web} );
23    $webObject->finish();
24}
25
26sub tear_down {
27    my $this = shift;
28    $this->removeWebFixture( $this->{session}, $this->{other_web} );
29    $this->SUPER::tear_down();
30}
31
32sub run_test_simple {
33    my $this = shift;
34    my $includeTopic = shift || $this->{test_web}.'.FirstTopic';
35    my $includeError = shift;
36    my $noSectionError = shift || $includeError;
37   
38    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1');
39    $this->assert_str_equals($includeError?"A $includeError B":'A 1 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'"}% B', 'WebHome', $this->{other_web}));
40   
41    $this->assert_str_equals($includeError?"A  B":'A 1 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" warn="off"}% B', 'WebHome', $this->{other_web}));
42
43
44    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTINCLUDE%2%STOPINCLUDE% 3');
45    $this->assert_str_equals($includeError?"A $includeError B":'A 2 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'"}% B', 'WebHome', $this->{other_web}));
46
47    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION{type="include"}%2%ENDSECTION{type="include"}% 3');
48    $this->assert_str_equals($includeError?"A $includeError B":'A 2 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'"}% B', 'WebHome', $this->{other_web}));
49
50    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION{type="include"}%2%ENDSECTION{type="include"}% 3 %STARTSECTION{type="include"}%4%ENDSECTION{type="include"}% 5');
51    $this->assert_str_equals($includeError?"A $includeError B":'A 24 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'"}% B', 'WebHome', $this->{other_web}));
52
53    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION%2%ENDSECTION% 3');
54    $this->assert_str_equals($includeError?"A $includeError B":'A 1 2 3 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'"}% B', 'WebHome', $this->{other_web}));
55
56    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION{"_default"}%2%ENDSECTION{"_default"}% 3');
57    $this->assert_str_equals($includeError?"A $includeError B":'A 1 2 3 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'"}% B', 'WebHome', $this->{other_web}));
58
59    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION{"_default"}%2%ENDSECTION{"_default"}% 3 %STARTSECTION{type="include"}%4%ENDSECTION{type="include"}% 5');
60    $this->assert_str_equals($includeError?"A $includeError B":'A 2 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="_default"}% B', 'WebHome', $this->{other_web}));
61   
62    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION{"_default"}%2%ENDSECTION{"_default"}% 3 %STARTSECTION{type="include"}%4%ENDSECTION{type="include"}% 5');
63    $this->assert_str_equals($noSectionError?"A $noSectionError B":'A 2 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="notthere"}% B', 'WebHome', $this->{other_web}));
64
65    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION{"_default"}%2%ENDSECTION{"_default"}% 3 %STARTSECTION{type="include"}%4%ENDSECTION{type="include"}% 5');
66    $this->assert_str_equals($includeError?"A  B":'A 2 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="_default" warn="off"}% B', 'WebHome', $this->{other_web}));
67   
68    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION{"_default"}%2%ENDSECTION{"_default"}% 3 %STARTSECTION{type="include"}%4%ENDSECTION{type="include"}% 5');
69    $this->assert_str_equals($noSectionError?"A  B":'A 2 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="notthere" warn="off"}% B', 'WebHome', $this->{other_web}));
70
71}
72
73sub test_simple {
74    my $this = shift;
75    $this->run_test_simple(undef, undef,
76    "<span class='foswikiAlert'>
77    Warning: Can't find named section <nop>notthere in topic <nop>TemporaryINCLUDETestWebINCLUDE.<nop>FirstTopic
78</span>");
79}
80
81sub test_simple_not_there {
82    my $this = shift;
83    $this->run_test_simple('NotThere', "<span class='foswikiAlert'>
84    Warning: Can't find topic <nop>TemporaryINCLUDETestWebINCLUDEother.<nop>NotThere
85</span>");
86}
87
88sub test_not_there_commas {
89    my $this = shift;
90    $this->run_test_simple('NotThere, System.NoTopic', "<span class='foswikiAlert'>
91    Warning: Can\'t find topic <nop>System.<nop>NoTopic
92</span>");
93}
94
95sub test_not_there_spaces {
96    my $this = shift;
97    $this->run_test_simple('NotThere System.NoTopic', "<span class='foswikiAlert'>
98    Warning: Can't find topic <nop>NotThere System.<nop>NoTopic
99</span>");
100}
101
102sub test_not_there_newlines {
103    my $this = shift;
104    $this->run_test_simple('NotThere
105System.NoTopic', "<span class='foswikiAlert'>
106   Warning: Can't INCLUDE '<nop>NotThere
107System.NoTopic', path is empty or contains illegal characters.
108</span>");
109}
110
111sub test_first_not_there_commas {
112    my $this = shift;
113    $this->run_test_simple('NotThere, '.$this->{test_web}.'.FirstTopic', undef, "<span class='foswikiAlert'>
114    Warning: Can't find named section <nop>notthere in topic <nop>TemporaryINCLUDETestWebINCLUDE.<nop>FirstTopic
115</span>");
116}
117
118sub test_first_not_there_spaces {
119    my $this = shift;
120    $this->run_test_simple('NotThere '.$this->{test_web}.'.FirstTopic', "<span class='foswikiAlert'>
121    Warning: Can't find topic <nop>NotThere TemporaryINCLUDETestWebINCLUDE.<nop>FirstTopic
122</span>");
123}
124
125sub test_first_not_there_newlines {
126    my $this = shift;
127    $this->run_test_simple('NotThere
128'.$this->{test_web}.'.FirstTopic', "<span class='foswikiAlert'>
129   Warning: Can't INCLUDE '<nop>NotThere
130TemporaryINCLUDETestWebINCLUDE.FirstTopic', path is empty or contains illegal characters.
131</span>");
132}
133
134sub test_simple_section {
135    my $this = shift;
136    my $includeSection = shift || '';
137    my $includeTopic = shift || $this->{test_web}.'.FirstTopic';
138    my $includeError = shift;
139    my $noSectionError = shift || $includeError;
140   
141    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1');
142    $this->assert_str_equals($noSectionError?"A $noSectionError B":'A 1 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="'.$includeSection.'"}% B', 'WebHome', $this->{other_web}));
143   
144    $this->assert_str_equals(($includeError||$noSectionError)?"A  B":'A 1 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="'.$includeSection.'" warn="off"}% B', 'WebHome', $this->{other_web}));
145
146
147    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTINCLUDE%2%STOPINCLUDE% 3');
148    $this->assert_str_equals($noSectionError?"A $noSectionError B":'A 2 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="'.$includeSection.'"}% B', 'WebHome', $this->{other_web}));
149
150    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION{type="include"}%2%ENDSECTION{type="include"}% 3');
151    $this->assert_str_equals($noSectionError?"A $noSectionError B":'A 2 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="'.$includeSection.'"}% B', 'WebHome', $this->{other_web}));
152
153    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION{type="include"}%2%ENDSECTION{type="include"}% 3 %STARTSECTION{type="include"}%4%ENDSECTION{type="include"}% 5');
154    $this->assert_str_equals($noSectionError?"A $noSectionError B":'A 24 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="'.$includeSection.'"}% B', 'WebHome', $this->{other_web}));
155
156    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION%2%ENDSECTION% 3');
157    $this->assert_str_equals($noSectionError?"A $noSectionError B":'A 1 2 3 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="'.$includeSection.'"}% B', 'WebHome', $this->{other_web}));
158
159    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION{"_default"}%2%ENDSECTION{"_default"}% 3');
160    $this->assert_str_equals($noSectionError?"A $noSectionError B":'A 1 2 3 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="'.$includeSection.'"}% B', 'WebHome', $this->{other_web}));
161
162    Foswiki::Func::saveTopic($this->{test_web}, 'FirstTopic', undef, '1 %STARTSECTION{"_default"}%2%ENDSECTION{"_default"}% 3 %STARTSECTION{type="include"}%4%ENDSECTION{type="include"}% 5');
163    $this->assert_str_equals($includeError?"A $includeError B":'A 2 B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.$includeTopic.'" section="'.$includeSection.'" section="_default"}% B', 'WebHome', $this->{other_web}));
164
165}
166
167
168sub test_select_first_that_defines_section {
169    my $this = shift;
170    $this->test_simple_section('section_name', 
171            join(', ', ('NoSuchTopic', $this->{test_web}.'.NoSuchTopic')),
172            "<span class='foswikiAlert'>
173    Warning: Can't find topic <nop>TemporaryINCLUDETestWebINCLUDE.<nop>NoSuchTopic
174</span>"
175            );
176
177
178    $this->test_simple_section('section_name', 
179            join(', ', ('NoSuchTopic', $this->{test_web}.'.FirstTopic')),
180            undef,
181            "<span class='foswikiAlert'>
182    Warning: Can't find named section <nop>section_name in topic <nop>TemporaryINCLUDETestWebINCLUDE.<nop>FirstTopic
183</span>"
184            );
185
186    Foswiki::Func::saveTopic($this->{test_web}, 'NoSection', undef, '1 %STARTSECTION{"_default"}%2%ENDSECTION{"_default"}% 3 %STARTSECTION{type="include"}%4%ENDSECTION{type="include"}% 5');
187    $this->test_simple_section('section_name', 
188            join(', ', ('NoSuchTopic', $this->{test_web}.'.NoSection', $this->{test_web}.'.FirstTopic')),
189            undef,
190            "<span class='foswikiAlert'>
191    Warning: Can't find named section <nop>section_name in topic <nop>TemporaryINCLUDETestWebINCLUDE.<nop>FirstTopic
192</span>"
193            );
194
195    Foswiki::Func::saveTopic($this->{test_web}, 'TheSection', undef, '1 %STARTSECTION{"section_name"}%::%ENDSECTION{"section_name"}% 3 %STARTSECTION{type="include"}%4%ENDSECTION{type="include"}% 5');
196    $this->assert_str_equals('A :: B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.
197                            join(', ', ($this->{test_web}.'.TheSection', 'NoSuchTopic', $this->{test_web}.'.FirstTopic'))
198                            .'" section="section_name"}% B', 'WebHome', $this->{other_web}));
199    $this->assert_str_equals('A :: B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.
200                            join(', ', ('NoSuchTopic', $this->{test_web}.'.TheSection', $this->{test_web}.'.FirstTopic'))
201                            .'" section="section_name"}% B', 'WebHome', $this->{other_web}));
202    $this->assert_str_equals('A :: B', Foswiki::Func::expandCommonVariables( 'A %INCLUDE{"'.
203                            join(', ', ('NoSuchTopic', $this->{test_web}.'.FirstTopic', $this->{test_web}.'.TheSection'))
204                            .'" section="section_name"}% B', 'WebHome', $this->{other_web}));
205
206}
207
208
209
210# Test that web references are correctly expanded when a topic is included
211# from another web. Verifies that verbatim, literal and noautolink zones
212# are correctly honoured.
213sub test_webExpansion {
214    my $this = shift;
215
216    # Create topic to include
217    my $includedTopic = "TopicToInclude";
218    my ($inkyDink) =
219      Foswiki::Func::readTopic( $this->{other_web}, $includedTopic );
220    $inkyDink->text( <<THIS);
221<literal>
2221 [[$includedTopic][one]] $includedTopic
223</literal>
224<verbatim>
2252 [[$includedTopic][two]] $includedTopic
226</verbatim>
227<pre>
2283 [[$includedTopic][three]] $includedTopic
229</pre>
230<noautolink>
2314 [[$includedTopic][four]] [[$includedTopic]] $includedTopic
232</noautolink>
2335 [[$includedTopic][five]] $includedTopic
234$includedTopic 6
2357 ($includedTopic)
2368 #$includedTopic
2379 [[System.$includedTopic]]
23810 [[$includedTopic]]
23911 [[http://fleegle][$includedTopic]]
24012 [[#anchor][$includedTopic]]
24113 [[#$includedTopic][$includedTopic]]
242THIS
243    $inkyDink->save();
244
245    # Expand an include in the context of the test web
246    my ($topicObject) =
247      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
248    my $text = $topicObject->expandMacros(
249        "%INCLUDE{$this->{other_web}.$includedTopic}%");
250    my @get    = split( /\n/, $text );
251    my @expect = split( /\n/, <<THIS);
252<literal>
2531 [[$includedTopic][one]] $includedTopic
254</literal>
255<verbatim>
2562 [[$includedTopic][two]] $includedTopic
257</verbatim>
258<pre>
2593 [[$this->{other_web}.$includedTopic][three]] $this->{other_web}.$includedTopic
260</pre>
261<noautolink>
2624 [[$this->{other_web}.$includedTopic][four]] [[$this->{other_web}.$includedTopic][$includedTopic]] $includedTopic
263</noautolink>
2645 [[$this->{other_web}.$includedTopic][five]] $this->{other_web}.$includedTopic
265$this->{other_web}.$includedTopic 6
2667 ($this->{other_web}.$includedTopic)
2678 #$includedTopic
2689 [[System.$includedTopic]]
26910 [[$this->{other_web}.$includedTopic][$includedTopic]]
27011 [[http://fleegle][$includedTopic]]
27112 [[#anchor][$includedTopic]]
27213 [[#$includedTopic][$includedTopic]]
273THIS
274    while ( my $e = pop(@expect) ) {
275        $this->assert_str_equals( $e, pop(@get) );
276    }
277
278}
279
280# Test include of a section when there is no such section in the included
281# topic
282sub test_3158 {
283    my $this          = shift;
284    my $includedTopic = "TopicToInclude";
285    my ($inkyDink) =
286      Foswiki::Func::readTopic( $this->{other_web}, $includedTopic );
287    $inkyDink->text(<<THIS);
288Snurfle
289%STARTSECTION{"suction"}%
290Such a section!
291%ENDSECTION{"suction"}%
292Out of scope
293THIS
294    $inkyDink->save();
295    my $text =
296      $this->{test_topicObject}->expandMacros(
297        "%INCLUDE{\"$this->{other_web}.$includedTopic\" section=\"suction\"}%");
298    $this->assert_str_equals( "\nSuch a section!\n", $text );
299
300    $inkyDink->text(<<THIS);
301%STARTSECTION{"nosuction"}%
302No such section!
303%ENDSECTION{"nosuction"}%
304THIS
305    $inkyDink->save();
306
307    #warnings are off
308    $text =
309      $this->{test_topicObject}->expandMacros(
310"%INCLUDE{\"$this->{other_web}.$includedTopic\" section=\"suction\" warn=\"off\"}%"
311      );
312    $this->assert_str_equals( '', $text );
313
314    #warning on
315    $text =
316      $this->{test_topicObject}->expandMacros(
317"%INCLUDE{\"$this->{other_web}.$includedTopic\" section=\"suction\" warn=\"on\"}%"
318      );
319    $this->assert_str_equals( <<HERE, $text . "\n" );
320<span class='foswikiAlert'>
321    Warning: Can't find named section <nop>suction in topic <nop>TemporaryINCLUDETestWebINCLUDEother.<nop>TopicToInclude
322</span>
323HERE
324
325    #custom warning
326    $text =
327      $this->{test_topicObject}->expandMacros(
328"%INCLUDE{\"$this->{other_web}.$includedTopic\" section=\"suction\" warn=\"consider yourself warned\"}%"
329      );
330    $this->assert_str_equals( 'consider yourself warned', $text );
331}
332
333# INCLUDE{"" section=""}% should act as though section was not set (ie, return the entire topic)
334sub test_5649 {
335    my $this          = shift;
336    my $includedTopic = "TopicToInclude";
337    my $topicText     = <<THIS;
338Snurfle
339%STARTSECTION{"suction"}%
340Such a section!
341%ENDSECTION{"suction"}%
342Out of scope
343THIS
344    my $handledTopicText = $topicText;
345    $handledTopicText =~ s/%(START|END)SECTION{"suction"}%//g;
346
347    my ($inkyDink) =
348      Foswiki::Func::readTopic( $this->{other_web}, $includedTopic );
349    $inkyDink->text($topicText);
350    $inkyDink->save();
351    my $text =
352      $this->{test_topicObject}->expandMacros(
353        "%INCLUDE{\"$this->{other_web}.$includedTopic\" section=\"\"}%");
354    $this->assert_str_equals( $handledTopicText, $text . "\n" )
355      ;    #add \n because expandMacros removes it :/
356}
357
358sub test_singlequoted_params {
359    my $this = shift;
360    my $text =
361      $this->{test_topicObject}
362      ->expandMacros("%INCLUDE{'Oneweb.SomeTopic' section='suction'}%");
363    $this->assert_str_equals(
364        "<span class='foswikiAlert'>
365   Warning: Can't INCLUDE '<nop>'Oneweb.SomeTopic' section='suction'', path is empty or contains illegal characters. 
366</span>", $text
367    );
368
369    $text =
370      $this->{test_topicObject}
371      ->expandMacros('%INCLUDE{"I can\'t believe its not butter"}%');
372    $this->assert_str_equals(
373        "<span class='foswikiAlert'>
374   Warning: Can't INCLUDE '<nop>I can't believe its not butter', path is empty or contains illegal characters.
375</span>", $text
376    );
377}
378
379sub test_fullPattern {
380    my $this          = shift;
381    my $includedTopic = "TopicToInclude";
382    my $topicText     = <<THIS;
383Baa baa black sheep
384Have you any socks?
385Yes sir, yes sir
386But only in acrylic
387THIS
388
389    my ($inkyDink) =
390      Foswiki::Func::readTopic( $this->{other_web}, $includedTopic );
391    $inkyDink->text($topicText);
392    $inkyDink->save();
393    my $text =
394      $this->{test_topicObject}->expandMacros(
395"%INCLUDE{\"$this->{other_web}.$includedTopic\" pattern=\"^.*?(Have.*sir).*\"}%"
396      );
397    $this->assert_str_equals( "Have you any socks?\nYes sir, yes sir", $text );
398}
399
400sub test_pattern {
401    my $this          = shift;
402    my $includedTopic = "TopicToInclude";
403    my $topicText     = <<THIS;
404Baa baa black sheep
405Have you any socks?
406Yes sir, yes sir
407But only in acrylic
408THIS
409
410    my ($inkyDink) =
411      Foswiki::Func::readTopic( $this->{other_web}, $includedTopic );
412    $inkyDink->text($topicText);
413    $inkyDink->save();
414    my $text =
415      $this->{test_topicObject}->expandMacros(
416"%INCLUDE{\"$this->{other_web}.$includedTopic\" pattern=\"(Have.*sir)\"}%"
417      );
418    $this->assert_str_equals( "Have you any socks?\nYes sir, yes sir", $text );
419}
420
421# INCLUDE{"" pattern="(blah)"}% that does not match should return nothing
422sub test_patternNoMatch {
423    my $this          = shift;
424    my $includedTopic = "TopicToInclude";
425    my $topicText     = <<THIS;
426Baa baa black sheep
427Have you any socks?
428Yes sir, yes sir
429But only in acrylic
430THIS
431
432    my ($inkyDink) =
433      Foswiki::Func::readTopic( $this->{other_web}, $includedTopic );
434    $inkyDink->text($topicText);
435    $inkyDink->save();
436    my $text =
437      $this->{test_topicObject}->expandMacros(
438        "%INCLUDE{\"$this->{other_web}.$includedTopic\" pattern=\"(blah)\"}%");
439    $this->assert_str_equals( "", $text );
440}
441
442# INCLUDE{"" pattern="blah"}% that does not capture should return nothing
443sub test_patternNoCapture {
444    my $this          = shift;
445    my $includedTopic = "TopicToInclude";
446    my $topicText     = <<THIS;
447Baa baa black sheep
448Have you any socks?
449Yes sir, yes sir
450But only in acrylic
451THIS
452
453    my ($inkyDink) =
454      Foswiki::Func::readTopic( $this->{other_web}, $includedTopic );
455    $inkyDink->text($topicText);
456    $inkyDink->save();
457    my $text =
458      $this->{test_topicObject}->expandMacros(
459        "%INCLUDE{\"$this->{other_web}.$includedTopic\" pattern=\".*\"}%");
460    $this->assert_str_equals( "", $text );
461}
462
463sub test_docInclude {
464    my $this = shift;
465
466    my $class = 'Foswiki::IncludeHandlers::doc';
467    my $text = $this->{test_topicObject}->expandMacros("%INCLUDE{doc:$class}%");
468    my $expected = <<"EXPECTED";
469
470---+ =internal package= Foswiki::IncludeHandlers::doc
471
472This package is designed to be lazy-loaded when Foswiki sees
473an INCLUDE macro with the doc: protocol. It implements a single
474method INCLUDE which generates perl documentation for a Foswiki class.
475
476EXPECTED
477    $this->assert_str_equals( $expected, $text );
478
479    # Add a pattern
480    $text =
481      $this->{test_topicObject}->expandMacros(
482        "%INCLUDE{\"doc:$class\" pattern=\"(Foswiki .*protocol)\"}%");
483    $expected = "Foswiki sees\nan INCLUDE macro with the doc: protocol";
484    $this->assert_str_equals( $expected, $text );
485
486    # A pattern with no ()'s
487    $text =
488      $this->{test_topicObject}->expandMacros(
489        "%INCLUDE{\"doc:$class\" pattern=\"Foswiki .*protocol\"}%");
490    $expected = '';
491    $this->assert_str_equals( $expected, $text );
492
493    # A pattern that does not match
494    $text =
495      $this->{test_topicObject}->expandMacros(
496        "%INCLUDE{\"doc:$class\" pattern=\"(cabbage.*avocado)\" warn=\"no\"}%");
497    $expected = '';
498    $this->assert_str_equals( $expected, $text );
499}
500
501sub test_hassleFreeHoff {
502    my $this = shift;
503
504    # Create topic to include
505    my $includedTopic = "TopicToInclude";
506    my ($inkyDink) =
507      Foswiki::Func::readTopic( $this->{test_web}, $includedTopic );
508    $inkyDink->text( <<INCLUDE);
509---+ H1
510---++ H2
511---+++ H3
512---++++ H4
513---+++++ H5
514---++++++ H6
515<h6>H6</H6>
516<H5>H5</h5>
517<H4>H4</H4>
518<h3>H3</h3>
519<h2 style="color:orange">H2</h2>
520<h1>H1</h1>
521<ho off="1">
522---+ H1
523<ho off="-1">
524---+ H1
525INCLUDE
526    $inkyDink->save();
527
528    my ($topicObject) =
529      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
530    my $text = $topicObject->expandMacros(<<EXPAND);
531%INCLUDE{"$includedTopic" headingoffset="1"}%
532%INCLUDE{"$includedTopic" headingoffset="+1"}%
533%INCLUDE{"$includedTopic" headingoffset="-1"}%
534EXPAND
535    $text = $topicObject->renderTML($text);
536    $text =~ s/<nop>//g;
537    my $expect = <<EXPECT;
538<h2 id="H1_AN3">  H1 </h2>
539<h3 id="H2">  H2 </h3>
540<h4 id="H3_AN3">  H3 </h4>
541<h5 id="H4_AN3">  H4 </h5>
542<h6 id="H5_AN3">  H5 </h6>
543<h6 id="H6_AN3">  H6 </h6>
544<h6 id="H6"> H6 </h6>
545<h6 id="H5"> H5 </h6>
546<h5 id="H4"> H4 </h5>
547<h4 id="H3"> H3 </h4>
548<h3 style="color:orange">H2</h3>
549<h2 id="H1"> H1 </h2>
550<h3 id="H1_AN4">  H1 </h3>
551<h2 id="H1_AN5">  H1 </h2>
552
553<h2 id="H1_AN6">  H1 </h2>
554<h3 id="H2_AN1">  H2 </h3>
555<h4 id="H3_AN4">  H3 </h4>
556<h5 id="H4_AN4">  H4 </h5>
557<h6 id="H5_AN4">  H5 </h6>
558<h6 id="H6_AN4">  H6 </h6>
559<h6 id="H6_AN1"> H6 </h6>
560<h6 id="H5_AN1"> H5 </h6>
561<h5 id="H4_AN1"> H4 </h5>
562<h4 id="H3_AN1"> H3 </h4>
563<h3 style="color:orange">H2</h3>
564<h2 id="H1_AN1"> H1 </h2>
565<h3 id="H1_AN7">  H1 </h3>
566<h2 id="H1_AN8">  H1 </h2>
567
568<h1 id="H1_AN9">  H1 </h1>
569<h1 id="H2_AN2">  H2 </h1>
570<h2 id="H3_AN5">  H3 </h2>
571<h3 id="H4_AN5">  H4 </h3>
572<h4 id="H5_AN5">  H5 </h4>
573<h5 id="H6_AN5">  H6 </h5>
574<h5 id="H6_AN2"> H6 </h5>
575<h4 id="H5_AN2"> H5 </h4>
576<h3 id="H4_AN2"> H4 </h3>
577<h2 id="H3_AN2"> H3 </h2>
578<h1 style="color:orange">H2</h1>
579<h1 id="H1_AN2"> H1 </h1>
580<h1 id="H1_AN10">  H1 </h1>
581<h1 id="H1_AN11">  H1 </h1>
582EXPECT
583    $this->assert_html_equals( $expect, $text );
584}
585
5861;
Note: See TracBrowser for help on using the repository browser.