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