summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/Maps/tests
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/Maps/tests')
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/DataAccess/GeoJsonFetcherTest.php (renamed from www/wiki/extensions/Maps/tests/Integration/parsers/JsonFileParserTest.php)43
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/CoordinatesTest.php8
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/ParserHookTest.php13
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/Parser/DisplayMapTest.php39
-rw-r--r--www/wiki/extensions/Maps/tests/Integration/ResourceModulesTest.php56
-rw-r--r--www/wiki/extensions/Maps/tests/Unit/MediaWiki/GeoJsonContentTest.php22
-rw-r--r--www/wiki/extensions/Maps/tests/js/leaflet/GeoJsonTest.js112
7 files changed, 263 insertions, 30 deletions
diff --git a/www/wiki/extensions/Maps/tests/Integration/parsers/JsonFileParserTest.php b/www/wiki/extensions/Maps/tests/Integration/DataAccess/GeoJsonFetcherTest.php
index a169beb1..a3edbb87 100644
--- a/www/wiki/extensions/Maps/tests/Integration/parsers/JsonFileParserTest.php
+++ b/www/wiki/extensions/Maps/tests/Integration/DataAccess/GeoJsonFetcherTest.php
@@ -1,45 +1,40 @@
<?php
-namespace Maps\Tests\Integration\parsers;
+namespace Maps\Tests\Integration\DataAccess;
use FileFetcher\FileFetcher;
use FileFetcher\NullFileFetcher;
use FileFetcher\SimpleFileFetcher;
use FileFetcher\StubFileFetcher;
use FileFetcher\ThrowingFileFetcher;
-use Maps\DataAccess\JsonFileParser;
+use Maps\DataAccess\GeoJsonFetcher;
+use Maps\MapsFactory;
use Maps\MediaWiki\Content\GeoJsonContent;
use PHPUnit\Framework\TestCase;
use PHPUnit4And6Compat;
use Title;
/**
- * @covers \Maps\DataAccess\JsonFileParser
+ * @covers \Maps\DataAccess\GeoJsonFetcher
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
-class JsonFileParserTest extends TestCase {
+class GeoJsonFetcherTest extends TestCase {
use PHPUnit4And6Compat;
private const VALID_FILE_JSON = [
- 'such' => 'string',
- 42 => 13.37,
- 'array' => [
- '~[,,_,,]:3'
- ]
+ 'type' => 'FeatureCollection',
+ 'features' => []
];
private const VALID_PAGE_JSON = [
- 'foo' => 'bar',
- 1 => 2.3,
- 'array' => [
- '~[,,_,,]:3'
- ]
+ 'type' => 'FeatureCollection',
+ 'features' => []
];
- 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';
+ private const EXISTING_GEO_JSON_PAGE = 'Test Such';
+ private const EXISTING_GEO_JSON_PAGE_WITH_PREFIX = 'GeoJson:Test Such';
+ private const NON_EXISTING_GEO_JSON_PAGE = 'GeoJson:Test Nope';
/**
* @var FileFetcher
@@ -53,11 +48,8 @@ class JsonFileParserTest extends TestCase {
$page->doEditContent( new GeoJsonContent( json_encode( self::VALID_PAGE_JSON ) ), '' );
}
- private function newJsonFileParser(): JsonFileParser {
- return new JsonFileParser(
- $this->fileFetcher,
- null
- );
+ private function newJsonFileParser(): GeoJsonFetcher {
+ return MapsFactory::newDefault()->newGeoJsonFetcher( $this->fileFetcher );
}
public function testWhenFileRetrievalFails_emptyJsonIsReturned() {
@@ -117,4 +109,11 @@ class JsonFileParserTest extends TestCase {
);
}
+ public function testPageIsReturnedAsSource() {
+ $this->assertSame(
+ self::EXISTING_GEO_JSON_PAGE,
+ $this->newJsonFileParser()->fetch( self::EXISTING_GEO_JSON_PAGE_WITH_PREFIX )->getTitleValue()->getText()
+ );
+ }
+
}
diff --git a/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/CoordinatesTest.php b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/CoordinatesTest.php
index 9ee324fe..9dffefae 100644
--- a/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/CoordinatesTest.php
+++ b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/CoordinatesTest.php
@@ -3,8 +3,8 @@
namespace Maps\Tests\Integration\MediaWiki\ParserHooks;
use DataValues\Geo\Values\LatLongValue;
+use Maps\MapsFactory;
use Maps\MediaWiki\ParserHooks\CoordinatesFunction;
-use ParamProcessor\ParamDefinition;
/**
* @covers CoordinatesFunction
@@ -71,7 +71,9 @@ class CoordinatesTest extends ParserHookTest {
* @see ParserHookTest::processingProvider
*/
public function processingProvider() {
- $definitions = ParamDefinition::getCleanDefinitions( $this->getInstance()->getParamDefinitions() );
+ $definitions = MapsFactory::globalInstance()->getParamDefinitionFactory()->newDefinitionsFromArrays(
+ $this->getInstance()->getParamDefinitions()
+ );
$argLists = [];
$values = [
@@ -122,4 +124,4 @@ class CoordinatesTest extends ParserHookTest {
return new \Maps\MediaWiki\ParserHooks\CoordinatesFunction();
}
-} \ 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
index eeb19d61..791f5d44 100644
--- a/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/ParserHookTest.php
+++ b/www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/ParserHookTest.php
@@ -2,7 +2,7 @@
namespace Maps\Tests\Integration\MediaWiki\ParserHooks;
-use ParamProcessor\ParamDefinition;
+use Maps\MapsFactory;
use ParamProcessor\Processor;
use PHPUnit\Framework\TestCase;
@@ -77,7 +77,10 @@ abstract class ParserHookTest extends TestCase {
$definitions = $this->getInstance()->getParamDefinitions();
$processor = Processor::newDefault();
- $processor->setParameters( $parameters, $definitions );
+ $processor->setParameters( $parameters );
+ $processor->setParameterDefinitions(
+ MapsFactory::globalInstance()->getParamDefinitionFactory()->newDefinitionsFromArrays( $definitions )
+ );
$result = $processor->processParameters();
@@ -108,7 +111,9 @@ abstract class ParserHookTest extends TestCase {
* Returns an array with the default values of the parameters.
*/
private function getDefaultValues() {
- $definitions = ParamDefinition::getCleanDefinitions( $this->getInstance()->getParamDefinitions() );
+ $definitions = MapsFactory::globalInstance()->getParamDefinitionFactory()->newDefinitionsFromArrays(
+ $this->getInstance()->getParamDefinitions()
+ );
$defaults = [];
@@ -130,4 +135,4 @@ abstract class ParserHookTest extends TestCase {
);
}
-} \ 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
index 9bd64bcf..4ef7c791 100644
--- a/www/wiki/extensions/Maps/tests/Integration/Parser/DisplayMapTest.php
+++ b/www/wiki/extensions/Maps/tests/Integration/Parser/DisplayMapTest.php
@@ -2,6 +2,7 @@
namespace Maps\Tests\Integration\Parser;
+use Maps\MediaWiki\Content\GeoJsonContent;
use PHPUnit\Framework\TestCase;
/**
@@ -217,4 +218,40 @@ class DisplayMapTest extends TestCase {
);
}
-} \ No newline at end of file
+ public function testGeoJsonSourceForFile() {
+ $this->assertContains(
+ '"GeoJsonSource":null,',
+ $this->parse(
+ "{{#display_map:geojson=404}}"
+ )
+ );
+ }
+
+ public function testGeoJsonSourceForPage() {
+ $page = new \WikiPage( \Title::newFromText( 'GeoJson:TestPageSource' ) );
+ $page->doEditContent(
+ new GeoJsonContent( json_encode( [
+ 'type' => 'FeatureCollection',
+ 'features' => []
+ ] ) ),
+ ''
+ );
+
+ $this->assertContains(
+ '"GeoJsonSource":"TestPageSource",',
+ $this->parse(
+ "{{#display_map:geojson=TestPageSource}}"
+ )
+ );
+ }
+
+ public function testGoogleMapsKmlFiltersInvalidFileNames() {
+ $this->assertContains(
+ '"kml":["ValidFile.kml"],',
+ $this->parse(
+ "{{#display_map:service=google|kml=, ,ValidFile.kml ,}}"
+ )
+ );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Integration/ResourceModulesTest.php b/www/wiki/extensions/Maps/tests/Integration/ResourceModulesTest.php
new file mode 100644
index 00000000..d6f2a6e5
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Integration/ResourceModulesTest.php
@@ -0,0 +1,56 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace Maps\Tests\Integration;
+
+use MediaWiki\MediaWikiServices;
+use PHPUnit\Framework\TestCase;
+use ResourceLoader;
+
+class ResourceModulesTest extends TestCase {
+
+ /**
+ * @dataProvider mapsModuleNameProvider
+ */
+ public function testDependenciesExist( string $moduleName ) {
+ $resourceLoader = $this->getResourceLoader();
+ $module = $resourceLoader->getModule( $moduleName );
+
+ if ( $module->getDependencies() === [] ) {
+ $this->assertTrue( true );
+ }
+ else {
+ foreach ( $module->getDependencies() as $dependency ) {
+ $this->assertNotNull(
+ $resourceLoader->getModule( $dependency ),
+ 'Dependency ' . $dependency . ' should exist'
+ );
+ }
+ }
+ }
+
+ public function mapsModuleNameProvider() {
+ foreach ( $this->getResourceLoader()->getModuleNames() as $name ) {
+ if ( $this->isMapsModule( $name ) ) {
+ yield $name => [ $name ];
+ }
+ }
+ }
+
+ private function isMapsModule( string $name ): bool {
+ $modulePrefix = 'ext.maps.';
+ return substr( $name, 0, strlen( $modulePrefix ) ) === $modulePrefix;
+ }
+
+ private function getResourceLoader(): ResourceLoader {
+ $mwServices = MediaWikiServices::getInstance();
+
+ if ( method_exists( $mwServices, 'getResourceLoader' ) ) {
+ return $mwServices->getResourceLoader();
+ }
+
+ return new ResourceLoader();
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/Unit/MediaWiki/GeoJsonContentTest.php b/www/wiki/extensions/Maps/tests/Unit/MediaWiki/GeoJsonContentTest.php
new file mode 100644
index 00000000..df2cc759
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/Unit/MediaWiki/GeoJsonContentTest.php
@@ -0,0 +1,22 @@
+<?php
+
+declare( strict_types = 1 );
+
+namespace Maps\Tests\Unit\MediaWiki;
+
+use Maps\MediaWiki\Content\GeoJsonContent;
+use PHPUnit\Framework\TestCase;
+
+class GeoJsonContentTest extends TestCase {
+
+ public function testEmptyJsonIsNotValidContent() {
+ $this->assertFalse( ( new GeoJsonContent( '{}' ) )->isValid() );
+ }
+
+ public function testMinimalGeoJsonIsValid() {
+ $this->assertTrue( ( new GeoJsonContent(
+ '{"type": "FeatureCollection", "features": []}'
+ ) )->isValid() );
+ }
+
+}
diff --git a/www/wiki/extensions/Maps/tests/js/leaflet/GeoJsonTest.js b/www/wiki/extensions/Maps/tests/js/leaflet/GeoJsonTest.js
new file mode 100644
index 00000000..768db788
--- /dev/null
+++ b/www/wiki/extensions/Maps/tests/js/leaflet/GeoJsonTest.js
@@ -0,0 +1,112 @@
+( function () {
+ QUnit.module( 'Maps' );
+
+ let GeoJSON = window.maps.leaflet.GeoJson;
+
+ QUnit.test( 'GeoJSON.simpleStyleToLeafletPathOptions', function ( assert ) {
+ assert.deepEqual(
+ GeoJSON.simpleStyleToLeafletPathOptions( {} ),
+ {},
+ 'Empty properties results in empty path'
+ );
+
+ let pathOptions = GeoJSON.simpleStyleToLeafletPathOptions( {
+ "stroke": "#a92c2c",
+ "stroke-width": 5.1,
+ "stroke-opacity": 1,
+ "fill": "#ffff00",
+ "fill-opacity": 0.5,
+ "title": "hi"
+ } );
+
+ assert.equal(
+ pathOptions.color,
+ '#a92c2c',
+ 'color is set (based on stroke)'
+ );
+
+ assert.equal(
+ pathOptions.weight,
+ 5.1,
+ 'weight is set (based on stroke-width)'
+ );
+
+ assert.equal(
+ pathOptions.opacity,
+ 1,
+ 'opacity is set (based on stroke-opacity)'
+ );
+
+ assert.equal(
+ pathOptions.fillColor,
+ "#ffff00",
+ 'fillColor is set'
+ );
+
+ assert.equal(
+ pathOptions.fillOpacity,
+ 0.5,
+ 'fillOpacity is set'
+ );
+ } );
+
+ QUnit.test( 'GeoJSON.popupContentFromProperties', function ( assert ) {
+ assert.equal(
+ GeoJSON.popupContentFromProperties({
+ title: 'Hello World',
+ description: 'pew pew'
+ }),
+ '<strong>Hello World</strong><br>pew pew',
+ 'Title and description: title is made bold and description is on a new line'
+ );
+
+ assert.equal(
+ GeoJSON.popupContentFromProperties({
+ title: 'Hello World'
+ }),
+ 'Hello World',
+ 'Only title'
+ );
+
+ assert.equal(
+ GeoJSON.popupContentFromProperties({
+ description: 'pew pew'
+ }),
+ 'pew pew',
+ 'Only description'
+ );
+
+ assert.equal(
+ GeoJSON.popupContentFromProperties({
+ }),
+ '',
+ 'No content'
+ );
+
+ assert.equal(
+ GeoJSON.popupContentFromProperties({
+ title: 'Hello <a href="#">link</a>'
+ }),
+ 'Hello &lt;a href=\"#\"&gt;link&lt;/a&gt;',
+ 'Title escaping'
+ );
+
+ assert.equal(
+ GeoJSON.popupContentFromProperties({
+ description: 'Hello <a href="#">link</a>'
+ }),
+ 'Hello &lt;a href=\"#\"&gt;link&lt;/a&gt;',
+ 'Description escaping'
+ );
+
+ assert.equal(
+ GeoJSON.popupContentFromProperties({
+ title: 'Hello <a href="#">link</a>',
+ description: "<script>alert('evil')</script>"
+ }),
+ '<strong>Hello &lt;a href=\"#\"&gt;link&lt;/a&gt;</strong><br>&lt;script&gt;alert(\'evil\')&lt;/script&gt;',
+ 'Title and description escaping'
+ );
+ } );
+
+}() );