|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Copyright (c) 2024 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 | + * Tests for the spatialhelper plugin. |
| 20 | + * |
| 21 | + * @group plugin_spatialhelper |
| 22 | + * @group plugins |
| 23 | + * |
| 24 | + * @noinspection AutoloadingIssuesInspection |
| 25 | + * @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps |
| 26 | + */ |
| 27 | +class indexing_test extends DokuWikiTest |
| 28 | +{ |
| 29 | + /** |
| 30 | + * copy data and add pages to the index. |
| 31 | + */ |
| 32 | + public static function setUpBeforeClass(): void |
| 33 | + { |
| 34 | + parent::setUpBeforeClass(); |
| 35 | + TestUtils::rcopy(TMP_DIR, __DIR__ . '/data/'); |
| 36 | + } |
| 37 | + |
| 38 | + final public function setUp(): void |
| 39 | + { |
| 40 | + $this->pluginsEnabled = array( |
| 41 | + 'geophp', |
| 42 | + 'geotag', |
| 43 | + 'spatialhelper' |
| 44 | + ); |
| 45 | + |
| 46 | + global $conf; |
| 47 | + $conf['allowdebug'] = 1; |
| 48 | + $conf['dontlog'] = []; |
| 49 | + $conf['cachetime'] = -1; |
| 50 | + |
| 51 | + parent::setUp(); |
| 52 | + |
| 53 | + $indexer = plugin_load('helper', 'spatialhelper_index'); |
| 54 | + self::assertInstanceOf('helper_plugin_spatialhelper_index', $indexer); |
| 55 | + |
| 56 | + $data = []; |
| 57 | + search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true)); |
| 58 | + |
| 59 | + foreach ($data as $val) { |
| 60 | + idx_addPage($val['id']); |
| 61 | + $indexer->updateSpatialIndex($val['id']); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @throws Exception if anything goes wrong |
| 67 | + */ |
| 68 | + final public function testIndexed(): void |
| 69 | + { |
| 70 | + // render the page |
| 71 | + $request = new TestRequest(); |
| 72 | + $response = $request->get(array('id' => 'geotag')); |
| 73 | + |
| 74 | + // test metadata |
| 75 | + self::assertEquals( |
| 76 | + '52.132633;5.291266;9', |
| 77 | + $response->queryHTML('meta[name="geo.position"]')->attr('content') |
| 78 | + ); |
| 79 | + self::assertEquals( |
| 80 | + '52.132633, 5.291266', |
| 81 | + $response->queryHTML('meta[name="ICBM"]')->attr('content') |
| 82 | + ); |
| 83 | + |
| 84 | + // test the geohash and index values |
| 85 | + self::assertStringStartsWith( |
| 86 | + 'u17b86kyx7jv', |
| 87 | + $response->queryHTML('meta[name="geo.geohash"]')->attr('content') |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + |
| 92 | + final public function testIndexFileExists(): void |
| 93 | + { |
| 94 | + self::assertFileExists(TMP_DIR . '/data/index/spatial.idx'); |
| 95 | + } |
| 96 | + |
| 97 | + final public function testIndexFileNotEmpty(): void |
| 98 | + { |
| 99 | + self::assertGreaterThan(0, filesize(TMP_DIR . '/data/index/spatial.idx')); |
| 100 | + } |
| 101 | + |
| 102 | + final public function testSearchNearby(): void |
| 103 | + { |
| 104 | + $search = plugin_load('helper', 'spatialhelper_search'); |
| 105 | + self::assertInstanceOf('helper_plugin_spatialhelper_search', $search); |
| 106 | + |
| 107 | + $result = $search->findNearby('u17b86kyx7'); |
| 108 | + self::assertIsArray($result); |
| 109 | + self::assertNotEmpty($result); |
| 110 | + self::assertEmpty($result['media']); |
| 111 | + self::assertEquals('geotag', $result['pages'][0]['id']); |
| 112 | + self::assertEquals('u17b86kyx7', $result['geohash']); |
| 113 | + self::assertEquals(0.6, $result['precision']); |
| 114 | + self::assertEqualsWithDelta(52.1326, $result['lat'], 0.001); |
| 115 | + self::assertEqualsWithDelta(5.2912, $result['lon'], 0.001); |
| 116 | + } |
| 117 | +} |
0 commit comments