summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Maps/tests
diff options
context:
space:
mode:
authorYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
committerYaco <franco@reevo.org>2020-06-04 11:01:00 -0300
commitfc7369835258467bf97eb64f184b93691f9a9fd5 (patch)
treedaabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/extensions/Maps/tests
first commit
Diffstat (limited to 'www/wiki/extensions/Maps/tests')
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/DataAccess/MediaWikiFileUrlFinderTest.php33
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/InitializationTest.php20
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/MapsDistanceParserTest.php177
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/MapsMapperTest.php42
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/CoordinatesTest.php125
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/DistanceTest.php91
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/FinddestinationTest.php94
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/GeocodeTest.php64
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/GeodistanceTest.php81
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/MapsDocTest.php54
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/ParserHookTest.php133
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/Parser/CoordinatesTest.php96
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/Parser/DisplayMapTest.php220
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/Semantic/ValueDescriptions/AreaDescriptionTest.php81
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/parsers/CircleParserTest.php43
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/parsers/DistanceParserTest.php66
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/parsers/JsonFileParserTest.php120
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/parsers/LineParserTest.php77
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/parsers/LocationParserTest.php119
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/parsers/RectlangleParserTest.php44
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/parsers/WmsOverlayParserTest.php54
-rw-r--r--www/wiki/extensions/Maps/tests/System/SemanticMW/MapQueryTest.php93
-rw-r--r--www/wiki/extensions/Maps/tests/Unit/Elements/BaseElementTest.php85
-rw-r--r--www/wiki/extensions/Maps/tests/Unit/Elements/CircleTest.php70
-rw-r--r--www/wiki/extensions/Maps/tests/Unit/Elements/ImageOverlayTest.php52
-rw-r--r--www/wiki/extensions/Maps/tests/Unit/Elements/LineTest.php74
-rw-r--r--www/wiki/extensions/Maps/tests/Unit/Elements/LocationTest.php36
-rw-r--r--www/wiki/extensions/Maps/tests/Unit/Elements/PolygonTest.php68
-rw-r--r--www/wiki/extensions/Maps/tests/Unit/Elements/RectangleTest.php73
-rw-r--r--www/wiki/extensions/Maps/tests/Unit/Presentation/KmlFormatterTest.php88
-rw-r--r--www/wiki/extensions/Maps/tests/Unit/Presentation/ParameterExtractorTest.php80
-rw-r--r--www/wiki/extensions/Maps/tests/Unit/Semantic/DataValues/CoordinateValueTest.php113
-rw-r--r--www/wiki/extensions/Maps/tests/Util/PageCreator.php24
-rw-r--r--www/wiki/extensions/Maps/tests/Util/TestFactory.php21
-rw-r--r--www/wiki/extensions/Maps/tests/bootstrap.php33
35 files changed, 2744 insertions, 0 deletions
diff --git a/www/wiki/extensions/Maps/tests/Integration/DataAccess/MediaWikiFileUrlFinderTest.php b/www/wiki/extensions/Maps/tests/Integration/DataAccess/MediaWikiFileUrlFinderTest.php
new file mode 100644
index 00000000..648c8c94
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/DataAccess/MediaWikiFileUrlFinderTest.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Maps\Tests\Integration\DataAccess;
+
+use Maps\DataAccess\MediaWikiFileUrlFinder;
+use Maps\FileUrlFinder;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @covers \Maps\DataAccess\MediaWikiFileUrlFinder
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class MediaWikiFileUrlFinderTest extends TestCase {
+
+ /**
+ * @var FileUrlFinder
+ */
+ private $urlFinder;
+
+ public function setUp() {
+ $this->urlFinder = new MediaWikiFileUrlFinder();
+ }
+
+ public function testGivenUrl_urlIsReturnedAsProvided() {
+ $this->assertSame(
+ 'http://example.com/such',
+ $this->urlFinder->getUrlForFileName( 'http://example.com/such' )
+ );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/InitializationTest.php b/www/wiki/extensions/Maps/tests/Integration/InitializationTest.php
new file mode 100644
index 00000000..5d94e291
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/InitializationTest.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace Maps\Tests\Integration;
+
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class InitializationTest extends TestCase {
+
+ public function testVersionConstantIsDefined() {
+ $this->assertInternalType( 'string', Maps_VERSION );
+ $this->assertInternalType( 'string', SM_VERSION );
+ $this->assertSame( Maps_VERSION, SM_VERSION );
+ $this->assertNotEmpty( Maps_VERSION );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/MapsDistanceParserTest.php b/www/wiki/extensions/Maps/tests/Integration/MapsDistanceParserTest.php
new file mode 100644
index 00000000..e5b04787
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/MapsDistanceParserTest.php
@@ -0,0 +1,177 @@
+<?php
+
+namespace Maps\Tests\Integration;
+
+use Maps\Presentation\MapsDistanceParser;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @covers MapsDistanceParser
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class MapsDistanceParserTest extends TestCase {
+
+ public static $distances = [
+ '1' => 1,
+ '1m' => 1,
+ '1 m' => 1,
+ ' 1 m ' => 1,
+ '1.1' => 1.1,
+ '1,1' => 1.1,
+ '1 km' => 1000,
+ '42 km' => 42000,
+ '4.2 km' => 4200,
+ '4,20km' => 4200,
+ '1 mile' => 1609.344,
+ '10 nauticalmiles' => 18520,
+ '1.0nautical mile' => 1852,
+ ];
+ public static $formatTests = [
+ 'm' => [
+ '1 m' => 1,
+ '1000 m' => 1000.00,
+ '42.42 m' => 42.42,
+ '42.4242 m' => 42.4242,
+ ],
+ 'km' => [
+ //'0.001 km' => 1,
+ '1 km' => 1000,
+ '4.24 km' => 4242,
+ ],
+ 'kilometers' => [
+ '0.001 kilometers' => 1,
+ '1 kilometers' => 1000,
+ '4.24 kilometers' => 4242,
+ ],
+ ];
+ /**
+ * Invalid distances.
+ *
+ * @var array
+ */
+ public static $fakeDistances = [
+ 'IN YOUR CODE, BEING TOTALLY RIDICULOUS',
+ '0x20 km',
+ 'km 42',
+ '42 42 km',
+ '42 km km',
+ '42 foo',
+ '3.4.2 km'
+ ];
+
+ public function setUp() {
+ if ( !defined( 'MEDIAWIKI' ) ) {
+ $this->markTestSkipped( 'MediaWiki is not available' );
+ }
+ }
+
+ /**
+ * Tests Maps\Presentation\MapsDistanceParser::parseDistance()
+ */
+ public function testParseDistance() {
+ foreach ( self::$distances as $rawValue => $parsedValue ) {
+ $this->assertEquals(
+ $parsedValue,
+ MapsDistanceParser::parseDistance( $rawValue ),
+ "'$rawValue' was not parsed to '$parsedValue':"
+ );
+ }
+
+ foreach ( self::$fakeDistances as $fakeDistance ) {
+ $this->assertFalse(
+ MapsDistanceParser::parseDistance( $fakeDistance ),
+ "'$fakeDistance' should not be recognized:"
+ );
+ }
+ }
+
+ /**
+ * Tests Maps\Presentation\MapsDistanceParser::formatDistance()
+ */
+ public function testFormatDistance() {
+ foreach ( self::$formatTests['km'] as $rawValue => $parsedValue ) {
+ $this->assertEquals(
+ $rawValue,
+ MapsDistanceParser::formatDistance( $parsedValue, 'km' ),
+ "'$parsedValue' was not formatted to '$rawValue':"
+ );
+ }
+ }
+
+ /**
+ * Tests Maps\Presentation\MapsDistanceParser::parseAndFormat()
+ */
+ public function testParseAndFormat() {
+ $conversions = [
+ '42 km' => '42000 m'
+ ];
+
+ foreach ( array_merge( $conversions, array_reverse( $conversions ) ) as $source => $target ) {
+ global $wgContLang;
+ $unit = explode( ' ', $target, 2 );
+ $unit = $unit[1];
+ $this->assertEquals(
+ $wgContLang->formatNum( $target ),
+ MapsDistanceParser::parseAndFormat( $source, $unit ),
+ "'$source' was not parsed and formatted to '$target':"
+ );
+ }
+ }
+
+ /**
+ * Tests Maps\Presentation\MapsDistanceParser::isDistance()
+ */
+ public function testIsDistance() {
+ foreach ( self::$fakeDistances as $fakeDistance ) {
+ $this->assertFalse(
+ MapsDistanceParser::isDistance( $fakeDistance ),
+ "'$fakeDistance' should not be recognized:"
+ );
+ }
+
+ foreach ( self::$distances as $distance ) {
+ $this->assertTrue( MapsDistanceParser::isDistance( $distance ), "'$distance' was not be recognized:" );
+ }
+ }
+
+ /**
+ * Tests Maps\Presentation\MapsDistanceParser::getUnitRatio()
+ */
+ public function testGetUnitRatio() {
+ foreach ( $GLOBALS['egMapsDistanceUnits'] as $unit => $ratio ) {
+ $r = MapsDistanceParser::getUnitRatio( $unit );
+ $this->assertEquals( $ratio, $r, "The ratio for '$unit' should be '$ratio' but was '$r'" );
+ }
+ }
+
+ /**
+ * Tests Maps\Presentation\MapsDistanceParser::getValidUnit()
+ */
+ public function testGetValidUnit() {
+ foreach ( $GLOBALS['egMapsDistanceUnits'] as $unit => $ratio ) {
+ $u = MapsDistanceParser::getValidUnit( $unit );
+ $this->assertEquals( $unit, $u, "The valid unit for '$unit' should be '$unit' but was '$u'" );
+ }
+
+ global $egMapsDistanceUnit;
+
+ foreach ( [ '0', 'swfwdffdhy', 'dxwgdrfh' ] as $unit ) {
+ $u = MapsDistanceParser::getValidUnit( $unit );
+ $this->assertEquals(
+ $egMapsDistanceUnit,
+ $u,
+ "The valid unit for '$unit' should be '$egMapsDistanceUnit' but was '$u'"
+ );
+ }
+ }
+
+ /**
+ * Tests Maps\Presentation\MapsDistanceParser::getUnits()
+ */
+ public function testGetUnits() {
+ $this->assertEquals( array_keys( $GLOBALS['egMapsDistanceUnits'] ), MapsDistanceParser::getUnits() );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/MapsMapperTest.php b/www/wiki/extensions/Maps/tests/Integration/MapsMapperTest.php
new file mode 100644
index 00000000..4760db5f
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/MapsMapperTest.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace Maps\Tests\Integration;
+
+use Maps\MapsFunctions;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @covers MapsFunctions
+ *
+ * @licence GNU GPL v2+
+ * @author Peter Grassberger < petertheone@gmail.com >
+ */
+class MapsMapperTest extends TestCase {
+
+ public function setUp() {
+ if ( !defined( 'MEDIAWIKI' ) ) {
+ $this->markTestSkipped( 'MediaWiki is not available' );
+ }
+ }
+
+ public function imageUrlProvider() {
+ return [
+ [ 'markerImage.png', 'markerImage.png' ],
+ [ '/w/images/c/ce/Green_marker.png', '/w/images/c/ce/Green_marker.png' ],
+ [
+ '//semantic-mediawiki.org/w/images/c/ce/Green_marker.png',
+ '//semantic-mediawiki.org/w/images/c/ce/Green_marker.png'
+ ],
+ [ 'Cat2.jpg', 'Cat2.jpg' ],
+ ];
+ }
+
+ /**
+ * Tests MapsMapperTest::getFileUrl()
+ *
+ * @dataProvider imageUrlProvider
+ */
+ public function testGetFileUrl( $file, $expected ) {
+ $this->assertSame( $expected, MapsFunctions::getFileUrl( $file ) );
+ }
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/CoordinatesTest.php b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/CoordinatesTest.php
new file mode 100644
index 00000000..9ee324fe
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/CoordinatesTest.php
@@ -0,0 +1,125 @@
+<?php
+
+namespace Maps\Tests\Integration\MediaWiki\ParserHooks;
+
+use DataValues\Geo\Values\LatLongValue;
+use Maps\MediaWiki\ParserHooks\CoordinatesFunction;
+use ParamProcessor\ParamDefinition;
+
+/**
+ * @covers CoordinatesFunction
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class CoordinatesTest extends ParserHookTest {
+
+ /**
+ * @see ParserHookTest::parametersProvider
+ */
+ public function parametersProvider() {
+ $paramLists = [];
+
+ $paramLists[] = [
+ [
+ 'location' => '4,2',
+ 'format' => 'dms',
+ 'directional' => 'no',
+ ],
+ '4° 0\' 0.00", 2° 0\' 0.00"'
+ ];
+
+ $paramLists[] = [
+ [
+ 'location' => '55 S, 37.6176330 W',
+ 'format' => 'dms',
+ 'directional' => 'no',
+ ],
+ '-55° 0\' 0.00", -37° 37\' 3.48"'
+ ];
+
+ $paramLists[] = [
+ [
+ 'location' => '4,2',
+ 'format' => 'float',
+ 'directional' => 'no',
+ ],
+ '4, 2'
+ ];
+
+ $paramLists[] = [
+ [
+ 'location' => '-4,-2',
+ 'format' => 'float',
+ 'directional' => 'yes',
+ ],
+ '4 S, 2 W'
+ ];
+
+ $paramLists[] = [
+ [
+ 'location' => '55 S, 37.6176330 W',
+ 'directional' => 'yes',
+ ],
+ '55° 0\' 0.00" S, 37° 37\' 3.48" W'
+ ];
+
+ return $paramLists;
+ }
+
+ /**
+ * @see ParserHookTest::processingProvider
+ */
+ public function processingProvider() {
+ $definitions = ParamDefinition::getCleanDefinitions( $this->getInstance()->getParamDefinitions() );
+ $argLists = [];
+
+ $values = [
+ 'location' => '4,2',
+ ];
+
+ $expected = [
+ 'location' => new LatLongValue( 4, 2 ),
+ ];
+
+ $argLists[] = [ $values, $expected ];
+
+ $values = [
+ 'location' => '4,2',
+ 'directional' => $definitions['directional']->getDefault() ? 'no' : 'yes',
+ 'format' => 'dd',
+ ];
+
+ $expected = [
+ 'location' => new LatLongValue( 4, 2 ),
+ 'directional' => !$definitions['directional']->getDefault(),
+ 'format' => 'dd',
+ ];
+
+ $argLists[] = [ $values, $expected ];
+
+ $values = [
+ 'location' => '4,2',
+ 'directional' => $definitions['directional']->getDefault() ? 'NO' : 'YES',
+ 'format' => ' DD ',
+ ];
+
+ $expected = [
+ 'location' => new LatLongValue( 4, 2 ),
+ 'directional' => !$definitions['directional']->getDefault(),
+ 'format' => 'dd',
+ ];
+
+ $argLists[] = [ $values, $expected ];
+
+ return $argLists;
+ }
+
+ /**
+ * @see ParserHookTest::getInstance
+ */
+ protected function getInstance() {
+ return new \Maps\MediaWiki\ParserHooks\CoordinatesFunction();
+ }
+
+} \ No newline at end of file
diff --git a/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/DistanceTest.php b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/DistanceTest.php
new file mode 100644
index 00000000..3e3889c8
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/DistanceTest.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace Maps\Tests\Integration\MediaWiki\ParserHooks;
+
+use Maps\MediaWiki\ParserHooks\DistanceFunction;
+
+/**
+ * @covers DistanceFunction
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class DistanceTest extends ParserHookTest {
+
+ private $distances = [
+ '42' => 42,
+ '42m' => 42,
+ '42 m' => 42,
+ '42 km' => 42000,
+ '4.2 km' => 4200,
+ '4.2 m' => 4.2,
+ ];
+
+ /**
+ * @see ParserHookTest::parametersProvider
+ */
+ public function parametersProvider() {
+ $paramLists = [];
+
+ foreach ( array_keys( $this->distances ) as $distance ) {
+ $paramLists[] = [ 'distance' => (string)$distance ];
+ }
+
+ return $this->arrayWrap( $paramLists );
+ }
+
+ /**
+ * @see ParserHookTest::processingProvider
+ */
+ public function processingProvider() {
+ $argLists = [];
+
+ foreach ( $this->distances as $input => $output ) {
+ $values = [
+ 'distance' => (string)$input,
+ ];
+
+ $expected = [
+ 'distance' => $output,
+ ];
+
+ $argLists[] = [ $values, $expected ];
+ }
+
+ $values = [
+ 'distance' => '42m',
+ 'unit' => 'km',
+ 'decimals' => '1',
+ ];
+
+ $expected = [
+ 'distance' => 42,
+ 'unit' => 'km',
+ 'decimals' => 1,
+ ];
+
+ $argLists[] = [ $values, $expected ];
+
+ $values = [
+ 'distance' => '42m',
+ 'unit' => '~=[,,_,,]:3',
+ 'decimals' => 'foobar',
+ ];
+
+ $expected = [
+ 'distance' => 42,
+ ];
+
+ $argLists[] = [ $values, $expected ];
+
+ return $argLists;
+ }
+
+ /**
+ * @see ParserHookTest::getInstance
+ */
+ protected function getInstance() {
+ return new \Maps\MediaWiki\ParserHooks\DistanceFunction();
+ }
+
+} \ No newline at end of file
diff --git a/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/FinddestinationTest.php b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/FinddestinationTest.php
new file mode 100644
index 00000000..811d16e2
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/FinddestinationTest.php
@@ -0,0 +1,94 @@
+<?php
+
+namespace Maps\Tests\Integration\MediaWiki\ParserHooks;
+
+use DataValues\Geo\Parsers\LatLongParser;
+use Maps\Elements\Location;
+use Maps\MediaWiki\ParserHooks\FindDestinationFunction;
+
+/**
+ * @covers FindDestinationFunction
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class FinddestinationTest extends ParserHookTest {
+
+ /**
+ * @var string[]
+ */
+ private $locations = [
+ '4,2',
+ '4.2,-42',
+ ];
+
+ private $bearings = [
+ 1,
+ 42,
+ -42,
+ 0,
+ 4.2,
+ ];
+
+ private $distances = [
+ '42' => 42,
+ '0' => 0,
+ '42 m' => 42,
+ '42 km' => 42000,
+ '4.2 km' => 4200,
+ ];
+
+ /**
+ * @see ParserHookTest::parametersProvider
+ */
+ public function parametersProvider() {
+ $paramLists = [];
+
+ $paramLists[] = [
+ 'location' => '4,2',
+ 'bearing' => '1',
+ 'distance' => '42 km'
+ ];
+
+ return $this->arrayWrap( $paramLists );
+ }
+
+ /**
+ * @see ParserHookTest::processingProvider
+ */
+ public function processingProvider() {
+ $argLists = [];
+
+ $coordinateParser = new LatLongParser();
+
+ foreach ( $this->distances as $distance => $expectedDistance ) {
+ foreach ( $this->bearings as $bearing ) {
+ foreach ( $this->locations as $locationString ) {
+ $values = [
+ 'distance' => (string)$distance,
+ 'bearing' => (string)$bearing,
+ 'location' => (string)$locationString,
+ ];
+
+ $expected = [
+ 'distance' => $expectedDistance,
+ 'bearing' => (float)$bearing,
+ 'location' => new Location( $coordinateParser->parse( $locationString )->getValue() ),
+ ];
+
+ $argLists[] = [ $values, $expected ];
+ }
+ }
+ }
+
+ return $argLists;
+ }
+
+ /**
+ * @see ParserHookTest::getInstance
+ */
+ protected function getInstance() {
+ return new \Maps\MediaWiki\ParserHooks\FindDestinationFunction();
+ }
+
+} \ No newline at end of file
diff --git a/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/GeocodeTest.php b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/GeocodeTest.php
new file mode 100644
index 00000000..0469650c
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/GeocodeTest.php
@@ -0,0 +1,64 @@
+<?php
+
+namespace Maps\Tests\Integration\MediaWiki\ParserHooks;
+
+use DataValues\Geo\Values\LatLongValue;
+use Jeroen\SimpleGeocoder\Geocoders\InMemoryGeocoder;
+use Maps\MediaWiki\ParserHooks\GeocodeFunction;
+
+/**
+ * @covers GeocodeFunction
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class GeocodeTest extends ParserHookTest {
+
+ /**
+ * @see ParserHookTest::parametersProvider
+ */
+ public function parametersProvider() {
+ $paramLists = [];
+
+ $paramLists[] = [ 'location' => 'New York', '4, 2' ];
+ $paramLists[] = [ 'location' => 'Brussels', '2, 3' ];
+ $paramLists[] = [ 'location' => 'I am a tomato', 'Geocoding failed' ];
+
+ return $this->arrayWrap( $paramLists );
+ }
+
+ /**
+ * @see ParserHookTest::processingProvider
+ */
+ public function processingProvider() {
+ $argLists = [];
+
+ $argLists[] = [
+ [
+ 'location' => '4,2',
+ 'directional' => 'yes',
+ ],
+ [
+ 'location' => '4,2',
+ 'directional' => true,
+ ]
+ ];
+
+ return $argLists;
+ }
+
+ /**
+ * @see ParserHookTest::getInstance
+ */
+ protected function getInstance() {
+ return new \Maps\MediaWiki\ParserHooks\GeocodeFunction(
+ new InMemoryGeocoder(
+ [
+ 'New York' => new LatLongValue( 4, 2 ),
+ 'Brussels' => new LatLongValue( 2, 3 ),
+ ]
+ )
+ );
+ }
+
+} \ No newline at end of file
diff --git a/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/GeodistanceTest.php b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/GeodistanceTest.php
new file mode 100644
index 00000000..59489371
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/GeodistanceTest.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Maps\Tests\Integration\MediaWiki\ParserHooks;
+
+use DataValues\Geo\Values\LatLongValue;
+use Maps\Elements\Location;
+use Maps\MediaWiki\ParserHooks\GeoDistanceFunction;
+
+/**
+ * @covers GeoDistanceFunction
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class GeodistanceTest extends ParserHookTest {
+
+ /**
+ * @see ParserHookTest::parametersProvider
+ */
+ public function parametersProvider() {
+ $paramLists = [];
+
+ $paramLists[] = [
+ 'location1' => '4,2',
+ 'location2' => '42,0',
+ ];
+
+ $paramLists[] = [
+ '4,2',
+ '42,0',
+ ];
+
+ return $this->arrayWrap( $paramLists );
+ }
+
+ /**
+ * @see ParserHookTest::processingProvider
+ * @since 3.0
+ * @return array
+ */
+ public function processingProvider() {
+ $argLists = [];
+
+ $values = [
+ 'location1' => '4,2',
+ 'location2' => '42,0',
+ ];
+
+ $expected = [
+ 'location1' => new Location( new LatLongValue( 4, 2 ) ),
+ 'location2' => new Location( new LatLongValue( 42, 0 ) ),
+ ];
+
+ $argLists[] = [ $values, $expected ];
+
+ $values = [
+ 'location1' => '4,2',
+ 'location2' => '42,0',
+ 'unit' => '~=[,,_,,]:3',
+ 'decimals' => '1',
+ ];
+
+ $expected = [
+ 'location1' => new Location( new LatLongValue( 4, 2 ) ),
+ 'location2' => new Location( new LatLongValue( 42, 0 ) ),
+ 'decimals' => 1,
+ ];
+
+ $argLists[] = [ $values, $expected ];
+
+ return $argLists;
+ }
+
+ /**
+ * @see ParserHookTest::getInstance
+ */
+ protected function getInstance() {
+ return new \Maps\MediaWiki\ParserHooks\GeoDistanceFunction();
+ }
+
+} \ No newline at end of file
diff --git a/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/MapsDocTest.php b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/MapsDocTest.php
new file mode 100644
index 00000000..96a06ca7
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/MapsDocTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Maps\Tests\Integration\MediaWiki\ParserHooks;
+
+use Maps\MediaWiki\ParserHooks\MapsDocFunction;
+
+/**
+ * @covers MapsDocFunction
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class MapsDocTest extends ParserHookTest {
+
+ /**
+ * @see ParserHookTest::parametersProvider
+ */
+ public function parametersProvider() {
+ $paramLists = [];
+
+ $paramLists[] = [];
+
+ return $this->arrayWrap( $paramLists );
+ }
+
+ /**
+ * @see ParserHookTest::processingProvider
+ */
+ public function processingProvider() {
+ $argLists = [];
+
+ $values = [ 'service' => 'googlemaps3' ];
+
+ $expected = [ 'service' => 'googlemaps3' ];
+
+ $argLists[] = [ $values, $expected ];
+
+ $values = [ 'service' => 'GOOGLEmaps3' ];
+
+ $expected = [ 'service' => 'googlemaps3' ];
+
+ $argLists[] = [ $values, $expected ];
+
+ return $argLists;
+ }
+
+ /**
+ * @see ParserHookTest::getInstance
+ */
+ protected function getInstance() {
+ return new \Maps\MediaWiki\ParserHooks\MapsDocFunction();
+ }
+
+} \ No newline at end of file
diff --git a/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/ParserHookTest.php b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/ParserHookTest.php
new file mode 100644
index 00000000..eeb19d61
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/ParserHookTest.php
@@ -0,0 +1,133 @@
+<?php
+
+namespace Maps\Tests\Integration\MediaWiki\ParserHooks;
+
+use ParamProcessor\ParamDefinition;
+use ParamProcessor\Processor;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+abstract class ParserHookTest extends TestCase {
+
+ public static function setUpBeforeClass() {
+ if ( !defined( 'MEDIAWIKI' ) ) {
+ self::markTestSkipped( 'MediaWiki is not available' );
+ }
+ }
+
+ /**
+ * @since 2.0
+ * @return array
+ */
+ public abstract function parametersProvider();
+
+ /**
+ * Triggers the render process with different sets of parameters to see if
+ * no errors or notices are thrown and the result indeed is a string.
+ *
+ * @dataProvider parametersProvider
+ * @since 2.0
+ *
+ * @param array $parameters
+ * @param string|null $expected
+ */
+ public function testRender( array $parameters, $expected = null ) {
+ $parserHook = $this->getInstance();
+
+ $parser = new \Parser();
+ $parser->mOptions = new \ParserOptions();
+ $parser->clearState();
+ $parser->setTitle( \Title::newMainPage() );
+
+ $renderResult = call_user_func_array(
+ [ $parserHook, 'renderFunction' ],
+ array_merge( [ &$parser ], $parameters )
+ );
+
+ if ( is_string( $renderResult ) ) {
+ $this->assertTrue( true );
+ } else {
+ $this->assertInternalType( 'array', $renderResult );
+ $this->assertInternalType( 'string', $renderResult[0] );
+ }
+
+ if ( $expected !== null ) {
+ $this->assertEquals( $expected, $renderResult[0] );
+ }
+ }
+
+ /**
+ * @since 2.0
+ * @return \ParserHook
+ */
+ protected abstract function getInstance();
+
+ public function processingProvider() {
+ return [];
+ }
+
+ /**
+ * @dataProvider processingProvider
+ * @since 3.0
+ */
+ public function testParamProcessing( array $parameters, array $expectedValues ) {
+ $definitions = $this->getInstance()->getParamDefinitions();
+
+ $processor = Processor::newDefault();
+ $processor->setParameters( $parameters, $definitions );
+
+ $result = $processor->processParameters();
+
+ if ( $result->hasFatal() ) {
+ $this->fail(
+ 'Fatal error occurred during the param processing: ' . $processor->hasFatalError()->getMessage()
+ );
+ }
+
+ $actual = $result->getParameters();
+
+ $expectedValues = array_merge( $this->getDefaultValues(), $expectedValues );
+
+ foreach ( $expectedValues as $name => $expected ) {
+ $this->assertArrayHasKey( $name, $actual );
+
+ $this->assertEquals(
+ $expected,
+ $actual[$name]->getValue(),
+ 'Expected ' . var_export( $expected, true )
+ . ' should match actual '
+ . var_export( $actual[$name]->getValue(), true )
+ );
+ }
+ }
+
+ /**
+ * Returns an array with the default values of the parameters.
+ */
+ private function getDefaultValues() {
+ $definitions = ParamDefinition::getCleanDefinitions( $this->getInstance()->getParamDefinitions() );
+
+ $defaults = [];
+
+ foreach ( $definitions as $definition ) {
+ if ( !$definition->isRequired() ) {
+ $defaults[$definition->getName()] = $definition->getDefault();
+ }
+ }
+
+ return $defaults;
+ }
+
+ protected function arrayWrap( array $elements ) {
+ return array_map(
+ function ( $element ) {
+ return [ $element ];
+ },
+ $elements
+ );
+ }
+
+} \ No newline at end of file
diff --git a/www/wiki/extensions/Maps/tests/Integration/Parser/CoordinatesTest.php b/www/wiki/extensions/Maps/tests/Integration/Parser/CoordinatesTest.php
new file mode 100644
index 00000000..4ec71630
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/Parser/CoordinatesTest.php
@@ -0,0 +1,96 @@
+<?php
+
+namespace Maps\Tests\Integration\Parser;
+
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class CoordinatesTest extends TestCase {
+
+ private function parse( string $textToParse ): string {
+ $parser = new \Parser();
+
+ return $parser->parse( $textToParse, \Title::newMainPage(), new \ParserOptions() )->getText();
+ }
+
+ public function testGivenInvalidCoordinates_errorIsShown() {
+ $this->assertContains(
+ '<span class="errorbox">',
+ $this->parse( '{{#coordinates:nope}}' )
+ );
+ }
+
+ public function testGivenNoCoordinates_errorIsShown() {
+ $this->assertContains(
+ '<span class="errorbox">',
+ $this->parse( '{{#coordinates:}}' )
+ );
+ }
+
+ public function testGivenValidCoordinates_theyAreFormatted() {
+ $this->assertContains(
+ '1° 0\' 0.00" N, 1° 0\' 0.00" E',
+ $this->parse( '{{#coordinates:1,1}}' )
+ );
+ }
+
+ public function testGivenFormat_coordinatesAreConvertedToIt() {
+ $this->assertContains(
+ '1.000000° N, 1.000000° E',
+ $this->parse( '{{#coordinates:1,1|format=dd}}' )
+ );
+ }
+
+ public function testGivenDirectionalParameter_itGetsUsed() {
+ $this->assertContains(
+ '1° 0\' 0.00", 1° 0\' 0.00"',
+ $this->parse( '{{#coordinates:1,1|directional=no}}' )
+ );
+ }
+
+ public function testCoordinatesInNonDms_theyGetParsed() {
+ $this->assertContains(
+ '1° 20\' 13.20" N, 4° 12\' 0.00" W',
+ $this->parse( '{{#coordinates:1.337°, -4.2°}}' )
+ );
+ }
+
+ public function testGivenInvalidFormat_defaultFormatGetsUsed() {
+ $this->assertContains(
+ '1° 0\' 0.00" N, 1° 0\' 0.00" E',
+ $this->parse( '{{#coordinates:1,1|format=such}}' )
+ );
+ }
+
+ public function testRoundingWhenFormattingAsFloat() {
+ $this->assertContains(
+ '52.136945 N, 0.466722 W',
+ $this->parse( '{{#coordinates:52.136945,-0.466722|format=float}}' )
+ );
+ }
+
+ public function testRoundingWhenFormattingAsDMS() {
+ $this->assertContains(
+ '52° 8\' 13.00" N, 0° 28\' 0.20" W',
+ $this->parse( '{{#coordinates:52.136945,-0.466722|format=dms}}' )
+ );
+ }
+
+ public function testRoundingWhenFormattingAsDD() {
+ $this->assertContains(
+ '52.136945° N, 0.466722° W',
+ $this->parse( '{{#coordinates:52.136945,-0.466722|format=dd}}' )
+ );
+ }
+
+ public function testRoundingWhenFormattingAsDM() {
+ $this->assertContains(
+ '52° 8.2167\' N, 0° 28.0033\' W',
+ $this->parse( '{{#coordinates:52.136945,-0.466722|format=dm}}' )
+ );
+ }
+
+} \ No newline at end of file
diff --git a/www/wiki/extensions/Maps/tests/Integration/Parser/DisplayMapTest.php b/www/wiki/extensions/Maps/tests/Integration/Parser/DisplayMapTest.php
new file mode 100644
index 00000000..9bd64bcf
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/Parser/DisplayMapTest.php
@@ -0,0 +1,220 @@
+<?php
+
+namespace Maps\Tests\Integration\Parser;
+
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class DisplayMapTest extends TestCase {
+
+ private $originalHeight;
+ private $originalWidth;
+
+ public function setUp() {
+ $this->originalHeight = $GLOBALS['egMapsMapHeight'];
+ $this->originalWidth = $GLOBALS['egMapsMapWidth'];
+ }
+
+ public function tearDown() {
+ $GLOBALS['egMapsMapHeight'] = $this->originalHeight;
+ $GLOBALS['egMapsMapWidth'] = $this->originalWidth;
+ }
+
+ public function testMapIdIsSet() {
+ $this->assertContains(
+ 'id="map_leaflet_',
+ $this->parse( '{{#display_map:1,1|service=leaflet}}' )
+ );
+ }
+
+ private function parse( string $textToParse ): string {
+ $parser = new \Parser();
+
+ return $parser->parse( $textToParse, \Title::newMainPage(), new \ParserOptions() )->getText();
+ }
+
+ public function testServiceSelectionWorks() {
+ $this->assertContains(
+ 'maps-googlemaps3',
+ $this->parse( '{{#display_map:1,1|service=google}}' )
+ );
+ }
+
+ public function testSingleCoordinatesAreIncluded() {
+ $this->assertContains(
+ '"lat":1,"lon":1',
+ $this->parse( '{{#display_map:1,1}}' )
+ );
+ }
+
+ public function testMultipleCoordinatesAreIncluded() {
+ $result = $this->parse( '{{#display_map:1,1; 4,2}}' );
+
+ $this->assertContains( '"lat":1,"lon":1', $result );
+ $this->assertContains( '"lat":4,"lon":2', $result );
+ }
+
+ public function testWhenValidZoomIsSpecified_itGetsUsed() {
+ $this->assertContains(
+ '"zoom":5',
+ $this->parse( '{{#display_map:1,1|service=google|zoom=5}}' )
+ );
+ }
+
+ public function testWhenZoomIsNotSpecifiedAndThereIsOnlyOneLocation_itIsDefaulted() {
+ $this->assertContains(
+ '"zoom":' . $GLOBALS['egMapsGMaps3Zoom'],
+ $this->parse( '{{#display_map:1,1|service=google}}' )
+ );
+ }
+
+ public function testWhenZoomIsNotSpecifiedAndThereAreMultipleLocations_itIsDefaulted() {
+ $this->assertContains(
+ '"zoom":false',
+ $this->parse( '{{#display_map:1,1;2,2|service=google}}' )
+ );
+ }
+
+ public function testWhenZoomIsInvalid_itIsDefaulted() {
+ $this->assertContains(
+ '"zoom":' . $GLOBALS['egMapsGMaps3Zoom'],
+ $this->parse( '{{#display_map:1,1|service=google|zoom=tomato}}' )
+ );
+ }
+
+ public function testTagIsRendered() {
+ $this->assertContains(
+ '"lat":1,"lon":1',
+ $this->parse( '<display_map>1,1</display_map>' )
+ );
+ }
+
+ public function testTagServiceParameterIsUsed() {
+ $this->assertContains(
+ 'maps-googlemaps3',
+ $this->parse( '<display_map service="google">1,1</display_map>' )
+ );
+ }
+
+ public function testWhenThereAreNoLocations_locationsArrayIsEmpty() {
+ $this->assertContains(
+ '"locations":[]',
+ $this->parse( '{{#display_map:}}' )
+ );
+ }
+
+ public function testLocationTitleGetsIncluded() {
+ $this->assertContains(
+ '"title":"title',
+ $this->parse( '{{#display_map:1,1~title}}' )
+ );
+ }
+
+ public function testLocationDescriptionGetsIncluded() {
+ $this->assertContains(
+ 'such description',
+ $this->parse( '{{#display_map:1,1~title~such description}}' )
+ );
+ }
+
+ public function testRectangleDisplay() {
+ $this->assertContains(
+ '"title":"title',
+ $this->parse( '{{#display_map:rectangles=1,1:2,2~title}}' )
+ );
+ }
+
+ public function testCircleDisplay() {
+ $this->assertContains(
+ '"title":"title',
+ $this->parse( '{{#display_map:circles=1,1:2~title}}' )
+ );
+ }
+
+ public function testRectangleFillOpacityIsUsed() {
+ $this->assertContains(
+ '"fillOpacity":"fill opacity"',
+ $this->parse( '{{#display_map:rectangles=1,1:2,2~title~text~color~opacity~thickness~fill color~fill opacity}}' )
+ );
+ }
+
+ public function testRectangleFillColorIsUsed() {
+ $this->assertContains(
+ '"fillColor":"fill color"',
+ $this->parse( '{{#display_map:rectangles=1,1:2,2~title~text~color~opacity~thickness~fill color~fill opacity}}' )
+ );
+ }
+
+ public function testServiceSelectionWorksWhenItIsPrecededByMultipleParameters() {
+ $this->assertContains(
+ 'maps-googlemaps3',
+ $this->parse(
+ "{{#display_map:rectangles=\n 1,1:2,2~title~text~color\n| scrollwheelzoom=off\n| service = google}}"
+ )
+ );
+ }
+
+ public function testDimensionDefaultsAsInteger() {
+ $GLOBALS['egMapsMapHeight'] = 420;
+ $GLOBALS['egMapsMapWidth'] = 230;
+
+ $this->assertContains(
+ 'height: 420px;',
+ $this->parse( '{{#display_map:1,1}}' )
+ );
+
+ $this->assertContains(
+ 'width: 230px;',
+ $this->parse( '{{#display_map:1,1}}' )
+ );
+ }
+
+ // TODO: need DI to test
+// public function testWhenLocationHasVisitedIconModifier_itIsUsed() {
+// $this->assertContains(
+// '"visitedicon":"VisitedIcon.png"',
+// $this->parse( '{{#display_map:1,1~title~text~icon~group~inline label~VisitedIcon.png}}' )
+// );
+// }
+//
+// public function testWhenLocationHasVisitedIconModifierWithNamespacePrefix_thePrefixGetsRemoved() {
+// $this->assertContains(MapsMapperTest
+// '"visitedicon":"VisitedIcon.png"',
+// $this->parse( '{{#display_map:1,1~title~text~icon~group~inline label~File:VisitedIcon.png}}' )
+// );
+// }
+//
+// public function testWhenVisitedIconParameterIsProvidedWithNamespacePrefix_thePrefixGetsRemoved() {
+// $this->assertContains(
+// '"visitedicon":"VisitedIcon.png"',
+// $this->parse( '{{#display_map:1,1|visitedicon=File:VisitedIcon.png}}' )
+// );
+// }
+//
+// public function testWhenLocationHasIconModifierWithNamespacePrefix_thePrefixGetsRemoved() {
+// $this->assertContains(
+// '"icon":"Icon.png"',
+// $this->parse( '{{#display_map:1,1~title~text~File:Icon.png}}' )
+// );
+// }
+
+ public function testWhenIconParameterIsProvidedButEmpty_itIsDefaulted() {
+ $this->assertContains(
+ '"icon":"","inlineLabel":"Ghent',
+ $this->parse(
+ "{{#display_map:Gent, Belgie~The city Ghent~Ghent is awesome~ ~ ~Ghent}}"
+ )
+ );
+ }
+
+ public function testWhenLocationHasNoTitleAndText_textFieldIsEmptyString() {
+ $this->assertContains(
+ '"text":""',
+ $this->parse( '{{#display_map:1,1}}' )
+ );
+ }
+
+} \ No newline at end of file
diff --git a/www/wiki/extensions/Maps/tests/Integration/Semantic/ValueDescriptions/AreaDescriptionTest.php b/www/wiki/extensions/Maps/tests/Integration/Semantic/ValueDescriptions/AreaDescriptionTest.php
new file mode 100644
index 00000000..9950b7d3
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/Semantic/ValueDescriptions/AreaDescriptionTest.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace Maps\Tests\Semantic\ValueDescriptions;
+
+use CoordinateValue;
+use Maps\SemanticMW\ValueDescriptions\AreaDescription;
+use PHPUnit\Framework\TestCase;
+use SMWDIGeoCoord;
+
+/**
+ * @covers \Maps\SemanticMW\ValueDescriptions\AreaDescription
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class AreaDescriptionTest extends TestCase {
+
+ public function setUp() {
+ if ( !defined( 'SMW_VERSION' ) ) {
+ $this->markTestSkipped( 'SMW is not available' );
+ }
+ }
+
+ public function testGetBoundingBox() {
+ $area = new AreaDescription(
+ new SMWDIGeoCoord( 0, 5 ),
+ SMW_CMP_EQ,
+ '10 km'
+ );
+
+ $this->assertEquals(
+ [
+ 'north' => 0.089932160591873,
+ 'east' => 5.089932160591873,
+ 'south' => -0.089932160591873,
+ 'west' => 4.9100678394081
+ ],
+ $area->getBoundingBox()
+ );
+ }
+
+ public function testGetSQLCondition() {
+ $area = new AreaDescription(
+ new SMWDIGeoCoord( 0, 5 ),
+ SMW_CMP_EQ,
+ '10 km'
+ );
+
+ $this->assertSame(
+ 'geo_table.lat_field < \'0.089932160591873\' AND geo_table.lat_field > \'-0.089932160591873\' '
+ . 'AND geo_table.long_field < \'5.0899321605919\' AND geo_table.long_field > \'4.9100678394081\'',
+ $area->getSQLCondition( 'geo_table', [ 'id_field', 'lat_field', 'long_field' ], wfGetDB( DB_MASTER ) )
+ );
+ }
+
+ public function testWhenComparatorIsNotSupported_getSQLConditionReturnsFalse() {
+ $area = new AreaDescription(
+ new SMWDIGeoCoord( 0, 5 ),
+ SMW_CMP_LIKE,
+ '10 km'
+ );
+
+ $this->assertFalse(
+ $area->getSQLCondition( 'geo_table', [ 'id_field', 'lat_field', 'long_field' ], wfGetDB( DB_MASTER ) )
+ );
+ }
+
+ public function testGetQueryString() {
+ $area = new AreaDescription(
+ new SMWDIGeoCoord( 1, 5 ),
+ SMW_CMP_EQ,
+ '10 km'
+ );
+
+ $this->assertSame(
+ '[[1° 0\' 0.00" N, 5° 0\' 0.00" E (10 km)]]',
+ $area->getQueryString()
+ );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/parsers/CircleParserTest.php b/www/wiki/extensions/Maps/tests/Integration/parsers/CircleParserTest.php
new file mode 100644
index 00000000..9009947b
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/parsers/CircleParserTest.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Maps\Tests\Integration\parsers;
+
+use DataValues\Geo\Values\LatLongValue;
+use Jeroen\SimpleGeocoder\Geocoders\Decorators\CoordinateFriendlyGeocoder;
+use Jeroen\SimpleGeocoder\Geocoders\NullGeocoder;
+use Maps\Elements\Circle;
+use Maps\Presentation\WikitextParsers\CircleParser;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @covers \Maps\Presentation\WikitextParsers\CircleParser
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class CircleParserTest extends TestCase {
+
+ public function testGivenCoordinateAndRadius_parserReturnsCircle() {
+ $parser = new CircleParser( new CoordinateFriendlyGeocoder( new NullGeocoder() ) );
+
+ $circle = $parser->parse( '57.421,23.90625:32684.605182' );
+
+ $this->assertInstanceOf( Circle::class, $circle );
+
+ $expectedLatLong = new LatLongValue( 57.421, 23.90625 );
+ $this->assertTrue( $expectedLatLong->equals( $circle->getCircleCentre() ) );
+
+ $this->assertSame( 32684.605182, $circle->getCircleRadius() );
+ }
+
+ public function testGivenTitleAndText_circleHasProvidedMetaData() {
+ $parser = new CircleParser( new CoordinateFriendlyGeocoder( new NullGeocoder() ) );
+
+ $circle = $parser->parse( '57.421,23.90625:32684.605182~title~text' );
+
+ $this->assertInstanceOf( Circle::class, $circle );
+
+ $this->assertSame( 'title', $circle->getTitle() );
+ $this->assertSame( 'text', $circle->getText() );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/parsers/DistanceParserTest.php b/www/wiki/extensions/Maps/tests/Integration/parsers/DistanceParserTest.php
new file mode 100644
index 00000000..f402d966
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/parsers/DistanceParserTest.php
@@ -0,0 +1,66 @@
+<?php
+
+namespace Maps\Tests\Integration\parsers;
+
+use Maps\Presentation\WikitextParsers\DistanceParser;
+use PHPUnit\Framework\TestCase;
+use PHPUnit4And6Compat;
+use ValueParsers\ParseException;
+
+/**
+ * @covers \Maps\Presentation\WikitextParsers\DistanceParser
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class DistanceParserTest extends TestCase {
+ use PHPUnit4And6Compat;
+
+ /**
+ * @dataProvider validInputProvider
+ */
+ public function testValidInputs( $input, $expected ) {
+ $this->assertSame(
+ $expected,
+ ( new DistanceParser() )->parse( $input )
+ );
+ }
+
+ public function validInputProvider() {
+ return [
+ [ '1', 1.0 ],
+ [ '1m', 1.0 ],
+ [ '42 km', 42000.0 ],
+ [ '4.2 km', 4200.0 ],
+ [ '4.2 m', 4.2 ],
+ [ '4.02 m', 4.02 ],
+ [ '4.02 km', 4020.0 ],
+ [ '0.001 km', 1.0 ],
+ ];
+ }
+
+ /**
+ * @dataProvider invalidInputProvider
+ */
+ public function testGivenInvalidInput_exceptionIsThrown( $input ) {
+ $parser = new DistanceParser();
+
+ $this->expectException( ParseException::class );
+ $parser->parse( $input );
+ }
+
+ public function invalidInputProvider() {
+ return [
+ [ '' ],
+ [ 'kittens' ],
+ [ '1 kittens' ],
+ [ '-1m' ],
+ [ 'foo m' ],
+ [ '1m foo' ],
+ [ 'foo 1m' ],
+ [ 'm1' ],
+ [ '4. m' ],
+ [ '4.2.1 m' ],
+ ];
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/parsers/JsonFileParserTest.php b/www/wiki/extensions/Maps/tests/Integration/parsers/JsonFileParserTest.php
new file mode 100644
index 00000000..a169beb1
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/parsers/JsonFileParserTest.php
@@ -0,0 +1,120 @@
+<?php
+
+namespace Maps\Tests\Integration\parsers;
+
+use FileFetcher\FileFetcher;
+use FileFetcher\NullFileFetcher;
+use FileFetcher\SimpleFileFetcher;
+use FileFetcher\StubFileFetcher;
+use FileFetcher\ThrowingFileFetcher;
+use Maps\DataAccess\JsonFileParser;
+use Maps\MediaWiki\Content\GeoJsonContent;
+use PHPUnit\Framework\TestCase;
+use PHPUnit4And6Compat;
+use Title;
+
+/**
+ * @covers \Maps\DataAccess\JsonFileParser
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class JsonFileParserTest extends TestCase {
+ use PHPUnit4And6Compat;
+
+ private const VALID_FILE_JSON = [
+ 'such' => 'string',
+ 42 => 13.37,
+ 'array' => [
+ '~[,,_,,]:3'
+ ]
+ ];
+
+ private const VALID_PAGE_JSON = [
+ 'foo' => 'bar',
+ 1 => 2.3,
+ 'array' => [
+ '~[,,_,,]:3'
+ ]
+ ];
+
+ private const EXISTING_GEO_JSON_PAGE = 'Such';
+ private const EXISTING_GEO_JSON_PAGE_WITH_PREFIX = 'GeoJson:Such';
+ private const NON_EXISTING_GEO_JSON_PAGE = 'GeoJson:Nope';
+
+ /**
+ * @var FileFetcher
+ */
+ private $fileFetcher;
+
+ public function setUp() {
+ $this->fileFetcher = new StubFileFetcher( json_encode( self::VALID_FILE_JSON ) );
+
+ $page = new \WikiPage( Title::newFromText( self::EXISTING_GEO_JSON_PAGE_WITH_PREFIX ) );
+ $page->doEditContent( new GeoJsonContent( json_encode( self::VALID_PAGE_JSON ) ), '' );
+ }
+
+ private function newJsonFileParser(): JsonFileParser {
+ return new JsonFileParser(
+ $this->fileFetcher,
+ null
+ );
+ }
+
+ public function testWhenFileRetrievalFails_emptyJsonIsReturned() {
+ $this->fileFetcher = new ThrowingFileFetcher();
+
+ $this->assertSame(
+ [],
+ $this->newJsonFileParser()->parse( 'http://such.a/file' )
+ );
+ }
+
+ public function testWhenFileHasValidJson_jsonIsReturned() {
+ $this->fileFetcher = new StubFileFetcher( json_encode( self::VALID_FILE_JSON ) );
+
+ $this->assertEquals(
+ self::VALID_FILE_JSON,
+ $this->newJsonFileParser()->parse( 'http://such.a/file' )
+ );
+ }
+
+ public function testWhenFileIsEmpty_emptyJsonIsReturned() {
+ $this->fileFetcher = new NullFileFetcher();
+
+ $this->assertSame(
+ [],
+ $this->newJsonFileParser()->parse( 'http://such.a/file' )
+ );
+ }
+
+ public function testWhenFileLocationIsNotUrl_emptyJsonIsReturned() {
+ $this->fileFetcher = new SimpleFileFetcher();
+
+ $jsonFilePath = __DIR__ . '/../../../composer.json';
+ $this->assertFileExists( $jsonFilePath );
+
+ $this->assertSame( [], $this->newJsonFileParser()->parse( $jsonFilePath ) );
+ }
+
+ public function testWhenPageExists_itsContentsIsReturned() {
+ $this->assertSame(
+ self::VALID_PAGE_JSON,
+ $this->newJsonFileParser()->parse( self::EXISTING_GEO_JSON_PAGE_WITH_PREFIX )
+ );
+ }
+
+ public function testWhenPageDoesNotExist_emptyJsonIsReturned() {
+ $this->assertSame(
+ [],
+ $this->newJsonFileParser()->parse( self::NON_EXISTING_GEO_JSON_PAGE )
+ );
+ }
+
+ public function testWhenExistingPageIsSpecifiedWithoutPrefix_itsContentsIsReturned() {
+ $this->assertSame(
+ self::VALID_PAGE_JSON,
+ $this->newJsonFileParser()->parse( self::EXISTING_GEO_JSON_PAGE )
+ );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/parsers/LineParserTest.php b/www/wiki/extensions/Maps/tests/Integration/parsers/LineParserTest.php
new file mode 100644
index 00000000..39b149da
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/parsers/LineParserTest.php
@@ -0,0 +1,77 @@
+<?php
+
+namespace Maps\Tests\Integration\parsers;
+
+use DataValues\Geo\Values\LatLongValue;
+use Jeroen\SimpleGeocoder\Geocoders\InMemoryGeocoder;
+use Maps\Elements\Line;
+use Maps\Presentation\WikitextParsers\LineParser;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @covers \Maps\Presentation\WikitextParsers\LineParser
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class LineParserTest extends TestCase {
+
+ public function testGivenOneCoordinate_lineWithOneCoordinateIsReturned() {
+ $parser = $this->newParser();
+
+ $this->assertEquals(
+ new Line( [ new LatLongValue( 4, 2 ) ] ),
+ $parser->parse( '4,2' )
+ );
+ }
+
+ /**
+ * @return \Maps\Presentation\WikitextParsers\LineParser
+ */
+ private function newParser() {
+ $parser = new LineParser();
+
+ $parser->setGeocoder(
+ new InMemoryGeocoder(
+ [
+ '4,2' => new LatLongValue( 4, 2 ),
+ '2,3' => new LatLongValue( 2, 3 ),
+ ]
+ )
+ );
+
+ return $parser;
+ }
+
+ public function testGivenTwoCoordinates_lineWithBothCoordinateIsReturned() {
+ $parser = $this->newParser();
+
+ $this->assertEquals(
+ new Line(
+ [
+ new LatLongValue( 4, 2 ),
+ new LatLongValue( 2, 3 )
+ ]
+ ),
+ $parser->parse( '4,2:2,3' )
+ );
+ }
+
+ public function testTitleAndTextGetSetWhenPresent() {
+ $parser = $this->newParser();
+
+ $expectedLine = new Line(
+ [
+ new LatLongValue( 4, 2 ),
+ new LatLongValue( 2, 3 )
+ ]
+ );
+ $expectedLine->setTitle( 'title' );
+ $expectedLine->setText( 'text' );
+
+ $this->assertEquals(
+ $expectedLine,
+ $parser->parse( '4,2:2,3~title~text' )
+ );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/parsers/LocationParserTest.php b/www/wiki/extensions/Maps/tests/Integration/parsers/LocationParserTest.php
new file mode 100644
index 00000000..60f93284
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/parsers/LocationParserTest.php
@@ -0,0 +1,119 @@
+<?php
+
+namespace Maps\Tests\Integration\parsers;
+
+use DataValues\Geo\Values\LatLongValue;
+use Jeroen\SimpleGeocoder\Geocoders\StubGeocoder;
+use Maps\DataAccess\MediaWikiFileUrlFinder;
+use Maps\Elements\Location;
+use Maps\Presentation\WikitextParsers\LocationParser;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @covers \Maps\Presentation\WikitextParsers\LocationParser
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class LocationParserTest extends TestCase {
+
+ private $geocoder;
+ private $fileUrlFinder;
+ private $useAddressAsTitle;
+
+ public function setUp() {
+ $this->geocoder = new StubGeocoder( new LatLongValue( 1, 2 ) );
+ $this->fileUrlFinder = new MediaWikiFileUrlFinder();
+ $this->useAddressAsTitle = false;
+ }
+
+ private function newLocationParser() {
+ return LocationParser::newInstance( $this->geocoder, $this->fileUrlFinder, $this->useAddressAsTitle );
+ }
+
+ /**
+ * @dataProvider titleProvider
+ */
+ public function testGivenTitleThatIsNotLink_titleIsSetAndLinkIsNot( $title ) {
+ $location = $this->newLocationParser()->parse( '4,2~' . $title );
+
+ $this->assertTitleAndLinkAre( $location, $title, '' );
+ }
+
+ protected function assertTitleAndLinkAre( Location $location, $title, $link ) {
+ $this->assertHasJsonKeyWithValue( $location, 'title', $title );
+ $this->assertHasJsonKeyWithValue( $location, 'link', $link );
+ }
+
+ protected function assertHasJsonKeyWithValue( Location $polygon, $key, $value ) {
+ $json = $polygon->getJSONObject();
+
+ $this->assertArrayHasKey( $key, $json );
+ $this->assertEquals( $value, $json[$key] );
+ }
+
+ public function titleProvider() {
+ return [
+ [ '' ],
+ [ 'Title' ],
+ [ 'Some title' ],
+ [ 'link' ],
+ [ 'links:foo' ],
+ ];
+ }
+
+ /**
+ * @dataProvider linkProvider
+ */
+ public function testGivenTitleThatIsLink_linkIsSetAndTitleIsNot( $link ) {
+ $location = $this->newLocationParser()->parse( '4,2~link:' . $link );
+
+ $this->assertTitleAndLinkAre( $location, '', $link );
+ }
+
+ public function linkProvider() {
+ return [
+ [ 'https://www.semantic-mediawiki.org' ],
+ [ 'irc://freenode.net' ],
+ ];
+ }
+
+// /**
+// * @dataProvider titleLinkProvider
+// */
+// public function testGivenPageTitleAsLink_pageTitleIsTurnedIntoUrl( $link ) {
+// $parser = new LocationParser();
+// $location = $parser->parse( '4,2~link:' . $link );
+//
+// $linkUrl = Title::newFromText( $link )->getFullURL();
+// $this->assertTitleAndLinkAre( $location, '', $linkUrl );
+// }
+//
+// public function titleLinkProvider() {
+// return array(
+// array( 'Foo' ),
+// array( 'Some_Page' ),
+// );
+// }
+
+ public function testGivenAddressAndNoTitle_addressIsSetAsTitle() {
+ $this->useAddressAsTitle = true;
+ $location = $this->newLocationParser()->parse( 'Tempelhofer Ufer 42' );
+
+ $this->assertSame( 'Tempelhofer Ufer 42', $location->getTitle() );
+ }
+
+ public function testGivenAddressAndTitle_addressIsNotUsedAsTitle() {
+ $this->useAddressAsTitle = true;
+ $location = $this->newLocationParser()->parse( 'Tempelhofer Ufer 42~Great title of doom' );
+
+ $this->assertSame( 'Great title of doom', $location->getTitle() );
+ }
+
+ public function testGivenCoordinatesAndNoTitle_noTitleIsSet() {
+ $this->useAddressAsTitle = true;
+ $location = $this->newLocationParser()->parse( '4,2' );
+
+ $this->assertSame( '', $location->getTitle() );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/parsers/RectlangleParserTest.php b/www/wiki/extensions/Maps/tests/Integration/parsers/RectlangleParserTest.php
new file mode 100644
index 00000000..027bdb07
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/parsers/RectlangleParserTest.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Maps\Tests\Integration\parsers;
+
+use DataValues\Geo\Values\LatLongValue;
+use Jeroen\SimpleGeocoder\Geocoders\Decorators\CoordinateFriendlyGeocoder;
+use Jeroen\SimpleGeocoder\Geocoders\NullGeocoder;
+use Maps\Elements\Rectangle;
+use Maps\Presentation\WikitextParsers\RectangleParser;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @covers \Maps\Presentation\WikitextParsers\RectangleParser
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class RectangleParserTest extends TestCase {
+
+ public function testGivenBoundingBox_parserReturnsRectangle() {
+ $parser = new RectangleParser( new CoordinateFriendlyGeocoder( new NullGeocoder() ) );
+
+ $rectangle = $parser->parse( '51.8357775,33.83789:46,23.37890625' );
+
+ $this->assertInstanceOf( Rectangle::class, $rectangle );
+
+ $expectedNorthEast = new LatLongValue( 51.8357775, 33.83789 );
+ $this->assertTrue( $expectedNorthEast->equals( $rectangle->getRectangleNorthEast() ) );
+
+ $expectedSouthWest = new LatLongValue( 46, 23.37890625 );
+ $this->assertTrue( $expectedSouthWest->equals( $rectangle->getRectangleSouthWest() ) );
+ }
+
+ public function testGivenTitleAndText_rectangleHasProvidedMetaData() {
+ $parser = new RectangleParser( new CoordinateFriendlyGeocoder( new NullGeocoder() ) );
+
+ $rectangle = $parser->parse( "51.8357775,33.83789:46,23.37890625~I'm a square~of doom" );
+
+ $this->assertInstanceOf( Rectangle::class, $rectangle );
+
+ $this->assertSame( "I'm a square", $rectangle->getTitle() );
+ $this->assertSame( 'of doom', $rectangle->getText() );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/parsers/WmsOverlayParserTest.php b/www/wiki/extensions/Maps/tests/Integration/parsers/WmsOverlayParserTest.php
new file mode 100644
index 00000000..4787f263
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/parsers/WmsOverlayParserTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Maps\Tests\Integration\parsers;
+
+use Maps\Presentation\WikitextParsers\WmsOverlayParser;
+use PHPUnit\Framework\TestCase;
+use PHPUnit4And6Compat;
+use ValueParsers\ParseException;
+
+/**
+ * @covers \Maps\Presentation\WikitextParsers\WmsOverlayParser
+ * @licence GNU GPL v2+
+ * @author Mathias Mølster Lidal <mathiaslidal@gmail.com>
+ */
+class WmsOverlayParserTest extends TestCase {
+ use PHPUnit4And6Compat;
+
+ public function testGivenValidInput_parserReturnsOverlayObject() {
+ $parser = new WmsOverlayParser();
+
+ $overlay = $parser->parse( 'http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi? Foundation.GTOPO30' );
+
+ $this->assertSame(
+ 'http://demo.cubewerx.com/demo/cubeserv/cubeserv.cgi?',
+ $overlay->getWmsServerUrl()
+ );
+
+ $this->assertSame(
+ 'Foundation.GTOPO30',
+ $overlay->getWmsLayerName()
+ );
+ }
+
+ public function testWhenStyleNameIsSpecified_getStyleNameReturnsIt() {
+ $parser = new WmsOverlayParser();
+
+ $overlay = $parser->parse(
+ 'http://maps.imr.no:80/geoserver/wms? vulnerable_areas:Identified_coral_area coral_identified_areas'
+ );
+
+ $this->assertSame(
+ 'coral_identified_areas',
+ $overlay->getWmsStyleName()
+ );
+ }
+
+ public function testWhenThereAreLessThanTwoSegments_parseExceptionIsThrown() {
+ $parser = new WmsOverlayParser();
+
+ $this->expectException( ParseException::class );
+ $parser->parse( 'Such' );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/System/SemanticMW/MapQueryTest.php b/www/wiki/extensions/Maps/tests/System/SemanticMW/MapQueryTest.php
new file mode 100644
index 00000000..be04fb44
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/System/SemanticMW/MapQueryTest.php
@@ -0,0 +1,93 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace Maps\Tests\System\SemanticMW;
+
+use Maps\DataAccess\PageContentFetcher;
+use Maps\MapsFactory;
+use Maps\Tests\Util\PageCreator;
+use Maps\Tests\Util\TestFactory;
+use PHPUnit\Framework\TestCase;
+use Title;
+
+/**
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class MapQueryTest extends TestCase {
+
+ /**
+ * @var PageCreator
+ */
+ private $pageCreator;
+
+ /**
+ * @var PageContentFetcher
+ */
+ private $contentFetcher;
+
+ public function setUp() {
+ if ( !defined( 'SMW_VERSION' ) ) {
+ $this->markTestSkipped( 'SMW is not available' );
+ }
+
+ $this->pageCreator = TestFactory::newInstance()->getPageCreator();
+ $this->contentFetcher = MapsFactory::newDefault()->getPageContentFetcher();
+ }
+
+ public function testMapQuery() {
+ $this->createPages();
+
+ $this->pageCreator->createPage(
+ 'MapQuery',
+ '{{#ask:[[Coordinates::+]]|?Coordinates|?Description|?URL|format=map}}'
+ );
+
+ // TODO: saner way
+ $content = $this->contentFetcher->getPageContent( 'MapQuery' )->getParserOutput( Title::newFromText( 'MapQuery' ) )->getText();
+
+ $this->assertContains(
+ '<div id="map_',
+ $content
+ );
+
+ $this->assertContains(
+ '<div id="map_',
+ $content
+ );
+ }
+
+ private function createPages() {
+ $this->pageCreator->createPage(
+ 'Property:Coordinates',
+ '[[Has type::Geographic coordinate|geographic coordinate]]'
+ );
+
+ $this->pageCreator->createPage(
+ 'Property:Description',
+ '[[Has type::Text]]'
+ );
+
+ $this->pageCreator->createPage(
+ 'Property:URL',
+ '[[Has type::URL]]'
+ );
+
+ $this->pageCreator->createPage(
+ 'Berlin',
+ '[[Coordinates::52° 31\' 0", 13° 24\' 0"]] [[Description::Capital of Germany]] [[URL::http://example.com/Berlin]]'
+ );
+
+ $this->pageCreator->createPage(
+ 'Brussels',
+ '[[Coordinates::50° 51\' 1", 4° 21\' 6"]] [[Description::Capital of Belgium]]'
+ );
+
+ $this->pageCreator->createPage(
+ 'Hamburg',
+ '[[Coordinates::53° 33\' 4", 9° 59\' 37"]]'
+ );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Unit/Elements/BaseElementTest.php b/www/wiki/extensions/Maps/tests/Unit/Elements/BaseElementTest.php
new file mode 100644
index 00000000..bda1c9bd
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Unit/Elements/BaseElementTest.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace Maps\Tests\Unit\Elements;
+
+use InvalidArgumentException;
+use PHPUnit\Framework\TestCase;
+use PHPUnit4And6Compat;
+
+/**
+ * Base class for unit tests classes for the Maps\BaseElement deriving objects.
+ *
+ * @since 3.0
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+abstract class BaseElementTest extends TestCase {
+ use PHPUnit4And6Compat;
+
+ public function invalidConstructorProvider() {
+ return [];
+ }
+
+ /**
+ * Creates and returns a new instance of the concrete class.
+ *
+ * @since 3.0
+ *
+ * @return mixed
+ */
+ public function newInstance() {
+ $reflector = new \ReflectionClass( $this->getClass() );
+ $args = func_get_args();
+ $instance = $reflector->newInstanceArgs( $args );
+ return $instance;
+ }
+
+ /**
+ * Returns the name of the concrete class tested by this test.
+ *
+ * @since 3.0
+ *
+ * @return string
+ */
+ public abstract function getClass();
+
+ /**
+ * @since 3.0
+ *
+ * @return array [instance, constructor args]
+ */
+ public function instanceProvider() {
+ $phpFails = [ $this, 'newInstance' ];
+
+ return array_map(
+ function ( array $args ) use ( $phpFails ) {
+ return [ call_user_func_array( $phpFails, $args ), $args ];
+ },
+ $this->validConstructorProvider()
+ );
+ }
+
+ public abstract function validConstructorProvider();
+
+ /**
+ * @dataProvider validConstructorProvider
+ *
+ * @since 3.0
+ */
+ public function testGivenValidArguments_constructorDoesNotThrowException() {
+ $instance = call_user_func_array( [ $this, 'newInstance' ], func_get_args() );
+ $this->assertInstanceOf( $this->getClass(), $instance );
+ }
+
+ /**
+ * @dataProvider invalidConstructorProvider
+ *
+ * @since 3.0
+ */
+ public function testGivenInvalidArguments_constructorThrowsException() {
+ $this->expectException( InvalidArgumentException::class );
+ call_user_func_array( [ $this, 'newInstance' ], func_get_args() );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Unit/Elements/CircleTest.php b/www/wiki/extensions/Maps/tests/Unit/Elements/CircleTest.php
new file mode 100644
index 00000000..3800f059
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Unit/Elements/CircleTest.php
@@ -0,0 +1,70 @@
+<?php
+
+namespace Maps\Tests\Unit\Elements;
+
+use DataValues\Geo\Values\LatLongValue;
+use Maps\Elements\Circle;
+
+/**
+ * @covers \Maps\Elements\Circle
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class CircleTest extends BaseElementTest {
+
+ /**
+ * @see BaseElementTest::getClass
+ *
+ * @since 3.0
+ *
+ * @return string
+ */
+ public function getClass() {
+ return Circle::class;
+ }
+
+ public function validConstructorProvider() {
+ $argLists = [];
+
+ $argLists[] = [ new LatLongValue( 4, 2 ), 42 ];
+ $argLists[] = [ new LatLongValue( 42, 2.2 ), 9000.1 ];
+ $argLists[] = [ new LatLongValue( 4, 2 ), 1 ];
+ $argLists[] = [ new LatLongValue( 4, 2 ), 0.1 ];
+
+ return $argLists;
+ }
+
+ public function invalidConstructorProvider() {
+ $argLists = [];
+
+ $argLists[] = [ new LatLongValue( 4, 2 ), 0 ];
+ $argLists[] = [ new LatLongValue( 4, 2 ), -42 ];
+
+ return $argLists;
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ *
+ * @param Circle $circle
+ * @param array $arguments
+ */
+ public function testGetCircleCentre( Circle $circle, array $arguments ) {
+ $this->assertTrue( $circle->getCircleCentre()->equals( $arguments[0] ) );
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ *
+ * @param Circle $circle
+ * @param array $arguments
+ */
+ public function testGetCircleRadius( Circle $circle, array $arguments ) {
+ $this->assertEquals( $arguments[1], $circle->getCircleRadius() );
+ }
+
+}
+
+
+
diff --git a/www/wiki/extensions/Maps/tests/Unit/Elements/ImageOverlayTest.php b/www/wiki/extensions/Maps/tests/Unit/Elements/ImageOverlayTest.php
new file mode 100644
index 00000000..21c43c31
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Unit/Elements/ImageOverlayTest.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace Maps\Tests\Unit\Elements;
+
+use DataValues\Geo\Values\LatLongValue;
+use Jeroen\SimpleGeocoder\Geocoders\Decorators\CoordinateFriendlyGeocoder;
+use Jeroen\SimpleGeocoder\Geocoders\NullGeocoder;
+use Maps\Elements\ImageOverlay;
+use Maps\Presentation\WikitextParsers\ImageOverlayParser;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @covers \Maps\Elements\ImageOverlay
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class ImageOverlayTest extends TestCase {
+
+ public function testGetImage() {
+ $imageOverlay = new ImageOverlay(
+ new LatLongValue( 4, 2 ),
+ new LatLongValue( -4, -2 ),
+ 'Foo.png'
+ );
+
+ $this->assertSame( 'Foo.png', $imageOverlay->getImage() );
+ }
+
+ public function testGivenMetaData_overlayHasProvidedMetaData() {
+ $parser = new ImageOverlayParser( new CoordinateFriendlyGeocoder( new NullGeocoder() ) );
+
+ $overlay = $parser->parse( "1,2:3,4:https://such.an/image.png~Semantic MediaWiki~World domination imminent!~https://such.link" );
+
+ $this->assertSame( 'https://such.an/image.png', $overlay->getImage() );
+ $this->assertSame( 'Semantic MediaWiki', $overlay->getTitle() );
+ $this->assertSame( 'World domination imminent!', $overlay->getText() );
+ $this->assertSame( 'https://such.link', $overlay->getLink() );
+ }
+
+ public function testGivenLinkWithPrefix_linkIsParsedAndPrefixIsRemoved() {
+ $parser = new ImageOverlayParser( new CoordinateFriendlyGeocoder( new NullGeocoder() ) );
+
+ $overlay = $parser->parse( "1,2:3,4:https://such.an/image.png~Semantic MediaWiki~World domination imminent!~link:https://such.link" );
+
+ $this->assertSame( 'https://such.link', $overlay->getLink() );
+ }
+
+}
+
+
+
diff --git a/www/wiki/extensions/Maps/tests/Unit/Elements/LineTest.php b/www/wiki/extensions/Maps/tests/Unit/Elements/LineTest.php
new file mode 100644
index 00000000..5ca462ff
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Unit/Elements/LineTest.php
@@ -0,0 +1,74 @@
+<?php
+
+namespace Maps\Tests\Unit\Elements;
+
+use DataValues\Geo\Values\LatLongValue;
+use Maps\Elements\Line;
+
+/**
+ * @covers \Maps\Elements\Line
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class LineTest extends BaseElementTest {
+
+ /**
+ * @see BaseElementTest::getClass
+ *
+ * @since 3.0
+ *
+ * @return string
+ */
+ public function getClass() {
+ return Line::class;
+ }
+
+ public function validConstructorProvider() {
+ $argLists = [];
+
+ $argLists[] = [ [] ];
+ $argLists[] = [ [ new LatLongValue( 4, 2 ) ] ];
+
+ $argLists[] = [
+ [
+ new LatLongValue( 4, 2 ),
+ new LatLongValue( 2, 4 ),
+ new LatLongValue( 42, 42 ),
+ ]
+ ];
+
+ return $argLists;
+ }
+
+ public function invalidConstructorProvider() {
+ $argLists = [];
+
+ $argLists[] = [ [ '~=[,,_,,]:3' ] ];
+ $argLists[] = [ [ new LatLongValue( 4, 2 ), '~=[,,_,,]:3' ] ];
+ $argLists[] = [ [ '~=[,,_,,]:3', new LatLongValue( 4, 2 ) ] ];
+
+ return $argLists;
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ *
+ * @param Line $line
+ * @param array $arguments
+ */
+ public function testGetLineCoordinates( Line $line, array $arguments ) {
+ $coordinates = $line->getLineCoordinates();
+
+ $this->assertInternalType( 'array', $coordinates );
+ $this->assertEquals( count( $arguments[0] ), count( $coordinates ) );
+
+ foreach ( $coordinates as $geoCoordinate ) {
+ $this->assertInstanceOf( LatLongValue::class, $geoCoordinate );
+ }
+ }
+
+}
+
+
+
diff --git a/www/wiki/extensions/Maps/tests/Unit/Elements/LocationTest.php b/www/wiki/extensions/Maps/tests/Unit/Elements/LocationTest.php
new file mode 100644
index 00000000..57041e07
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Unit/Elements/LocationTest.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Maps\Tests\Unit\Elements;
+
+use DataValues\Geo\Values\LatLongValue;
+use Maps\Elements\Location;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @covers \Maps\Elements\Location
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class LocationTest extends TestCase {
+
+ public function latLongValueProvider() {
+ $argLists = [];
+
+ $argLists[] = [ new LatLongValue( 0, 0 ) ];
+ $argLists[] = [ new LatLongValue( 4, 2 ) ];
+ $argLists[] = [ new LatLongValue( 42, 42 ) ];
+ $argLists[] = [ new LatLongValue( -4.2, -42 ) ];
+
+ return $argLists;
+ }
+
+ /**
+ * @dataProvider latLongValueProvider
+ */
+ public function testGivenLatLongInConstructor_getCoordinatesReturnsIt( LatLongValue $latLong ) {
+ $location = new Location( $latLong );
+ $this->assertTrue( $latLong->equals( $location->getCoordinates() ) );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Unit/Elements/PolygonTest.php b/www/wiki/extensions/Maps/tests/Unit/Elements/PolygonTest.php
new file mode 100644
index 00000000..f1c8f513
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Unit/Elements/PolygonTest.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace Maps\Tests\Unit\Elements;
+
+use Maps\Elements\Polygon;
+
+/**
+ * @covers \Maps\Elements\Polygon
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class PolygonTest extends LineTest {
+
+ /**
+ * @see BaseElementTest::getClass
+ *
+ * @since 3.0
+ *
+ * @return string
+ */
+ public function getClass() {
+ return Polygon::class;
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ */
+ public function testSetOnlyVisibleOnHover( Polygon $polygon ) {
+ $this->assertFalse( $polygon->isOnlyVisibleOnHover() );
+
+ $polygon->setOnlyVisibleOnHover( true );
+ $this->assertTrue( $polygon->isOnlyVisibleOnHover() );
+
+ $polygon->setOnlyVisibleOnHover( false );
+ $this->assertFalse( $polygon->isOnlyVisibleOnHover() );
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ */
+ public function testSetFillOpacity( Polygon $polygon ) {
+ $polygon->setFillOpacity( '0.42' );
+ $this->assertHasJsonKeyWithValue( $polygon, 'fillOpacity', '0.42' );
+ }
+
+ protected function assertHasJsonKeyWithValue( Polygon $polygon, $key, $value ) {
+ $json = $polygon->getJSONObject();
+
+ $this->assertArrayHasKey( $key, $json );
+ $this->assertEquals(
+ $value,
+ $json[$key]
+ );
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ */
+ public function testSetFillColor( Polygon $polygon ) {
+ $polygon->setFillColor( '#FFCCCC' );
+ $this->assertHasJsonKeyWithValue( $polygon, 'fillColor', '#FFCCCC' );
+ }
+
+}
+
+
+
diff --git a/www/wiki/extensions/Maps/tests/Unit/Elements/RectangleTest.php b/www/wiki/extensions/Maps/tests/Unit/Elements/RectangleTest.php
new file mode 100644
index 00000000..daed71cb
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Unit/Elements/RectangleTest.php
@@ -0,0 +1,73 @@
+<?php
+
+namespace Maps\Tests\Unit\Elements;
+
+use DataValues\Geo\Values\LatLongValue;
+use Maps\Elements\Rectangle;
+
+/**
+ * @covers \Maps\Elements\Rectangle
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class RectangleTest extends BaseElementTest {
+
+ /**
+ * @see BaseElementTest::getClass
+ *
+ * @since 3.0
+ *
+ * @return string
+ */
+ public function getClass() {
+ return Rectangle::class;
+ }
+
+ public function validConstructorProvider() {
+ $argLists = [];
+
+ $argLists[] = [ new LatLongValue( 4, 2 ), new LatLongValue( -4, -2 ) ];
+ $argLists[] = [ new LatLongValue( -42, -42 ), new LatLongValue( -4, -2 ) ];
+
+ return $argLists;
+ }
+
+ public function invalidConstructorProvider() {
+ $argLists = [];
+
+ $argLists[] = [ new LatLongValue( 4, 2 ), new LatLongValue( 4, 2 ) ];
+
+ return $argLists;
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ */
+ public function testGetCorners( Rectangle $rectangle, array $arguments ) {
+ $this->assertTrue( $rectangle->getRectangleNorthEast()->equals( $arguments[0] ) );
+ $this->assertTrue( $rectangle->getRectangleSouthWest()->equals( $arguments[1] ) );
+ }
+
+ /**
+ * @dataProvider instanceProvider
+ */
+ public function testSetCorners( Rectangle $rectangle ) {
+ $coordinates = [
+ new LatLongValue( 42, 42 ),
+ new LatLongValue( 0, 0 )
+ ];
+
+ foreach ( $coordinates as $coordinate ) {
+ $rectangle->setRectangleNorthEast( $coordinate );
+ $this->assertTrue( $rectangle->getRectangleNorthEast()->equals( $coordinate ) );
+
+ $rectangle->setRectangleSouthWest( $coordinate );
+ $this->assertTrue( $rectangle->getRectangleSouthWest()->equals( $coordinate ) );
+ }
+ }
+
+}
+
+
+
diff --git a/www/wiki/extensions/Maps/tests/Unit/Presentation/KmlFormatterTest.php b/www/wiki/extensions/Maps/tests/Unit/Presentation/KmlFormatterTest.php
new file mode 100644
index 00000000..cc88f005
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Unit/Presentation/KmlFormatterTest.php
@@ -0,0 +1,88 @@
+<?php
+
+namespace Maps\Tests\Unit\Presentation;
+
+use DataValues\Geo\Values\LatLongValue;
+use Maps\Elements\Location;
+use Maps\Presentation\KmlFormatter;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @covers \Maps\Presentation\KmlFormatter
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class KmlFormatterTest extends TestCase {
+
+ public function testEmptyList() {
+ $this->assertSame(
+ '<?xml version="1.0" encoding="UTF-8"?>
+<kml xmlns="http://www.opengis.net/kml/2.2">
+ <Document>
+
+ </Document>
+</kml>',
+ ( new KmlFormatter() )->formatLocationsAsKml()
+ );
+ }
+
+ public function testSeveralLocations() {
+ $this->assertSame(
+ '<?xml version="1.0" encoding="UTF-8"?>
+<kml xmlns="http://www.opengis.net/kml/2.2">
+ <Document>
+ <Placemark>
+ <name><![CDATA[first title]]></name>
+ <description><![CDATA[first text]]></description>
+ <Point>
+ <coordinates>23,42.42,0</coordinates>
+ </Point>
+ </Placemark>
+ <Placemark>
+ <name><![CDATA[second title]]></name>
+ <description><![CDATA[second text]]></description>
+ <Point>
+ <coordinates>0,-1,0</coordinates>
+ </Point>
+ </Placemark>
+ </Document>
+</kml>',
+ ( new KmlFormatter() )->formatLocationsAsKml(
+ new Location(
+ new LatLongValue( 42.42,23 ),
+ 'first title',
+ 'first text'
+ ),
+ new Location(
+ new LatLongValue( -1,0 ),
+ 'second title',
+ 'second text'
+ )
+ )
+ );
+ }
+
+ public function testLocationWithoutTitleAndText() {
+ $this->assertSame(
+ '<?xml version="1.0" encoding="UTF-8"?>
+<kml xmlns="http://www.opengis.net/kml/2.2">
+ <Document>
+ <Placemark>
+ <name><![CDATA[]]></name>
+ <description><![CDATA[]]></description>
+ <Point>
+ <coordinates>23,42.42,0</coordinates>
+ </Point>
+ </Placemark>
+ </Document>
+</kml>',
+ ( new KmlFormatter() )->formatLocationsAsKml(
+ new Location(
+ new LatLongValue( 42.42,23 )
+ )
+ )
+ );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Unit/Presentation/ParameterExtractorTest.php b/www/wiki/extensions/Maps/tests/Unit/Presentation/ParameterExtractorTest.php
new file mode 100644
index 00000000..2e526809
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Unit/Presentation/ParameterExtractorTest.php
@@ -0,0 +1,80 @@
+<?php
+
+namespace Maps\Tests\Unit\Presentation;
+
+use Maps\Presentation\ParameterExtractor;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @covers \Maps\Presentation\ParameterExtractor
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class ParameterExtractorTest extends TestCase {
+
+ public function testGivenNoParameters_nullIsReturned() {
+ $this->assertNull( ( new ParameterExtractor() )->extract( [ 'name' ], [] ) );
+ }
+
+ public function testGivenWhenPrimaryNameIsPresent_itsValueIsReturned() {
+ $this->assertSame(
+ 'value',
+ ( new ParameterExtractor() )->extract(
+ [ 'name' ],
+ [ 'foo' => 'bar', 'name' => 'value', 'baz' => 'bah' ]
+ )
+ );
+ }
+
+ public function testGivenAliasIsPresent_itsValueIsReturned() {
+ $this->assertSame(
+ 'value',
+ ( new ParameterExtractor() )->extract(
+ [ 'name', 'secondary', 'alias' ],
+ [ 'foo' => 'bar', 'alias' => 'value', 'baz' => 'bah' ]
+ )
+ );
+ }
+
+ public function testWhenAliasAndPrimaryArePresent_thePrimariesValueIsReturned() {
+ $this->assertSame(
+ 'value',
+ ( new ParameterExtractor() )->extract(
+ [ 'name', 'secondary', 'alias' ],
+ [ 'foo' => 'bar', 'alias' => 'wrong', 'name' => 'value' ]
+ )
+ );
+ }
+
+ public function testValueIsTrimmed() {
+ $this->assertSame(
+ 'value',
+ ( new ParameterExtractor() )->extract(
+ [ 'name' ],
+ [ 'name' => " value\t " ]
+ )
+ );
+ }
+
+ public function testWhenUpperCaseIsUsedInTheName_itIsStillFound() {
+ $this->assertSame(
+ 'value',
+ ( new ParameterExtractor() )->extract(
+ [ 'name' ],
+ [ 'nAmE' => 'value' ]
+ )
+ );
+ }
+
+ public function testNameHasSpacesAroundIt_itIsStillFound() {
+ $this->assertSame(
+ 'value',
+ ( new ParameterExtractor() )->extract(
+ [ 'name' ],
+ [ ' name ' => 'value' ]
+ )
+ );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Unit/Semantic/DataValues/CoordinateValueTest.php b/www/wiki/extensions/Maps/tests/Unit/Semantic/DataValues/CoordinateValueTest.php
new file mode 100644
index 00000000..bbf8d0f1
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Unit/Semantic/DataValues/CoordinateValueTest.php
@@ -0,0 +1,113 @@
+<?php
+
+namespace Maps\Tests\Unit\Semantic\DataValues;
+
+use Maps\SemanticMW\DataValues\CoordinateValue;
+use Maps\SemanticMW\ValueDescriptions\AreaDescription;
+use Maps\SemanticMW\ValueDescriptions\CoordinateDescription;
+use PHPUnit\Framework\TestCase;
+use SMW\DataValueFactory;
+use SMWDataItem;
+use SMWDIGeoCoord;
+
+/**
+ * @covers \Maps\SemanticMW\ValueDescriptions\CoordinateValue
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class CoordinateValueTest extends TestCase {
+
+ public function setUp() {
+ if ( !defined( 'SMW_VERSION' ) ) {
+ $this->markTestSkipped( 'SMW is not available' );
+ }
+ }
+
+ public function testConstruct() {
+ $geoDI = new SMWDIGeoCoord( 23, 42 );
+
+ /**
+ * @var CoordinateValue $geoValue
+ */
+ $geoValue = DataValueFactory::newDataItemValue( $geoDI );
+
+ $this->assertInstanceOf( CoordinateValue::class, $geoValue );
+
+ $this->assertEquals( $geoDI, $geoValue->getDataItem() );
+ $this->assertSame( '23° 0\' 0.00" N, 42° 0\' 0.00" E', $geoValue->getShortWikiText() );
+ }
+
+ /**
+ * @dataProvider coordinateProvider
+ */
+ public function testGetQueryDescription( $lat, $long, $serialization ) {
+ $geoValue = $this->newInstance();
+
+ $description = $geoValue->getQueryDescription( $serialization );
+
+ $this->assertIsCorrectCoordValue( $description, $lat, $long );
+ }
+
+ protected function newInstance() {
+ return new CoordinateValue( SMWDataItem::TYPE_GEO );
+ }
+
+ private function assertIsCorrectCoordValue( $description, $lat, $long ) {
+ /**
+ * @var CoordinateDescription $description
+ */
+ $this->assertInstanceOf( CoordinateDescription::class, $description );
+ $this->assertEquals( $lat, $description->getDataItem()->getLatitude() );
+ $this->assertEquals( $long, $description->getDataItem()->getLongitude() );
+ }
+
+ public function coordinateProvider() {
+ return [
+ [
+ 23,
+ 42,
+ '23° 0\' 0", 42° 0\' 0"',
+ ],
+ [
+ 0,
+ 0,
+ '0° 0\' 0", 0° 0\' 0"',
+ ],
+ [
+ -23.5,
+ -42.5,
+ '-23° 30\' 0", -42° 30\' 0"',
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider coordinateWithDistanceProvider
+ */
+ public function testGetQueryDescriptionForArea( $serialization ) {
+ $geoValue = $this->newInstance();
+
+ $description = $geoValue->getQueryDescription( $serialization );
+
+ $this->assertInstanceOf( AreaDescription::class, $description );
+ }
+
+ public function coordinateWithDistanceProvider() {
+ return [
+ [
+ '23° 0\' 0", 42° 0\' 0"(1km)',
+ 1000,
+ ],
+ [
+ '0° 0\' 0", 0° 0\' 0" ( 1 m )',
+ 1,
+ ],
+ [
+ '-23° 30\' 0", -42° 30\' 0" (9001m)',
+ 9001,
+ ],
+ ];
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Util/PageCreator.php b/www/wiki/extensions/Maps/tests/Util/PageCreator.php
new file mode 100644
index 00000000..ca5ba675
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Util/PageCreator.php
@@ -0,0 +1,24 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace Maps\Tests\Util;
+
+use Title;
+
+/**
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class PageCreator {
+
+ public function createPage( string $title, string $content = null ) {
+ $page = new \WikiPage( Title::newFromText( $title ) );
+
+ $page->doEditContent(
+ new \WikitextContent( $content ?? 'Content of ' . $title ),
+ __CLASS__ . ' creating page ' . $title
+ );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Util/TestFactory.php b/www/wiki/extensions/Maps/tests/Util/TestFactory.php
new file mode 100644
index 00000000..286272d1
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Util/TestFactory.php
@@ -0,0 +1,21 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace Maps\Tests\Util;
+
+/**
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+class TestFactory {
+
+ public static function newInstance(): self {
+ return new self();
+ }
+
+ public function getPageCreator(): PageCreator {
+ return new PageCreator();
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/bootstrap.php b/www/wiki/extensions/Maps/tests/bootstrap.php
new file mode 100644
index 00000000..1b0e39e5
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/bootstrap.php
@@ -0,0 +1,33 @@
+<?php
+
+if ( PHP_SAPI !== 'cli' ) {
+ die( 'Not an entry point' );
+}
+
+if ( defined( 'MEDIAWIKI' ) ) {
+ // If testing against an older version of MediaWiki, define
+ // an empty trait to avoid fatal errors.
+ if ( !trait_exists( PHPUnit4And6Compat::class ) ) {
+ trait PHPUnit4And6Compat {
+ public function expectException( string $exception ) {
+ $this->setExpectedException( $exception );
+ }
+ }
+ }
+
+ return;
+}
+
+if ( !trait_exists( PHPUnit4And6Compat::class ) ) {
+ trait PHPUnit4And6Compat {
+ }
+}
+
+error_reporting( -1 );
+ini_set( 'display_errors', 1 );
+
+if ( !is_readable( __DIR__ . '/../vendor/autoload.php' ) ) {
+ die( 'You need to install this package with Composer before you can run the tests' );
+}
+
+require __DIR__ . '/../vendor/autoload.php'; \ No newline at end of file