Skip to content

Commit 3ecf038

Browse files
authored
Merge pull request #57 from mprins/issue#56
fix E_WARNING: Undefined array key GPSLatitudeRef / GPSLongitudeRef
2 parents 38adda4 + c8ba6be commit 3ecf038

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed
Loading
127 KB
Loading

_test/general.test.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1515
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1616
*/
17+
namespace dokuwiki\plugin\spatialhelper\test;
1718

19+
use DokuWikiTest;
1820
/**
1921
* General tests for the spatialhelper plugin.
2022
*
@@ -58,7 +60,9 @@ final public function test_plugin_spatialhelper_isloaded(): void
5860
{
5961
global $plugin_controller;
6062
self::assertContains(
61-
'spatialhelper', $plugin_controller->getList(), "spatialhelper plugin is loaded"
63+
'spatialhelper',
64+
$plugin_controller->getList(),
65+
"spatialhelper plugin is loaded"
6266
);
6367
}
6468
}

_test/index.test.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use DokuWikiTest;
66
use helper_plugin_spatialhelper_index;
7+
use TestUtils;
78

89
/**
910
* Tests for the class helper_plugin_spatialhelper_index of the spatialhelper plugin.
@@ -16,6 +17,18 @@ class index_test extends DokuWikiTest
1617

1718
protected $pluginsEnabled = array('spatialhelper');
1819

20+
/**
21+
* copy data and add pages to the index.
22+
*/
23+
public static function setUpBeforeClass(): void
24+
{
25+
parent::setUpBeforeClass();
26+
global $conf;
27+
$conf['allowdebug'] = 1;
28+
29+
TestUtils::rcopy(TMP_DIR, __DIR__ . '/data/');
30+
}
31+
1932
/**
2033
* Testdata for @return array
2134
* @see index_test::test_convertDMStoD
@@ -47,6 +60,15 @@ final public static function convertDMStoDTestdata(): array
4760
);
4861
}
4962

63+
final public function setUp(): void
64+
{
65+
parent::setUp();
66+
67+
global $conf;
68+
$conf['allowdebug'] = 1;
69+
$conf['cachetime'] = -1;
70+
}
71+
5072
/**
5173
* @dataProvider convertDMStoDTestdata
5274
*/
@@ -59,4 +81,27 @@ final public function test_convertDMStoD(array $input, float $expected_output, s
5981

6082
self::assertEqualsWithDelta($expected_output, $actual_output, 0.0001, $msg);
6183
}
84+
85+
final public function test_ImageWithoutGeotag(): void
86+
{
87+
$index = plugin_load('helper', 'spatialhelper_index');
88+
assert($index instanceof helper_plugin_spatialhelper_index);
89+
90+
$actual_output = $index->getCoordsFromExif(':vesder_eupen_no_gps.jpg');
91+
self::assertFalse($actual_output, 'Expected no geotag to be found');
92+
}
93+
94+
final public function test_ImageWithGeotag(): void
95+
{
96+
$index = plugin_load('helper', 'spatialhelper_index');
97+
assert($index instanceof helper_plugin_spatialhelper_index);
98+
99+
// lat/lon: 37°4'36.12",31°39'21.96" or x/y: 31.6561,37.0767
100+
$actual_output = $index->getCoordsFromExif(':manavgat_restaurant_handost_with_gps.jpg');
101+
102+
self::assertNotNull($actual_output, 'Expected a geotag to be found');
103+
self::assertNotFalse($actual_output, 'Expected a geotag to be found');
104+
self::assertEqualsWithDelta(31.6561, $actual_output->x(), 0.0001);
105+
self::assertEqualsWithDelta(37.0767, $actual_output->y(), 0.0001);
106+
}
62107
}

helper/index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ final public function indexImage(string $imgId): bool
240240
final public function getCoordsFromExif(string $id): Point|false
241241
{
242242
$exif = exif_read_data(mediaFN($id), 0, true);
243-
if (empty($exif ['GPS'])) {
243+
if (!$exif || empty($exif ['GPS'])) {
244244
return false;
245245
}
246246

@@ -249,7 +249,7 @@ final public function getCoordsFromExif(string $id): Point|false
249249
$exif ['GPS'] ['GPSLatitude'] [0],
250250
$exif ['GPS'] ['GPSLatitude'] [1],
251251
$exif ['GPS'] ['GPSLatitude'] [2],
252-
$exif ['GPS'] ['GPSLatitudeRef']
252+
$exif ['GPS'] ['GPSLatitudeRef'] ?? 'N'
253253
]
254254
);
255255

@@ -258,7 +258,7 @@ final public function getCoordsFromExif(string $id): Point|false
258258
$exif ['GPS'] ['GPSLongitude'] [0],
259259
$exif ['GPS'] ['GPSLongitude'] [1],
260260
$exif ['GPS'] ['GPSLongitude'] [2],
261-
$exif ['GPS'] ['GPSLongitudeRef']
261+
$exif ['GPS'] ['GPSLongitudeRef'] ?? 'E'
262262
]
263263
);
264264

plugin.info.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
base spatialhelper
22
author Mark C. Prins
33
email mprins@users.sf.net
4-
date 2024-04-08
4+
date 2025-01-31
55
name Spatial Helper plugin for DokuWiki
66
desc Provides spatial indexing and spatial search facilities.
77
url https://www.dokuwiki.org/plugin:spatialhelper

0 commit comments

Comments
 (0)