dokuwiki-indexmenu-plugin – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 <?php
2  
3 require_once DOKU_INC.'inc/parser/xhtml.php';
4  
5 /**
6 * @group plugin_indexmenu
7 */
8 class indexmenu_syntax_indexmenu_test extends DokuWikiTest {
9  
10 private $exampleIndex;
11  
12 public function setup() {
13 global $conf;
14 $this->pluginsEnabled[] = 'indexmenu';
15 parent::setup();
16  
17 //$conf['plugin']['indexmenu']['headpage'] = '';
18 //$conf['plugin']['indexmenu']['hide_headpage'] = false;
19  
20 //saveWikiText('titleonly:sub:test', "====== Title ====== \n content", 'created');
21 //saveWikiText('test', "====== Title ====== \n content", 'created');
22 //idx_addPage('titleonly:sub:test');
23 //idx_addPage('test');
24 }
25  
26 function __construct() {
27 $this->exampleIndex = "{{indexmenu>:}}";
28 }
29  
30 /**
31 * Create from list of values the output array of handle()
32 *
33 * @param array $values
34 * @return array aligned similar to output of handle()
35 */
36 function createData($values) {
37  
38 list($ns, $theme, $identifier, $nocookie, $navbar, $noscroll, $maxjs, $notoc, $scorespace, $jsajax, $context, $nomenu,
39 $sort, $msort, $rsort, $nsort, $level, $nons, $nopg, $nss, $max, $js, $skipns, $skipfile, $hsort,
40 $headpage, $hide_headpage) = $values;
41  
42 return array(
43 $ns,
44 Array(
45 'theme' => $theme,
46 'identifier' => $identifier,
47 'nocookie' => $nocookie,
48 'navbar' => $navbar,
49 'noscroll' => $noscroll,
50 'maxjs' => $maxjs,
51 'notoc' => $notoc,
52 'scorespace' => $scorespace,
53 'jsajax' => $jsajax,
54 'context' => $context,
55 'nomenu' => $nomenu,
56 ),
57 $sort,
58 $msort,
59 $rsort,
60 $nsort,
61 array(
62 'level' => $level,
63 'nons' => $nons,
64 'nopg' => $nopg,
65 'nss' => $nss,
66 'max' => $max,
67 'js' => $js,
68 'skip_index' => $skipns,
69 'skip_file' => $skipfile,
70 'headpage' => $headpage,
71 'hide_headpage' => $hide_headpage
72 ),
73 $hsort
74 );
75 }
76  
77 /**
78 * Parse the syntax to options
79 * expect: different combinations with or without js option, covers recognizing all syntax options
80 */
81 function testHandle() {
82 global $conf;
83  
84 $plugin = new syntax_plugin_indexmenu_indexmenu();
85  
86 $null = new Doku_Handler();
87 $result = $plugin->handle($this->exampleIndex, 0, 40, $null);
88  
89 $idcalculatedfromns = sprintf("%u", crc32(''));
90 $tests = array(
91 //root ns (empty is not recognized..)
92 array(
93 'syntax'=> "{{indexmenu>:}}",
94 'data' => array(
95 '', 'default', 'random', false, false, false, 0, false, '', false, false,
96 0, false, false, false, -1, false, false, array(), 0, false, array(''), array(''), false,
97 ":start:,:same:,:inside:", 1
98 )
99 ),
100 //root ns, #levels=1, js renderer
101 array(
102 'syntax'=> "{{indexmenu>#1|js}}",
103 'data' => array(
104 '', 'default', 'random', false, false, false, 0, false, '', false, false,
105 0, false, false, false, 1, false, false, array(), 0, true, array(''), array(''), false,
106 ":start:,:same:,:inside:", 1
107 )
108 ),
109 //root ns, #levels=2, all not js specific options (nocookie is from context)
110 array(
111 'syntax'=> "{{indexmenu>#2 test#6|navbar context tsort dsort msort hsort rsort nsort nons nopg}}",
112 'data' => array(
113 '', 'default', 'random', true, true, false, 0, false, '&sort=t&msort=indexmenu_n&rsort=1&nsort=1&hsort=1&nopg=1', true, false,
114 't', 'indexmenu_n', true, true, 2, true, true, array(array('test', 6)), 0, false, array(''), array(''), true,
115 ":start:,:same:,:inside:", 1
116 )
117 ),
118 //root ns, #levels=2, js renderer, all not js specific options
119 array(
120 'syntax'=> "{{indexmenu>#2 test#6|navbar js#bj_ubuntu.png context tsort dsort msort hsort rsort nsort nons nopg}}",
121 'data' => array(
122 '', 'bj_ubuntu.png', 'random', true, true, false, 0, false, '&sort=t&msort=indexmenu_n&rsort=1&nsort=1&hsort=1&nopg=1', true, false,
123 't', 'indexmenu_n', true, true, 2, true, true, array(array('test', 6)), 0, true, array(''), array(''), true,
124 ":start:,:same:,:inside:", 1
125 ),
126 ),
127 //root ns, #levels=1, all options
128 array(
129 'syntax'=> "{{indexmenu>#1|navbar context nocookie noscroll notoc scorespace nomenu dsort msort#date:modified hsort rsort nsort nons nopg max#2#4 maxjs#3 id#54321}}",
130 'data' => array(
131 '', 'default', 'random', true, true, true, 0, true, '&sort=d&msort=date modified&rsort=1&nsort=1&hsort=1&nopg=1', true, true,
132 'd', 'date modified', true, true, 1, true, true, array(), 0, false, array(''), array(''), true,
133 ":start:,:same:,:inside:", 1
134 )
135 ),
136 //root ns, #levels=1, js renderer, all options
137 array(
138 'syntax'=> "{{indexmenu>#1|js#bj_ubuntu.png navbar context nocookie noscroll notoc scorespace nomenu dsort msort#date:modified hsort rsort nsort nons nopg max#2#4 maxjs#3 id#54321}}",
139 'data' => array(
140 '', 'bj_ubuntu.png', 54321, true, true, true, 3, true, '&sort=d&msort=date modified&rsort=1&nsort=1&hsort=1&nopg=1&max=4', true, true,
141 'd', 'date modified', true, true, 1, true, true, array(), 2, true, array(''), array(''), true,
142 ":start:,:same:,:inside:", 1
143 )
144 ),
145 //root ns, #levels=1, skipfile and ns
146  
147 array(
148 'syntax'=> "{{indexmenu>#1 test|skipfile+/(^myusers:spaces$|privatens:userss)/ skipns=/(^myusers:spaces$|privatens:users)/ id#ns}}",
149 'data' => array(
150 '', 'default', 'random', false, false, false, 0, false, '&skipns=%3D/%28%5Emyusers%3Aspaces%24%7Cprivatens%3Ausers%29/&skipfile=%2B/%28%5Emyusers%3Aspaces%24%7Cprivatens%3Auserss%29/', false, false,
151 0, false, false, false, 1, false, false, array(array('test', -1)), 0, false, array('/(^myusers:spaces$|privatens:users)/'), array('', '/(^myusers:spaces$|privatens:userss)/'), false,
152 ":start:,:same:,:inside:", 1
153 )
154 ),
155 //root ns, #levels=1, js renderer, skipfile and ns
156 array(
157 'syntax'=> "{{indexmenu>#1 test|js skipfile=/(^myusers:spaces$|privatens:userss)/ skipns+/(^myusers:spaces$|privatens:userssss)/ id#ns}}",
158 'data' => array(
159 '', 'default', 0, false, false, false, 0, false, '&skipns=%2B/%28%5Emyusers%3Aspaces%24%7Cprivatens%3Auserssss%29/&skipfile=%3D/%28%5Emyusers%3Aspaces%24%7Cprivatens%3Auserss%29/', false, false,
160 0, false, false, false, 1, false, false, array(array('test', -1)), 0, true, array('', '/(^myusers:spaces$|privatens:userssss)/'), array('/(^myusers:spaces$|privatens:userss)/'), false,
161 ":start:,:same:,:inside:", 1
162 )
163 )
164 );
165  
166 foreach($tests as $test) {
167 $null = new Doku_Handler();
168 $result = $plugin->handle($test['syntax'], 0, 40, $null);
169  
170 //copy unique generated number, which is about 23 characters
171 $len_id = strlen($result[1]['identifier']);
172 if(!is_numeric($test['data'][2]) && ($len_id > 20||$len_id<=23)) {
173 $test['data'][2] = $result[1]['identifier'];
174 }
175 $data = $this->createData($test['data']);
176  
177 $this->assertEquals($data, $result, 'Data array corrupted');
178 }
179 }
180  
181 /**
182 * Rendering for nonexisting namespace
183 * expect: no paragraph due to no message set
184 * expect: one paragraph, since message set
185 * expect: contains namespace which replaced {{ns}}
186 * expect: message contained rendered italic syntax
187 */
188 function testRenderEmptymsg() {
189 global $conf;
190  
191 $noexistns = 'nonexisting:namespace';
192 $emptyindexsyntax = "{{indexmenu>$noexistns}}";
193  
194 $xhtml = new Doku_Renderer_xhtml();
195 $plugin = new syntax_plugin_indexmenu_indexmenu();
196  
197 $null = new Doku_Handler();
198 $result = $plugin->handle($emptyindexsyntax, 0, 10, $null);
199  
200 //no empty message
201 $plugin->render('xhtml', $xhtml, $result);
202 $doc = phpQuery::newDocument($xhtml->doc);
203 $this->assertEquals(0, pq('p', $doc)->length);
204  
205 // Fill in empty message
206 $conf['plugin']['indexmenu']['empty_msg'] = 'This namespace is //empty//: {{ns}}';
207 $plugin->render('xhtml', $xhtml, $result);
208 $doc = phpQuery::newDocument($xhtml->doc);
209  
210 $this->assertEquals(1, pq('p', $doc)->length);
211 $this->assertEquals(1, pq("p:contains($noexistns)")->length);
212 $this->assertEquals(1, pq("p em")->length);
213 }
214  
215 }