1<?php 2/* 3* Copyright (c) 2022 Mark C. Prins <mprins@users.sf.net> 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 */ 24class syntax_plugin_openlayersmap_test extends DokuWikiTest { 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/'); 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)) { 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'); 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(); 75 $response = $request->get(array('id' => 'rur')); 76 77 $_content = $response->getContent(); 78 self::assertStringContainsString('Rur', $_content); 79 self::assertStringContainsString('<script defer="defer" src="/./lib/plugins/openlayersmap/ol7/ol.js"></script>', $_content); 80 self::assertStringContainsString('<div id="olMap-static" class="olStaticMap">', $_content); 81 self::assertStringContainsString('<table class="olPOItable" id="olMap-table">', $_content); 82 83 // image data/media/olmapmaps/openstreetmap/13/cache_8b/9b/94cd3dabd2d1c470a2d5b4bea6df.png should exist 84 // <img src="/./lib/exe/fetch.php?w=650&h=550&tok=72bf3a&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 Hogfather 125 // self::assertEquals('50.548611º', $_latCells->first()->text()); 126 self::assertEquals('50.548611º', $_latCells->get(0)->text()); 127 128 $_lonCells = $response->queryHTML('td[class="lon"]'); 129 self::assertNotEmpty($_lonCells); 130 // not available in Hogfather 131 // self::assertEquals('6.29766º', $_lonCells->last()->text()); 132 self::assertEquals('6.29766º', $_lonCells->get(1)->text()); 133 } 134}