1<?php /** @noinspection PhpComposerExtensionStubsInspection */
2
3use ComboStrap\TplUtility;
4
5require_once(__DIR__ . '/../class/TplUtility.php');
6require_once(__DIR__ . '/../class/DomUtility.php');
7
8/**
9 *
10 * Test the {@link tpl_strap_meta_header()
11 *
12 * @group template_strap
13 * @group templates
14 */
15class strapTest extends DokuWikiTest
16{
17
18    const DEFAULT_BOOTSTRAP_4 = "4.5.0 - bootstrap";
19    const DEFAULT_BOOTSTRAP_5 = "5.0.1 - bootstrap";
20
21    public function setUp(): void
22    {
23
24        global $conf;
25        parent::setUp();
26        $conf ['template'] = 'strap';
27
28        /**
29         * static variable bug in the {@link tpl_getConf()}
30         * that does not load the configuration twice
31         */
32        TplUtility::reloadConf();
33
34    }
35
36    /**
37     * An utility function that test if the headers meta are still
38     * on the page (ie response)
39     * @param TestResponse $response
40     * @param $selector - the DOM elementselector
41     * @param $attr - the attribute to check
42     * @param $scriptSignatures - the pattern signature to find
43     * @param string $testDescription - the login type (anonymous, logged in, ...)
44     */
45    private function checkMeta(TestResponse $response, $selector, $attr, $scriptSignatures, $testDescription)
46    {
47
48
49        /**
50         * @var array|DomElement $scripts
51         */
52        $domElements = $response->queryHTML($selector)->get();
53
54        $domValueToChecks = [];
55        foreach ($domElements as $domElement) {
56            /**
57             * @var DOMElement $domElement
58             */
59            $value = $domElement->getAttribute($attr);
60            if (empty($value)) {
61                $value = $domElement->textContent;
62            }
63            $domValueToChecks[] = $value;
64        }
65        $domValueNotFounds = $domValueToChecks;
66        foreach ($scriptSignatures as $signatureToFind) {
67            $patternFound = 0;
68            foreach ($domValueToChecks as $domValueToCheck) {
69                $patternFound = preg_match("/$signatureToFind/i", $domValueToCheck);
70                if ($patternFound === 1) {
71                    if (($key = array_search($domValueToCheck, $domValueNotFounds)) !== false) {
72                        unset($domValueNotFounds[$key]);
73                    }
74                    break;
75                }
76            }
77            $this->assertTrue($patternFound !== 0, "Unable to find ($signatureToFind) for ${testDescription}");
78        }
79
80
81        foreach ($domValueNotFounds as $domValueNotFound) {
82            $this->assertNull($domValueNotFound, "All selected element have been found by a signature, for ($selector) on ${testDescription}");
83        }
84
85
86    }
87
88
89    /**
90     * Test the default configuration
91     *
92     * Test the {@link \Combostrap\TplUtility::handleBootstrapMetaHeaders()} function
93     */
94    public function test_handleBootStrapMetaHeaders_anonymous_default()
95    {
96
97        $bootstrapStylesheetVersions = [self::DEFAULT_BOOTSTRAP_5, self::DEFAULT_BOOTSTRAP_4];
98
99        foreach ($bootstrapStylesheetVersions as $bootstrapStylesheetVersion) {
100            TplUtility::setConf(TplUtility::CONF_BOOTSTRAP_VERSION_STYLESHEET, $bootstrapStylesheetVersion);
101
102            $version = TplUtility::getBootStrapVersion();
103            if ($version == "4.5.0") {
104                /**
105                 * Script signature
106                 * CDN is on by default
107                 *
108                 * js.php is needed for custom script such as a consent box
109                 */
110                $scriptsSignature = [
111                    "jquery.com\/jquery-(.*).js",
112                    "cdn.jsdelivr.net\/npm\/popper.js",
113                    "stackpath.bootstrapcdn.com\/bootstrap\/$version\/js\/bootstrap.min.js",
114                    'JSINFO',
115                    'js.php'
116                ];
117
118                /**
119                 * Stylesheet signature (href)
120                 */
121                $stylsheetSignature = ["stackpath.bootstrapcdn.com\/bootstrap\/$version\/css\/bootstrap.min.css", '\/lib\/exe\/css.php\?t\=strap'];
122
123            } else {
124
125                $scriptsSignature = [
126                    //    "jquery.com\/jquery-(.*).js", no more need in Bootstrap 5
127                    "cdn.jsdelivr.net\/npm\/@popperjs",// out of the bundle to use it for auto-completion dropdown
128                    "cdn.jsdelivr.net\/npm\/bootstrap\@$version\/dist\/js\/bootstrap.min.js",
129                    "jquery.php", // jquery of Dokuwiki (Bootstrap 5 does not have its own)
130                    'JSINFO',
131                    'js.php'
132                ];
133
134                /**
135                 * Stylesheet signature (href)
136                 */
137                $stylsheetSignature = [
138                    "cdn.jsdelivr.net\/npm\/bootstrap\@$version\/dist\/css\/bootstrap.min.css",
139                    '\/lib\/exe\/css.php\?t\=strap'
140                ];
141
142            }
143
144            // Anonymous
145            $pageId = 'start';
146            saveWikiText($pageId, "Content", 'Script Test base');
147            idx_addPage($pageId);
148
149            $request = new TestRequest();
150            $response = $request->get(array('id' => $pageId, '/doku.php'));
151
152            $cdn = tpl_getConf(TplUtility::CONF_USE_CDN);
153            $this->assertEquals(1, $cdn, "The CDN is by default on on version $bootstrapStylesheetVersion");
154
155            /**
156             * Meta script test
157             */
158            $testDescription = "Anonymous on version ($bootstrapStylesheetVersion)";
159            $this->checkMeta($response, 'script', "src", $scriptsSignature, $testDescription);
160            /**
161             * Meta stylesheet test
162             */
163            $this->checkMeta($response, 'link[rel="stylesheet"]', "href", $stylsheetSignature, $testDescription);
164        }
165
166
167    }
168
169    /**
170     * Test the Jquery conf
171     *
172     * Test the {@link \Combostrap\TplUtility::handleBootstrapMetaHeaders()} function
173     * @throws Exception
174     */
175    public function test_handleBootStrapMetaHeaders_anonymous_jquery_doku()
176    {
177
178        /**
179         * Jquery Doku is off by default
180         * Because on Bootstrap 5, there is no Jquery
181         * There should be a Jquery even if off
182         */
183        $jqueryUI = tpl_getConf(TplUtility::CONF_JQUERY_DOKU);
184        $this->assertEquals(0, $jqueryUI, "jquery is off");
185        TplUtility::setConf(TplUtility::CONF_BOOTSTRAP_VERSION_STYLESHEET, self::DEFAULT_BOOTSTRAP_5);
186        $testDescription = "Jquery on Boostrap 5 should be present";
187        $version = TplUtility::getBootStrapVersion();
188        $scriptsSignature = [
189            "jquery.php",
190            "cdn.jsdelivr.net\/npm\/@popperjs",
191            "cdn.jsdelivr.net\/npm\/bootstrap\@$version\/dist\/js\/bootstrap.min.js",
192            'JSINFO',
193            'js.php'
194        ];
195        $stylsheetSignature = [
196            "cdn.jsdelivr.net\/npm\/bootstrap\@$version\/dist\/css\/bootstrap.min.css",
197            '\/lib\/exe\/css.php\?t\=strap'
198        ];
199        $pageId = 'start';
200        saveWikiText($pageId, "Content", 'Script Test base');
201        idx_addPage($pageId);
202        $request = new TestRequest();
203        $response = $request->get(array('id' => $pageId, '/doku.php'));
204        $this->checkMeta($response, 'script', "src", $scriptsSignature, $testDescription);
205        $this->checkMeta($response, 'link[rel="stylesheet"]', "href", $stylsheetSignature, $testDescription);
206
207        /**
208         * Jquery is on
209         */
210        TplUtility::setConf(TplUtility::CONF_JQUERY_DOKU, 1);
211        $jqueryUI = tpl_getConf(TplUtility::CONF_JQUERY_DOKU);
212        $this->assertEquals(1, $jqueryUI, "jquery is on");
213
214        /**
215         * For 4 and 5
216         */
217        $bootstrapStylesheetVersions = [self::DEFAULT_BOOTSTRAP_5, self::DEFAULT_BOOTSTRAP_4];
218
219        foreach ($bootstrapStylesheetVersions as $bootstrapStylesheetVersion) {
220
221            $testDescription = "Anonymous for $bootstrapStylesheetVersion";
222
223            TplUtility::setConf(TplUtility::CONF_BOOTSTRAP_VERSION_STYLESHEET, $bootstrapStylesheetVersion);
224
225            $version = TplUtility::getBootStrapVersion();
226            if ($version == "4.5.0") {
227
228                $scriptsSignature = [
229                    "jquery.php",
230                    "cdn.jsdelivr.net\/npm\/popper.js",
231                    "stackpath.bootstrapcdn.com\/bootstrap\/$version\/js\/bootstrap.min.js",
232                    'JSINFO',
233                    'js.php'
234                ];
235
236                $stylsheetSignature = ["stackpath.bootstrapcdn.com\/bootstrap\/$version\/css\/bootstrap.min.css", '\/lib\/exe\/css.php\?t\=strap'];
237
238
239            } else {
240
241                /**
242                 * 5
243                 */
244                $scriptsSignature = [
245                    "jquery.php",
246                    "cdn.jsdelivr.net\/npm\/@popperjs",
247                    "cdn.jsdelivr.net\/npm\/bootstrap\@$version\/dist\/js\/bootstrap.min.js",
248                    'JSINFO',
249                    'js.php'
250                ];
251
252                $stylsheetSignature = [
253                    "cdn.jsdelivr.net\/npm\/bootstrap\@$version\/dist\/css\/bootstrap.min.css",
254                    '\/lib\/exe\/css.php\?t\=strap'
255                ];
256
257
258            }
259            // Anonymous
260            $pageId = 'start';
261            saveWikiText($pageId, "Content", 'Script Test base');
262            idx_addPage($pageId);
263
264            $request = new TestRequest();
265            $response = $request->get(array('id' => $pageId, '/doku.php'));
266
267
268            /**
269             * Script signature
270             * CDN is on by default
271             *
272             * js.php is needed for custom script such as a consent box
273             */
274
275            $this->checkMeta($response, 'script', "src", $scriptsSignature, $testDescription);
276
277            /**
278             * Stylesheet signature (href)
279             */
280            $this->checkMeta($response, 'link[rel="stylesheet"]', "href", $stylsheetSignature, $testDescription);
281
282        }
283    }
284
285    /**
286     * @throws Exception
287     */
288    public function test_handleBootStrapMetaHeaders_anonymous_nocdn()
289    {
290
291        /**
292         * CDN is on by default, disable
293         */
294        TplUtility::setConf(TplUtility::CONF_USE_CDN, 0);
295
296        /**
297         * For 4 and 5
298         */
299        $bootstrapStylesheetVersions = [self::DEFAULT_BOOTSTRAP_5, self::DEFAULT_BOOTSTRAP_4];
300
301        foreach ($bootstrapStylesheetVersions as $bootstrapStylesheetVersion) {
302
303            $testDescription = "Anonymous no cdn for $bootstrapStylesheetVersion";
304
305            TplUtility::setConf(TplUtility::CONF_BOOTSTRAP_VERSION_STYLESHEET, $bootstrapStylesheetVersion);
306
307            $version = TplUtility::getBootStrapVersion();
308            $localDirPattern = '\/lib\/tpl\/strap\/bootstrap\/' . $version;
309            if ($version == "4.5.0") {
310
311                $scriptsSignature = [
312
313                    "$localDirPattern\/jquery-(.*).js",
314                    "$localDirPattern\/popper.min.js",
315                    "$localDirPattern\/bootstrap.min.js",
316                    'JSINFO', 'js.php'];
317
318                $stylsheetSignature = [
319                    "$localDirPattern\/bootstrap.min.css",
320                    '\/lib\/exe\/css.php\?t\=strap'
321                ];
322
323
324            } else {
325
326                /**
327                 * 5
328                 */
329                $scriptsSignature = [
330                    // "jquery.php", no jquery
331                    "$localDirPattern\/bootstrap.min.js",
332                    "$localDirPattern\/popper.min.js",
333                    "jquery.php", // jquery of Dokuwiki (Bootstrap 5 does not have its own)
334                    'JSINFO',
335                    'js.php'
336                ];
337
338                $stylsheetSignature = [
339                    "$localDirPattern\/bootstrap.min.css",
340                    '\/lib\/exe\/css.php\?t\=strap'
341                ];
342
343
344            }
345
346            // Anonymous
347            $pageId = 'start';
348            saveWikiText($pageId, "Content", 'Script Test base');
349            idx_addPage($pageId);
350
351            $request = new TestRequest();
352            $response = $request->get(array('id' => $pageId, '/doku.php'));
353
354            /**
355             * Script signature
356             */
357
358
359            $this->checkMeta($response, 'script', "src", $scriptsSignature, $testDescription);
360
361            /**
362             * Stylesheet signature (href)
363             */
364            $this->checkMeta($response, 'link[rel="stylesheet"]', "href", $stylsheetSignature, $testDescription);
365        }
366
367    }
368
369
370    /**
371     * For public combostrap website
372     * The Dokuwiki Javascript can be disabled
373     * If no other plugin use it
374     */
375    public function test_handleBootStrapMetaHeaders_anonymous_no_dokuwiki_javascript()
376    {
377
378        /**
379         * Disable
380         */
381        TplUtility::setConf(TplUtility::CONF_DISABLE_BACKEND_JAVASCRIPT, 1);
382
383        /**
384         * For 4 and 5
385         */
386        $bootstrapStylesheetVersions = [self::DEFAULT_BOOTSTRAP_5, self::DEFAULT_BOOTSTRAP_4];
387
388        foreach ($bootstrapStylesheetVersions as $bootstrapStylesheetVersion) {
389
390            $testDescription = "No Javascript for public user (Bootstrap $bootstrapStylesheetVersion)";
391
392            TplUtility::setConf(TplUtility::CONF_BOOTSTRAP_VERSION_STYLESHEET, $bootstrapStylesheetVersion);
393
394            $version = TplUtility::getBootStrapVersion();
395            if ($version == "4.5.0") {
396
397                /**
398                 * On 4, bootstrap depends on Jquery
399                 */
400                $scriptsSignature = [
401                    "jquery-(.*).js",
402                    "popper.min.js",
403                    "bootstrap.min.js",
404                    'JSINFO'
405                ];
406
407                $stylsheetSignature = [
408                    "bootstrap.min.css",
409                    '\/lib\/exe\/css.php\?t\=strap'
410                ];
411
412
413            } else {
414
415                /**
416                 * 5, only boostrap js
417                 */
418                $scriptsSignature = [
419                    "bootstrap.min.js",
420                    "cdn.jsdelivr.net\/npm\/@popperjs",
421                    'JSINFO'
422                ];
423
424                $stylsheetSignature = [
425                    "bootstrap.min.css",
426                    '\/lib\/exe\/css.php\?t\=strap'
427                ];
428
429
430            }
431
432            // Anonymous
433            $pageId = 'start';
434            saveWikiText($pageId, "Content", 'Script Test base');
435            idx_addPage($pageId);
436
437            $request = new TestRequest();
438            $response = $request->get(array('id' => $pageId, '/doku.php'));
439
440            /**
441             * Script signature
442             */
443            $this->checkMeta($response, 'script', "src", $scriptsSignature, $testDescription);
444
445            /**
446             * Stylesheet signature (href)
447             */
448            $this->checkMeta($response, 'link[rel="stylesheet"]', "href", $stylsheetSignature, $testDescription);
449        }
450
451    }
452
453    /**
454     * When a user is logged in, the CDN is no more
455     */
456    public
457    function test_handleBootStrapMetaHeaders_loggedin_default()
458    {
459
460        $pageId = 'start';
461        saveWikiText($pageId, "Content", 'Script Test base');
462        idx_addPage($pageId);
463        // Log in
464        global $conf;
465        $conf['useacl'] = 1;
466        $user = 'admin';
467        $conf['superuser'] = $user;
468
469        /**
470         * For 4 and 5
471         */
472        $bootstrapStylesheetVersions = [self::DEFAULT_BOOTSTRAP_5, self::DEFAULT_BOOTSTRAP_4];
473
474        foreach ($bootstrapStylesheetVersions as $bootstrapStylesheetVersion) {
475
476            $testDescription = "Logged in for $bootstrapStylesheetVersion";
477
478            TplUtility::setConf(TplUtility::CONF_BOOTSTRAP_VERSION_STYLESHEET, $bootstrapStylesheetVersion);
479
480            $version = TplUtility::getBootStrapVersion();
481            if ($version == "4.5.0") {
482
483                $scriptsSignature = [
484                    "jquery.php",
485                    "cdn.jsdelivr.net\/npm\/popper.js",
486                    "stackpath.bootstrapcdn.com\/bootstrap\/$version\/js\/bootstrap.min.js",
487                    'JSINFO',
488                    'js.php'];
489
490                $stylsheetSignature = [
491                    "stackpath.bootstrapcdn.com\/bootstrap\/$version\/css\/bootstrap.min.css",
492                    '\/lib\/exe\/css.php\?t\=strap'
493                ];
494
495
496            } else {
497
498                /**
499                 * 5
500                 */
501                $scriptsSignature = [
502                    "jquery.php",
503                    "cdn.jsdelivr.net\/npm\/@popperjs",
504                    "cdn.jsdelivr.net\/npm\/bootstrap\@$version\/dist\/js\/bootstrap.min.js",
505                    'JSINFO',
506                    'js.php'];
507
508                $stylsheetSignature = [
509                    "cdn.jsdelivr.net\/npm\/bootstrap\@$version\/dist\/css\/bootstrap.min.css",
510                    '\/lib\/exe\/css.php\?t\=strap'
511                ];
512
513            }
514
515            $request = new TestRequest();
516            $request->setServer('REMOTE_USER', $user);
517            $response = $request->get(array('id' => $pageId, '/doku.php'));
518
519            /**
520             * No Css preloading
521             */
522            $stylesheets = $response->queryHTML('link[rel="preload"]')->get();
523            $this->assertEquals(0, sizeof($stylesheets));
524
525            /**
526             * Script signature
527             */
528            $this->checkMeta($response, 'script', "src", $scriptsSignature, $testDescription);
529
530            /**
531             * Stylesheet signature (href)
532             */
533            $this->checkMeta($response, 'link[rel="stylesheet"]', "href", $stylsheetSignature, $testDescription);
534        }
535
536    }
537
538    /**
539     * test the css preload configuration
540     *
541     * @throws Exception
542     */
543    public
544    function test_css_preload_anonymous()
545    {
546
547        TplUtility::setConf('preloadCss', 1);
548
549        $pageId = 'start';
550        saveWikiText($pageId, "Content", 'Script Test base');
551        idx_addPage($pageId);
552
553        /**
554         * For 4 and 5
555         */
556        $bootstrapStylesheetVersions = [self::DEFAULT_BOOTSTRAP_5, self::DEFAULT_BOOTSTRAP_4];
557
558        foreach ($bootstrapStylesheetVersions as $bootstrapStylesheetVersion) {
559
560            $testDescription = "CSS preload in for $bootstrapStylesheetVersion";
561
562            TplUtility::setConf(TplUtility::CONF_BOOTSTRAP_VERSION_STYLESHEET, $bootstrapStylesheetVersion);
563
564            $version = TplUtility::getBootStrapVersion();
565            if ($version == "4.5.0") {
566
567                $stylsheetSignature = [
568                    "stackpath.bootstrapcdn.com\/bootstrap\/$version\/css\/bootstrap.min.css",
569                    '\/lib\/exe\/css.php\?t\=strap'
570                ];
571
572
573            } else {
574
575                /**
576                 * 5
577                 */
578                $stylsheetSignature = [
579                    "cdn.jsdelivr.net\/npm\/bootstrap\@$version\/dist\/css\/bootstrap.min.css",
580                    '\/lib\/exe\/css.php\?t\=strap'
581                ];
582
583            }
584
585            $request = new TestRequest();
586            $response = $request->get(array('id' => $pageId, '/doku.php'));
587
588
589            /**
590             * preload object
591             */
592            $stylesheets = $response->queryHTML('link[rel="preload"]')->get();
593
594
595            $node = array();
596            foreach ($stylesheets as $key => $stylesheet) {
597                if ($stylesheet->hasAttributes()) {
598                    foreach ($stylesheet->attributes as $attr) {
599                        $name = $attr->name;
600                        $value = $attr->value;
601                        $node[$key][$name] = $value;
602                    }
603                }
604            }
605
606            $this->assertEquals(2, sizeof($node), "The stylesheet count should be 2");
607
608            $this->checkMeta($response, 'link[rel="stylesheet"]', "href", $stylsheetSignature, $testDescription);
609
610        }
611
612
613    }
614
615
616    /**
617     * Test the {@link \Combostrap\TplUtility::getBootstrapMetaHeaders()} function
618     * with default conf
619     * @throws Exception
620     */
621    public
622    function test_getBootstrapMetaHeaders()
623    {
624
625        // Default
626        $metas = TplUtility::getBootstrapMetaHeaders();
627        $this->assertEquals(2, sizeof($metas));
628        $this->assertEquals(2, sizeof($metas['script']), "There is two js script (bootstrap+popper)");
629        $this->assertEquals(1, sizeof($metas['link']), "There is one css script");
630
631        TplUtility::setConf(TplUtility::CONF_BOOTSTRAP_VERSION_STYLESHEET, self::DEFAULT_BOOTSTRAP_4);
632        $metas = TplUtility::getBootstrapMetaHeaders();
633        $this->assertEquals(2, sizeof($metas));
634        $this->assertEquals(3, sizeof($metas['script']), "There is three js script");
635        $this->assertEquals(1, sizeof($metas['link']), "There is one css script");
636
637
638    }
639
640    /**
641     * Test the {@link \Combostrap\TplUtility::getBootstrapMetaHeaders()} function
642     * with bootswatch stylesheet and cdn (default)
643     * @throws Exception
644     */
645    public
646    function test_getBootstrapMetaHeadersWithCustomStyleSheet()
647    {
648        $template = "simplex";
649        $version = "5.0.1";
650        TplUtility::setConf(TplUtility::CONF_BOOTSTRAP_VERSION_STYLESHEET, "$version - $template");
651        $metas = TplUtility::getBootstrapMetaHeaders();
652        $this->assertEquals(2, sizeof($metas));
653        $this->assertEquals(2, sizeof($metas['script']), "There is 2 js script (bootstrap+popper)");
654        $this->assertEquals(1, sizeof($metas['link']), "There is one css script");
655        $this->assertEquals("https://cdn.jsdelivr.net/npm/bootswatch@{$version}/dist/$template/bootstrap.min.css", $metas['link']['css']['href'], "The href is the cdn");
656
657        $version = "4.5.0";
658        TplUtility::setConf(TplUtility::CONF_BOOTSTRAP_VERSION_STYLESHEET, "$version - {$template}");
659        $metas = TplUtility::getBootstrapMetaHeaders();
660        $this->assertEquals(2, sizeof($metas));
661        $this->assertEquals(3, sizeof($metas['script']), "There is three js script");
662        $this->assertEquals(1, sizeof($metas['link']), "There is one css script");
663        $this->assertEquals("https://cdn.jsdelivr.net/npm/bootswatch@$version/dist/$template/bootstrap.min.css", $metas['link']['css']['href'], "The href is the cdn");
664
665    }
666
667
668    /**
669     * Test favicon
670     */
671    public
672    function test_favicon()
673    {
674        $pageId = 'start';
675        saveWikiText($pageId, "Content", 'Script Test base');
676        idx_addPage($pageId);
677
678        $request = new TestRequest();
679        $response = $request->get(array('id' => $pageId));
680
681        // Favicon
682        $shortCut = $response->queryHTML('link[rel="shortcut icon"]');
683        $this->assertEquals(1, $shortCut->count());
684        $this->assertEquals("http://wiki.example.com/./lib/tpl/strap/images/favicon.ico", $shortCut->attr("href"), "Favicon");
685
686        // Icon
687        $icons = $response->queryHTML('link[rel="icon"]');
688        $this->assertEquals(2, $icons->count());
689        /**
690         * @var DOMElement $firstIcons
691         */
692        $firstIcons = $icons->elements[0];
693        $this->assertEquals("http://wiki.example.com/./lib/tpl/strap/images/favicon-32x32.png", $firstIcons->getAttribute("href"));
694        /**
695         * @var DOMElement $secondIcon
696         */
697        $secondIcon = $icons->elements[1];
698        $this->assertEquals("http://wiki.example.com/./lib/tpl/strap/images/favicon-16x16.png", $secondIcon->getAttribute("href"));
699
700        // Apple touch icon
701        $appleIcons = $response->queryHTML('link[rel="apple-touch-icon"]');
702        $this->assertEquals(1, $appleIcons->count());
703        $this->assertEquals("http://wiki.example.com/./lib/tpl/strap/images/apple-touch-icon.png", $appleIcons->attr("href"), "Apple Icon");
704
705    }
706
707    /**
708     * Test that a media page is rendering
709     */
710    public
711    function test_media_manager_php()
712    {
713        $pageId = 'start';
714        saveWikiText($pageId, "Content", 'Script Test base');
715        idx_addPage($pageId);
716
717        $request = new TestRequest();
718        $response = $request->get(array('id' => $pageId, '/mediamanager.php'));
719
720        $generator = $response->queryHTML('meta[name="generator"]')->attr("content");
721        $this->assertEquals("DokuWiki", $generator);
722
723    }
724
725    /**
726     * Test that a railbar is not shown when it's private
727     * @throws Exception
728     */
729    public
730    function test_privateRailbar()
731    {
732        TplUtility::setConf(TplUtility::CONF_PRIVATE_RAIL_BAR, 0);
733
734        $pageId = 'start';
735        saveWikiText($pageId, "Content", 'Script Test base');
736        idx_addPage($pageId);
737
738        $request = new TestRequest();
739        $response = $request->get(array('id' => $pageId, '/doku.php'));
740
741        $toolbarCount = $response->queryHTML('.railbar')->count();
742        $this->assertEquals(2, $toolbarCount);
743
744        // Anonymous user should not see it
745        TplUtility::setConf(TplUtility::CONF_PRIVATE_RAIL_BAR, 1);
746        $request = new TestRequest();
747        $response = $request->get(array('id' => $pageId, '/doku.php'));
748        $toolbarCount = $response->queryHTML('.railbar')->count();
749        $this->assertEquals(0, $toolbarCount);
750
751        // Connected user should see it
752        $request = new TestRequest();
753        $request->setServer('REMOTE_USER', 'auser');
754        $response = $request->get(array('id' => $pageId, '/doku.php'));
755        $toolbarCount = $response->queryHTML('.railbar')->count();
756        $this->assertEquals(2, $toolbarCount);
757
758    }
759
760
761}
762