From f0e1c62119da358ef7659e6365a0279df2523465 Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Sat, 3 Oct 2026 21:20:51 +0200 Subject: [PATCH] Restore MediaWiki:Maps after a failing config-save test and test the namespace check Follows-up to https://github.com/ProfessionalWiki/Maps/pull/949 `ConfigPageHooksTest` saves `MediaWiki:Maps` on the wiki's real database, so a failing run left the invalid test config as the wiki's live configuration. A save that goes through is now undone before the assertions run. The test for other JSON pages changed namespace and title at once, so dropping the namespace half of the config-page check went unnoticed. It now uses a page named `Maps` in the GeoJson namespace. `MapPrinter` imports `MapsFactory`, and its tracking-category comment no longer claims for every caller what only holds for `#ask` and `#show`. Co-Authored-By: Claude Opus 5.5 (1M context) --- src/Map/SemanticFormat/MapPrinter.php | 11 +++++----- tests/Integration/ConfigPageHooksTest.php | 26 +++++++++++++++++++---- 2 files changed, 28 insertions(+), 9 deletions(-) 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":[]}' ) ); }