Mwjames has uploaded a new change for review.
https://gerrit.wikimedia.org/r/58547
Change subject: (Bug 47079) onParserAfterTidy was missing an updateOutput()
......................................................................
(Bug 47079) onParserAfterTidy was missing an updateOutput()
Took me more time to write an appropriate test then to fix
the problem
Change-Id: I60798f8f312cacada4efd38c4aed74934ae5b7c7
---
M SemanticMediaWiki.hooks.php
M tests/phpunit/includes/ParserDataTest.php
2 files changed, 52 insertions(+), 2 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/SemanticMediaWiki
refs/changes/47/58547/1
diff --git a/SemanticMediaWiki.hooks.php b/SemanticMediaWiki.hooks.php
index 0c73a74..6bc6545 100644
--- a/SemanticMediaWiki.hooks.php
+++ b/SemanticMediaWiki.hooks.php
@@ -494,6 +494,7 @@
$parserData = new SMW\ParserData( $parser->getTitle(),
$parser->getOutput(), $options );
$parserData->addCategories(
$parser->getOutput()->getCategoryLinks() );
$parserData->addDefaultSort( $parser->getDefaultSort() );
+ $parserData->updateOutput();
// If an article was was manually purged/moved ensure that the
store is
// updated as well for all other cases onLinksUpdateConstructed
will
diff --git a/tests/phpunit/includes/ParserDataTest.php
b/tests/phpunit/includes/ParserDataTest.php
index 3c2df8a..df6e35d 100644
--- a/tests/phpunit/includes/ParserDataTest.php
+++ b/tests/phpunit/includes/ParserDataTest.php
@@ -64,8 +64,8 @@
*
* @return SMW\ParserData
*/
- private function getInstance( $titleName, ParserOutput $parserOutput ) {
- return new ParserData( $this->getTitle( $titleName ),
$parserOutput );
+ private function getInstance( $titleName, ParserOutput $parserOutput,
array $settings = array() ) {
+ return new ParserData( $this->getTitle( $titleName ),
$parserOutput, $settings );
}
/**
@@ -124,4 +124,53 @@
}
}
+ /**
+ * @covers SMWHooks::onParserAfterTidy
+ *
+ * @see Bug 47079
+ *
+ * @since 1.9
+ */
+ public function testOnParserAfterTidy() {
+ $categories = array( 'Foo', 'Bar' );
+ $settings = array(
+ 'smwgUseCategoryHierarchy' => true,
+ 'smwgCategoriesAsInstances' => true,
+ );
+
+ $instance = $this->getInstance( 'Foo',
$this->getParserOutput(), $settings );
+ $instance->addCategories( $categories );
+
+ // Get semantic data from the ParserOutput that where stored/or
not earlier
+ // during parse()
+ $parserData = new ParserData( $this->getTitle( 'Foo' ),
$instance->getOutput(), $settings );
+
+ // Check the returned instance
+ $this->assertInstanceOf( 'SMWSemanticData',
$parserData->getData() );
+ $this->assertCount( 0, $parserData->getErrors() );
+
+ // Bug 47079 updateOutput() therefore resulting in count = 0
+ $this->assertCount( 0, $parserData->getData()->getProperties()
);
+
+ // Doing the same thing again but this time executing
updateOutput()
+ $instance = $this->getInstance( 'Bar',
$this->getParserOutput(), $settings );
+ $instance->addCategories( $categories );
+ $instance->updateOutput();
+
+ $parserData = new ParserData( $this->getTitle( 'Bar' ),
$instance->getOutput(), $settings );
+
+ $this->assertInstanceOf( 'SMWSemanticData',
$parserData->getData() );
+ $this->assertCount( 0, $parserData->getErrors() );
+
+ // Bug 47079 execute updateOutput(), resulting in count = 1
+ $this->assertCount( 1, $parserData->getData()->getProperties()
);
+
+ // Category property is available for further processing
+ foreach ( $parserData->getData()->getProperties() as $key =>
$diproperty ){
+ $this->assertInstanceOf( 'SMWDIProperty', $diproperty );
+
+ $this->assertEquals( '__sin',
$diproperty->findPropertyTypeID() );
+ $this->assertCount( 2,
$parserData->getData()->getPropertyValues( $diproperty ) );
+ }
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/58547
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I60798f8f312cacada4efd38c4aed74934ae5b7c7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits