diff --git a/src/Map/SemanticFormat/MapPrinter.php b/src/Map/SemanticFormat/MapPrinter.php index ee09e82f..f511076c 100644 --- a/src/Map/SemanticFormat/MapPrinter.php +++ b/src/Map/SemanticFormat/MapPrinter.php @@ -11,6 +11,7 @@ use Maps\Map\MapOutput; use Maps\Map\MapOutputBuilder; use Maps\MappingService; +use Maps\MapsFactory; use Maps\Presentation\ElementJsonSerializer; use Maps\Presentation\WikitextParser; use Maps\SemanticMW\QueryHandler; @@ -89,7 +90,7 @@ final public function getResultText( QueryResult $res, $outputMode ): string { $this->isHTML = true; - $factory = \Maps\MapsFactory::globalInstance(); + $factory = MapsFactory::globalInstance(); $this->locationParser = $factory->newLocationParser(); $this->fileUrlFinder = $factory->getFileUrlFinder(); @@ -170,14 +171,14 @@ function( BaseElement $element ) { private function addTrackingCategoryIfNeeded() { // Queries on special pages, such as Special:Ask, are not part of a page. - if ( !$this->mInline || !\Maps\MapsFactory::globalInstance()->getEffectiveSettings()->get( 'egMapsEnableCategory' ) ) { + if ( !$this->mInline || !MapsFactory::globalInstance()->getEffectiveSettings()->get( 'egMapsEnableCategory' ) ) { return; } - // copyParser() does not copy: it returns the parser that runs the inline query. + // copyParser() does not copy. For #ask and #show it returns the parser running the query; other callers can + // get a parser that never parsed and has no output yet. $parser = $this->copyParser(); - // Callers other than SMW's #ask can pass a parser that never parsed and has no output yet. if ( $parser->getOptions() !== null ) { $parser->addTrackingCategory( 'maps-tracking-category' ); } @@ -317,7 +318,7 @@ public function getParamDefinitions( array $definitions ): array { * @return array */ private function getParameterInfo() { - $config = \Maps\MapsFactory::globalInstance()->getEffectiveSettings(); + $config = MapsFactory::globalInstance()->getEffectiveSettings(); $params = $this->service->getParameterInfo(); diff --git a/tests/Integration/ConfigPageHooksTest.php b/tests/Integration/ConfigPageHooksTest.php index 26f4b728..51507a31 100644 --- a/tests/Integration/ConfigPageHooksTest.php +++ b/tests/Integration/ConfigPageHooksTest.php @@ -77,7 +77,7 @@ public function testContentModelIsNotForcedWhenWikiConfigDisabled() { } public function testSavingInvalidConfigFailsWithEachError() { - $status = $this->saveConfigPage( '{"leaflets":{},"googlemaps":{}}' ); + $status = $this->trySavingConfigPage( '{"leaflets":{},"googlemaps":{}}' ); $this->assertStatusNotOK( $status ); $this->assertStatusMessagesExactly( @@ -88,8 +88,26 @@ public function testSavingInvalidConfigFailsWithEachError() { } /** - * Saves the way maintenance scripts and extensions do, without the edit form. + * Saves the way maintenance scripts and extensions do, without the edit form. A save that goes through is + * undone, so a failing run does not leave the test config as the wiki's configuration. */ + private function trySavingConfigPage( string $json ): StatusValue { + $previousJson = $this->configPageJson(); + $status = $this->saveConfigPage( $json ); + + if ( $status->isOK() ) { + $this->saveConfigPage( $previousJson ); + } + + return $status; + } + + private function configPageJson(): string { + $content = MapsTestFactory::newTestInstance()->getPageContentFetcher()->getPageContent( 'MediaWiki:Maps' ); + + return $content instanceof JsonContent ? $content->getText() : '{}'; + } + private function saveConfigPage( string $json ): StatusValue { return PageCreator::instance()->createPageWithContent( 'MediaWiki:Maps', new JsonContent( $json ) ); } @@ -123,9 +141,9 @@ public function testErrorsShowConfigKeysAsText() { $this->assertStringContainsString( '(maps-config-error-unknown-key: later)', $text ); } - public function testOtherJsonPagesAreNotValidated() { + public function testPageNamedMapsInAnotherNamespaceIsNotValidated() { $this->assertStatusGood( $this->validateSave( - Title::makeTitle( NS_GEO_JSON, 'Some area' ), + Title::makeTitle( NS_GEO_JSON, 'Maps' ), '{"type":"FeatureCollection","features":[]}' ) ); }