diff options
Diffstat (limited to 'www/wiki/extensions/Maps/tests/Integration')
-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.php | 8 | ||||
-rw-r--r-- | www/wiki/extensions/Maps/tests/Integration/MediaWiki/ParserHooks/ParserHookTest.php | 13 | ||||
-rw-r--r-- | www/wiki/extensions/Maps/tests/Integration/Parser/DisplayMapTest.php | 39 | ||||
-rw-r--r-- | www/wiki/extensions/Maps/tests/Integration/ResourceModulesTest.php | 56 |
5 files changed, 129 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(); + } + +} |