syntax_plugin_openlayersmap_test   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 132
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 57
dl 0
loc 132
rs 10
c 1
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A test_issue34() 0 4 1
A test_issue34_fixed() 0 15 1
A setUp() 0 12 3
A tearDown() 0 9 2
A test_rur() 0 60 1
A setUpBeforeClass() 0 12 1
1
<?php
2
/*
3
* Copyright (c) 2022 Mark C. Prins <[email protected]>
4
*
5
* Permission to use, copy, modify, and distribute this software for any
6
* purpose with or without fee is hereby granted, provided that the above
7
* copyright notice and this permission notice appear in all copies.
8
*
9
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
*/
17
18
/**
19
 * Syntax tests for the openlayersmap plugin.
20
 *
21
 * @group plugin_openlayersmap
22
 * @group plugins
23
 */
24
class syntax_plugin_openlayersmap_test extends DokuWikiTest {
0 ignored issues
show
Bug introduced by
The type DokuWikiTest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
    protected $pluginsEnabled = array('openlayersmap', 'geophp');
26
27
    /**
28
     * copy data and add pages to the index.
29
     */
30
    public static function setUpBeforeClass(): void {
31
        parent::setUpBeforeClass();
32
        global $conf;
33
        $conf['allowdebug'] = 1;
34
        $conf['dontlog']    = '';
35
        $conf['cachetime']  = -1;
36
37
        $conf['plugin']['openlayersmap']['displayformat']            = 'DD';
38
        $conf['plugin']['openlayersmap']['optionStaticMapGenerator'] = 'local';
39
        $conf['plugin']['openlayersmap']['autoZoomMap']              = 1;
40
41
        TestUtils::rcopy(TMP_DIR, __DIR__ . '/data/');
0 ignored issues
show
Bug introduced by
The constant TMP_DIR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The type TestUtils was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
42
    }
43
44
    final public function setUp(): void {
45
        parent::setUp();
46
47
        global $conf;
48
//        $data              = array();
49
//        search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true));
50
//        foreach($data as $val) {
51
//            idx_addPage($val['id']);
52
//        }
53
        if($conf['allowdebug']) {
54
            if(mkdir(DOKU_TMP_DATA . 'data/log/debug/', 0777, true)) {
0 ignored issues
show
Bug introduced by
The constant DOKU_TMP_DATA was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
55
                touch(DOKU_TMP_DATA . 'data/log/debug/' . date('Y-m-d') . '.log');
56
            }
57
58
        }
59
    }
60
61
    final public function tearDown(): void {
62
        parent::tearDown();
63
64
        global $conf;
65
        // try to get the debug log after running the test, print and clear
66
        if($conf['allowdebug']) {
67
            print "\n";
68
            readfile(DOKU_TMP_DATA . 'data/log/debug/' . date('Y-m-d') . '.log');
0 ignored issues
show
Bug introduced by
The constant DOKU_TMP_DATA was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
69
            unlink(DOKU_TMP_DATA . 'data/log/debug/' . date('Y-m-d') . '.log');
70
        }
71
    }
72
73
    final public function test_rur(): void {
74
        $request  = new TestRequest();
0 ignored issues
show
Bug introduced by
The type TestRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
75
        $response = $request->get(array('id' => 'rur'));
76
        self::assertNotNull($response);
77
78
        $_content = $response->getContent();
79
        self::assertStringContainsString('Rur', $_content);
80
        self::assertStringContainsString('<script defer="defer" src="/lib/plugins/openlayersmap/ol/ol.js"></script>', $_content);
81
        self::assertStringContainsString('<div id="olMap-static" class="olStaticMap">', $_content);
82
        self::assertStringContainsString('<table id="olMap-table" class="olPOItable">', $_content);
83
84
        // <img src="/./lib/exe/fetch.php?w=650&amp;h=550&amp;tok=72bf3a&amp;media=olmapmaps:openstreetmap:13:cache_8b:9b:94cd3dabd2d1c470a2d5b4bea6df.png"
85
        // class="medialeft" loading="lazy" title="Rur parkings " alt="Rur parkings " width="650" height="550" />
86
        $_staticImage = $response->queryHTML('img[src*="olmapmaps:openstreetmap:13:cache_8b:9b:94cd3dabd2d1c470a2d5b4bea6df.png"]');
87
        self::assertNotEmpty($_staticImage);
88
        self::assertEquals('medialeft', $_staticImage->attr('class'));
89
        self::assertEquals('650', $_staticImage->attr('width'));
90
        self::assertEquals('550', $_staticImage->attr('height'));
91
        self::assertStringContainsString('Rur parkings', $_staticImage->attr('title'));
92
93
        // <div class="olPOItableSpan" id="olMap-table-span">\n
94
        //    <table class="olPOItable" id="olMap-table">\n
95
        //    <caption class="olPOITblCaption">Points of Interest</caption>\n
96
        //    <thead class="olPOITblHeader">\n
97
        //    <tr>\n
98
        //    <th class="rowId" scope="col">id</th>\n
99
        //    <th class="icon" scope="col">symbol</th>\n
100
        //    <th class="lat" scope="col" title="latitude in decimal degrees">latitude</th>\n
101
        //    <th class="lon" scope="col" title="longitude in decimal degrees">longitude</th>\n
102
        //    <th class="txt" scope="col">description</th>\n
103
        //    </tr>\n
104
        //    </thead><tfoot class="olPOITblFooter"><tr><td colspan="5">Rur parkings</td></tr></tfoot><tbody class="olPOITblBody">\n
105
        //    <tr>\n
106
        //    <td class="rowId">1</td>\n
107
        //    <td class="icon"><img src="/./lib/plugins/openlayersmap/icons/parking.png" alt="parking" /></td>\n
108
        //    <td class="lat" title="latitude in decimal degrees">50.548611º</td>\n
109
        //    <td class="lon" title="longitude in decimal degrees">6.228889º</td>\n
110
        //    <td class="txt"><p>Parking Dreistegen</p></td>\n
111
        //    </tr>\n
112
        //    <tr>\n
113
        //    <td class="rowId">2</td>\n
114
        //    <td class="icon"><img src="/./lib/plugins/openlayersmap/icons/parking.png" alt="parking" /></td>\n
115
        //    <td class="lat" title="latitude in decimal degrees">50.56384º</td>\n
116
        //    <td class="lon" title="longitude in decimal degrees">6.29766º</td>\n
117
        //    <td class="txt"><p>Parking Grünenthalstrasse</p></td>\n
118
        //    </tr></tbody>\n
119
        //    </table>\n
120
        // </div>\n
121
122
        $_latCells = $response->queryHTML('td[class="lat"]');
123
        self::assertNotEmpty($_latCells);
124
        // not available in "stable"
125
        // self::assertEquals('50.548611º', $_latCells->first()->text());
126
        self::assertEquals('50.548611º', $_latCells->get(0)->textContent);
127
128
        $_lonCells = $response->queryHTML('td[class="lon"]');
129
        self::assertNotEmpty($_lonCells);
130
        // not available in "stable"
131
        // self::assertEquals('6.29766º', $_lonCells->last()->text());
132
        self::assertEquals('6.29766º', $_lonCells->get(1)->textContent);
133
    }
134
135
    final public function test_issue34(): void {
136
        $request  = new TestRequest();
137
        $response = $request->get(array('id' => 'issue34'));
138
        self::assertNotNull($response);
139
    }
140
141
    final public function test_issue34_fixed(): void {
142
        $request  = new TestRequest();
143
        $response = $request->get(array('id' => 'issue34-fixed'));
144
        self::assertNotNull($response);
145
146
        $_content = $response->getContent();
147
        self::assertStringContainsString('issue34-fixed', $_content);
148
        self::assertStringContainsString('<div id="olMap_example-static" class="olStaticMap">', $_content);
149
        self::assertStringContainsString('<table id="olMap_example-table" class="olPOItable">', $_content);
150
151
        $_staticImage = $response->queryHTML('img[src*="olmapmaps:openstreetmap:14:cache_32:12:6533646ecb8cf2f193db46305e5f.png"]');
152
        self::assertNotEmpty($_staticImage);
153
        self::assertEquals('550', $_staticImage->attr('width'));
154
        self::assertEquals('450', $_staticImage->attr('height'));
155
        self::assertEmpty(trim($_staticImage->attr('title')));
156
    }
157
}