1<?php
2
3
4class action_plugin_piwiktagmanagerTest extends DokuWikiTest
5{
6
7    const pwtmPluginName = 'piwiktagmanager';
8
9    public function setUp()
10    {
11        $this->pluginsEnabled[] = self::pwtmPluginName;
12        parent::setUp();
13    }
14
15    public function test_piwik_tag_manager()
16    {
17
18        global $conf;
19        $pwtmValue = "Xabcdef";
20        $pwtmHostValue = "piwik.lehmann.cx";
21        $conf['plugin'][self::pwtmPluginName][action_plugin_piwiktagmanager::PWTMID] = $pwtmValue;
22        $conf['plugin'][self::pwtmPluginName][action_plugin_piwiktagmanager::PWTMHOST] = $pwtmHostValue;
23
24        $pageId = 'start';
25        saveWikiText($pageId, "Content", 'Script Test base');
26        idx_addPage($pageId);
27
28        $request = new TestRequest();
29        $response = $request->get(array('id' => $pageId, '/doku.php'));
30
31        /**
32         * Tags to searched
33         */
34        $tagsSearched = ["script", "noscript"];
35
36        foreach ($tagsSearched as $tagSearched) {
37
38            $domElements = $response->queryHTML($tagSearched)->get();
39
40            $patternFound = 0;
41            foreach ($domElements as $domElement) {
42                /**
43                 * @var DOMElement $domElement
44                 */
45                if ($tagSearched=="script") {
46                    $value = $domElement->textContent;
47                } else {
48                    // iframe src
49                    $value = $domElement->firstChild->getAttribute("src");
50                }
51                $patternFound = preg_match("/$pwtmValue/i", $value);
52                if ($patternFound === 1) {
53                    break;
54                }
55            }
56            $this->assertEquals(1, $patternFound, "The piwik scripts have been found for the tag $tagSearched");
57        }
58
59
60    }
61
62}
63