1<?php
2
3
4/**
5 * Test the component plugin
6 *
7 * @group plugin_minimap
8 * @group plugins
9 */
10class plugin_minimap_test extends DokuWikiTest
11{
12
13    protected $pluginsEnabled = [syntax_plugin_minimap::PLUGIN_NAME];
14
15    public function setUp()
16    {
17        parent::setUp();
18        global $conf;
19        $conf['template']='dokuwiki';
20    }
21
22
23    public function test_component_name()
24    {
25
26        $componentName = syntax_plugin_minimap::getTag();
27
28        $this->assertEquals('minimap', $componentName);
29
30    }
31
32    public function test_minimap_basic()
33    {
34
35        $namespace = 'minimap_basic';
36        $page1 = $namespace.':'.'page1';
37        saveWikiText($page1, 'First page', 'First page');
38        idx_addPage($page1);
39
40        $page2 = $namespace.':'.'page2';
41        saveWikiText($page2, 'First page', 'First page');
42        idx_addPage($page2);
43
44        $minimapPage = $namespace.':'.'sidebar';
45        saveWikiText($minimapPage, '<' . syntax_plugin_minimap::PLUGIN_NAME . ' />', 'Page with minimap');
46        idx_addPage($minimapPage);
47
48        $testRequest = new TestRequest();
49        $testResponse = $testRequest->get(array('id' => $page1));
50
51        // One minimap
52        $phpQueryObject = $testResponse->queryHTML('#minimap__plugin');
53        $count = $phpQueryObject->count();
54        $this->assertEquals(1, $count, "We should see the id");
55
56        // Panel present
57        $phpQueryObject = $testResponse->queryHTML('.panel');
58        $count = $phpQueryObject->count();
59        $this->assertEquals(1, $count,"We should see container for the whole map");
60
61        // Panel header
62        $phpQueryObject = $testResponse->queryHTML('.panel-heading');
63        $count = $phpQueryObject->count();
64        $this->assertEquals(1, $count, "We should see one container for the header");
65
66        // List group (container page)
67        $phpQueryObject = $testResponse->queryHTML('.list-group');
68        $count = $phpQueryObject->count();
69        $this->assertEquals(1, $count,"We should see one container for the pages");
70
71        // List  (page)
72        $phpQueryObject = $testResponse->queryHTML('.list-group-item');
73        $count = $phpQueryObject->count();
74        $this->assertEquals(2, $count, "We should see two pages");
75
76        // List  (one item active)
77        $phpQueryObject = $testResponse->queryHTML('.list-group-item.active');
78        $count = $phpQueryObject->count();
79        $this->assertEquals(1, $count,"One page should be active");
80
81    }
82
83
84    public function test_minimap_conf_subdirectory()
85    {
86
87        // Changing it to true
88        global $conf;
89        $conf['plugin'][syntax_plugin_minimap::PLUGIN_NAME][syntax_plugin_minimap::INCLUDE_DIRECTORY_PARAMETERS]=true;
90
91        // Test
92        $namespace = 'minimap_conf_sub_directory';
93        $page1 = $namespace.':'.'page1';
94        saveWikiText($page1, 'First page', 'First page');
95        idx_addPage($page1);
96
97        $subpage = $namespace.':sub:sub';
98        saveWikiText($subpage, 'Sub page', 'Sub page');
99        idx_addPage($subpage);
100
101        $minimapPage = $namespace.':'.'sidebar';
102        saveWikiText($minimapPage, '<' . syntax_plugin_minimap::PLUGIN_NAME . ' />', 'Page with minimap');
103        idx_addPage($minimapPage);
104
105        $testRequest = new TestRequest();
106        $testResponse = $testRequest->get(array('id' => $page1));
107
108        // One minimap
109        $phpQueryObject = $testResponse->queryHTML('#minimap__plugin');
110        $count = $phpQueryObject->count();
111        $this->assertEquals(1, $count, "We should see the id");
112
113        // List  (page)
114        $phpQueryObject = $testResponse->queryHTML('.list-group-item');
115        $count = $phpQueryObject->count();
116        $this->assertEquals(2, $count, "We should see two pages ");
117
118        // List  (page)
119        $phpQueryObject = $testResponse->queryHTML('.nicon_folder_open');
120        $count = $phpQueryObject->count();
121        $this->assertEquals(1, $count, "We should see the folder");
122
123
124    }
125
126    /**
127     * Test the inline parameter includeDirectory
128     */
129    public function test_minimap_param_subdirectory()
130    {
131
132
133        // Test
134        $namespace = 'minimap_param_subdir';
135        $page1 = $namespace.':'.'page1';
136        saveWikiText($page1, 'First page', 'First page');
137        idx_addPage($page1);
138
139        $subpage = $namespace.':sub:sub';
140        saveWikiText($subpage, 'Sub page', 'Sub page');
141        idx_addPage($subpage);
142
143        $minimapPage = $namespace.':'.'sidebar';
144        saveWikiText($minimapPage, '<' . syntax_plugin_minimap::PLUGIN_NAME . ' '.syntax_plugin_minimap::INCLUDE_DIRECTORY_PARAMETERS.'="true" />', 'Page with minimap');
145        idx_addPage($minimapPage);
146
147        $testRequest = new TestRequest();
148        $testResponse = $testRequest->get(array('id' => $page1));
149
150        // One minimap
151        $phpQueryObject = $testResponse->queryHTML('#minimap__plugin');
152        $count = $phpQueryObject->count();
153        $this->assertEquals(1, $count, "We should see the id");
154
155        // List  (page)
156        $phpQueryObject = $testResponse->queryHTML('.nicon_folder_open');
157        $count = $phpQueryObject->count();
158        $this->assertEquals(1, $count, "We should see the folder");
159
160
161        // List  (page)
162        $phpQueryObject = $testResponse->queryHTML('.list-group-item');
163        $count = $phpQueryObject->count();
164        $this->assertEquals(2, $count, "We should see two pages ");
165
166
167
168
169
170    }
171
172
173    /**
174     * The header should not show up if there is no header
175     */
176    public function test_minimap_conf_showheader()
177    {
178
179        // Changing it to true
180        global $conf;
181        $conf['plugin'][syntax_plugin_minimap::PLUGIN_NAME][syntax_plugin_minimap::SHOW_HEADER]=false;
182
183        // Test
184        $namespace = 'minimap_conf_show_header';
185        $page1 = $namespace.':'.'page1';
186        saveWikiText($page1, 'First page', 'First page');
187        idx_addPage($page1);
188
189        $minimapPage = $namespace.':'.'sidebar';
190        saveWikiText($minimapPage, '<' . syntax_plugin_minimap::PLUGIN_NAME . ' />', 'Page with minimap');
191        idx_addPage($minimapPage);
192
193        $testRequest = new TestRequest();
194        $testResponse = $testRequest->get(array('id' => $page1));
195
196        // One minimap
197        $phpQueryObject = $testResponse->queryHTML('#minimap__plugin');
198        $count = $phpQueryObject->count();
199        $this->assertEquals(1, $count, "We should see the id");
200
201
202        // List  (page)
203        $phpQueryObject = $testResponse->queryHTML('.panel-heading');
204        $count = $phpQueryObject->count();
205        $this->assertEquals(0, $count, "Because there is no home page, we should not see the header");
206
207
208
209    }
210
211    /**
212     * The header should not show up if there is a inline showHeader param
213     */
214    public function test_minimap_param_showheader()
215    {
216
217
218        // Test
219        $namespace = 'minimap_param_show_header';
220        $page1 = $namespace.':'.'page1';
221        saveWikiText($page1, 'First page', 'First page');
222        idx_addPage($page1);
223
224        $minimapPage = $namespace.':'.'sidebar';
225        saveWikiText($minimapPage, '<' . syntax_plugin_minimap::PLUGIN_NAME . ' '.syntax_plugin_minimap::SHOW_HEADER.'="false" />', 'Page with minimap');
226        idx_addPage($minimapPage);
227
228        $testRequest = new TestRequest();
229        $testResponse = $testRequest->get(array('id' => $page1));
230
231        // One minimap
232        $phpQueryObject = $testResponse->queryHTML('#minimap__plugin');
233        $count = $phpQueryObject->count();
234        $this->assertEquals(1, $count, "We should see the id");
235
236
237        // List  (page)
238        $phpQueryObject = $testResponse->queryHTML('.panel-heading');
239        $count = $phpQueryObject->count();
240        $this->assertEquals(0, $count, "Because there is no home page, we should not see the header");
241
242
243
244    }
245
246
247
248    /**
249     * Test the inline namespace parameter
250     */
251    public function test_minimap_param_namespace()
252    {
253
254
255        // Test
256        $namespace = 'minimap_param_namespace';
257        $page1 = $namespace.':'.'page1';
258        saveWikiText($page1, 'First page', 'First page');
259        idx_addPage($page1);
260
261        $page2 = $namespace.':'.'page2';
262        saveWikiText($page2, 'Second page', 'Second page');
263        idx_addPage($page2);
264
265        $subNamespace=$namespace.':sub';
266        $subpage = $subNamespace.':sub';
267        saveWikiText($subpage, 'Sub page', 'Sub page');
268        idx_addPage($subpage);
269
270        $minimapPage = $namespace.':'.'sidebar';
271        saveWikiText($minimapPage, '<' . syntax_plugin_minimap::PLUGIN_NAME . ' '.syntax_plugin_minimap::NAMESPACE.'="'.$subNamespace.'" />', 'Page with minimap');
272        idx_addPage($minimapPage);
273
274        $testRequest = new TestRequest();
275        $testResponse = $testRequest->get(array('id' => $page1));
276
277        // One minimap
278        $phpQueryObject = $testResponse->queryHTML('#minimap__plugin');
279        $count = $phpQueryObject->count();
280        $this->assertEquals(1, $count, "We should see the id");
281
282
283        // List  (page)
284        $phpQueryObject = $testResponse->queryHTML('.list-group-item');
285        $count = $phpQueryObject->count();
286        $this->assertEquals(1, $count, "We should only one page");
287
288
289
290    }
291
292
293
294}
295
296