jenkins-bot has submitted this change and it was merged.
Change subject: Add further tests for the new {{#statements|…}} parser function
......................................................................
Add further tests for the new {{#statements|…}} parser function
Change-Id: I3b11c4faeaa98a7ef45809a7409174a1e59c12c1
---
M
client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyParserFunctionIntegrationTest.php
M client/tests/phpunit/includes/DataAccess/PropertyParserFunction/RunnerTest.php
M
client/tests/phpunit/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactoryTest.php
A
client/tests/phpunit/includes/DataAccess/PropertyParserFunction/StatementsParserFunctionIntegrationTest.php
M
client/tests/phpunit/includes/DataAccess/WikibaseDataAccessTestItemSetUpHelper.php
M client/tests/phpunit/includes/Hooks/ParserFunctionRegistrantTest.php
6 files changed, 202 insertions(+), 13 deletions(-)
Approvals:
Jonas Kress (WMDE): Looks good to me, approved
Thiemo Mättig (WMDE): Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git
a/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyParserFunctionIntegrationTest.php
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyParserFunctionIntegrationTest.php
index 5ae7324..6758bd0 100644
---
a/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyParserFunctionIntegrationTest.php
+++
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/PropertyParserFunctionIntegrationTest.php
@@ -85,6 +85,12 @@
$this->assertSame( "<p>Lua :)\n</p>", $result );
}
+ public function testPropertyParserFunction_multipleValues() {
+ $result = $this->parseWikitextToHtml(
'{{#property:P342|from=Q32489}}' );
+
+ $this->assertSame( "<p>Lua :), Lua :)\n</p>", $result
);
+ }
+
public function testPropertyParserFunction_arbitraryAccessNotFound() {
$result = $this->parseWikitextToHtml(
'{{#property:P342|from=Q1234567}}' );
diff --git
a/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/RunnerTest.php
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/RunnerTest.php
index 5adc5a9..ed51cb8 100644
---
a/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/RunnerTest.php
+++
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/RunnerTest.php
@@ -36,11 +36,14 @@
*/
class RunnerTest extends PHPUnit_Framework_TestCase {
- public function testRunPropertyParserFunction() {
+ /**
+ * @dataProvider typeProvider
+ */
+ public function testRunPropertyParserFunction( $type ) {
$itemId = new ItemId( 'Q3' );
$runner = new Runner(
- $this->getStatementGroupRendererFactory( $itemId, 'Cat'
),
+ $this->getStatementGroupRendererFactory( $itemId,
'Cat', $type ),
$this->getSiteLinkLookup( $itemId ),
new BasicEntityIdParser(),
$this->getRestrictedEntityLookup(),
@@ -50,7 +53,7 @@
$parser = $this->getParser();
$frame = new PPFrame_Hash( new Preprocessor_Hash( $parser ) );
- $result = $runner->runPropertyParserFunction( $parser, $frame,
array( 'Cat' ) );
+ $result = $runner->runPropertyParserFunction( $parser, $frame,
array( 'Cat' ), $type );
$expected = array(
'meow!',
@@ -63,11 +66,22 @@
$this->assertSame( 0, $parser->mExpensiveFunctionCount );
}
+ public function typeProvider() {
+ return [
+ [
+ 'escaped-plaintext'
+ ],
+ [
+ 'rich-wikitext'
+ ]
+ ];
+ }
+
public function testRunPropertyParserFunction_arbitraryAccess() {
$itemId = new ItemId( 'Q42' );
$runner = new Runner(
- $this->getStatementGroupRendererFactory( $itemId, 'Cat'
),
+ $this->getStatementGroupRendererFactory( $itemId,
'Cat', 'escaped-plaintext' ),
$this->getMock( SiteLinkLookup::class ),
new BasicEntityIdParser(),
$this->getRestrictedEntityLookup(),
@@ -103,7 +117,7 @@
$restrictedEntityLookup->getEntity( $itemId );
$runner = new Runner(
- $this->getStatementGroupRendererFactory( $itemId, 'Cat'
),
+ $this->getStatementGroupRendererFactory( $itemId,
'Cat', 'escaped-plaintext' ),
$this->getMock( SiteLinkLookup::class ),
new BasicEntityIdParser(),
$restrictedEntityLookup,
@@ -127,7 +141,7 @@
$itemId = new ItemId( 'Q42' );
$runner = new Runner(
- $this->getStatementGroupRendererFactory( $itemId, 'Cat'
),
+ $this->getStatementGroupRendererFactory( $itemId,
'Cat', 'escaped-plaintext' ),
$this->getMock( SiteLinkLookup::class ),
new BasicEntityIdParser(),
$this->getRestrictedEntityLookup(),
@@ -257,11 +271,12 @@
/**
* @param EntityId $entityId
* @param string $propertyLabelOrId
+ * @param string $type
*
* @return StatementGroupRendererFactory
*/
- private function getStatementGroupRendererFactory( EntityId $entityId,
$propertyLabelOrId ) {
- $renderer = $this->getRenderer( $entityId, $propertyLabelOrId );
+ private function getStatementGroupRendererFactory( EntityId $entityId,
$propertyLabelOrId, $type ) {
+ $renderer = $this->getRenderer( $entityId, $propertyLabelOrId,
$type );
$rendererFactory = $this->getMockBuilder(
StatementGroupRendererFactory::class )
->disableOriginalConstructor()
@@ -269,6 +284,7 @@
$rendererFactory->expects( $this->any() )
->method( 'newRendererFromParser' )
+ ->with( $this->isInstanceOf( Parser::class ), $type )
->will( $this->returnValue( $renderer ) );
return $rendererFactory;
diff --git
a/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactoryTest.php
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactoryTest.php
index f36c3b3..060e740 100644
---
a/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactoryTest.php
+++
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/StatementGroupRendererFactoryTest.php
@@ -41,7 +41,7 @@
*/
class StatementGroupRendererFactoryTest extends \PHPUnit_Framework_TestCase {
- public function testNewRendererForInterfaceMessage() {
+ public function testNewRenderer_forInterfaceMessage() {
$parser = $this->getParser( 'zh', 'es', true );
$rendererFactory = $this->getStatementGroupRendererFactory();
@@ -50,6 +50,15 @@
$this->assertInstanceOf( LanguageAwareRenderer::class,
$renderer );
}
+ public function testNewRender_richWikitext() {
+ $parser = $this->getParser( 'zh', 'es', true );
+
+ $rendererFactory = $this->getStatementGroupRendererFactory();
+ $renderer = $rendererFactory->newRendererFromParser( $parser,
'rich-wikitext' );
+
+ $this->assertInstanceOf( LanguageAwareRenderer::class,
$renderer );
+ }
+
public function testNewRenderer_contentConversionDisabled() {
$parser = $this->getParser( 'zh', 'es', false, true );
diff --git
a/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/StatementsParserFunctionIntegrationTest.php
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/StatementsParserFunctionIntegrationTest.php
new file mode 100644
index 0000000..a22a62b
--- /dev/null
+++
b/client/tests/phpunit/includes/DataAccess/PropertyParserFunction/StatementsParserFunctionIntegrationTest.php
@@ -0,0 +1,139 @@
+<?php
+
+namespace Wikibase\Client\Tests\DataAccess\PropertyParserFunction;
+
+use Language;
+use MediaWikiTestCase;
+use Parser;
+use ParserOptions;
+use Title;
+use User;
+use Wikibase\Client\Tests\DataAccess\WikibaseDataAccessTestItemSetUpHelper;
+use Wikibase\Client\WikibaseClient;
+use Wikibase\Test\MockClientStore;
+
+/**
+ * Simple integration test for the {{#statements:…}} parser function.
+ *
+ * @group Wikibase
+ * @group WikibaseClient
+ * @group WikibaseDataAccess
+ * @group WikibaseIntegration
+ * @group Database
+ *
+ * @license GPL-2.0+
+ * @author Marius Hoch < [email protected] >
+ */
+class StatementsParserFunctionIntegrationTest extends MediaWikiTestCase {
+
+ protected function setUp() {
+ parent::setUp();
+
+ $wikibaseClient = WikibaseClient::getDefaultInstance( 'reset' );
+ $store = $wikibaseClient->getStore();
+
+ if ( !( $store instanceof MockClientStore ) ) {
+ $store = new MockClientStore( 'de' );
+ $wikibaseClient->overrideStore( $store );
+ }
+
+ $this->assertInstanceOf(
+ MockClientStore::class,
+ $wikibaseClient->getStore(),
+ 'Mocking the default ClientStore failed'
+ );
+
+ $this->setMwGlobals( 'wgContLang', Language::factory( 'de' ) );
+
+ $setupHelper = new WikibaseDataAccessTestItemSetUpHelper(
$store );
+ $setupHelper->setUp();
+
+ $this->oldAllowDataAccessInUserLanguage =
$wikibaseClient->getSettings()->getSetting( 'allowDataAccessInUserLanguage' );
+ $this->setAllowDataAccessInUserLanguage( false );
+ }
+
+ protected function tearDown() {
+ parent::tearDown();
+
+ $this->setAllowDataAccessInUserLanguage(
$this->oldAllowDataAccessInUserLanguage );
+ WikibaseClient::getDefaultInstance( 'reset' );
+ }
+
+ /**
+ * @param bool $value
+ */
+ private function setAllowDataAccessInUserLanguage( $value ) {
+ $settings = WikibaseClient::getDefaultInstance()->getSettings();
+ $settings->setSetting( 'allowDataAccessInUserLanguage', $value
);
+ }
+
+ public function testStatementsParserFunction_byPropertyLabel() {
+ $result = $this->parseWikitextToHtml(
'{{#statements:LuaTestStringProperty}}' );
+
+ $this->assertSame( "<p><span>Lua :)</span>\n</p>", $result
);
+ }
+
+ public function testStatementsParserFunction_byPropertyId() {
+ $result = $this->parseWikitextToHtml( '{{#statements:P342}}' );
+
+ $this->assertSame( "<p><span>Lua :)</span>\n</p>", $result
);
+ }
+
+ public function testStatementsParserFunction_arbitraryAccess() {
+ $result = $this->parseWikitextToHtml(
'{{#statements:P342|from=Q32488}}' );
+
+ $this->assertSame( "<p><span>Lua :)</span>\n</p>", $result
);
+ }
+
+ public function testStatementsParserFunction_multipleValues() {
+ $result = $this->parseWikitextToHtml(
'{{#statements:P342|from=Q32489}}' );
+
+ $this->assertSame( "<p><span>Lua :)</span>,
<span>Lua :)</span>\n</p>", $result );
+ }
+
+ public function testStatementsParserFunction_arbitraryAccessNotFound() {
+ $result = $this->parseWikitextToHtml(
'{{#statements:P342|from=Q1234567}}' );
+
+ $this->assertSame( '', $result );
+ }
+
+ public function testStatementsParserFunction_byNonExistent() {
+ $result = $this->parseWikitextToHtml(
'{{#statements:P2147483647}}' );
+
+ $this->assertRegExp(
+ '/<p.*class=".*wikibase-error.*">.*P2147483647.*<\/p>/',
+ $result
+ );
+ }
+
+ public function testStatementsParserFunction_pageNotConnected() {
+ $result = $this->parseWikitextToHtml(
+ '{{#statements:P342}}',
+ 'A page not connected to an item'
+ );
+
+ $this->assertSame( '', $result );
+ }
+
+ /**
+ * @param string $wikiText
+ * @param string $title
+ *
+ * @return string HTML
+ */
+ private function parseWikitextToHtml( $wikiText, $title =
'WikibaseClientDataAccessTest' ) {
+ $settings = WikibaseClient::getDefaultInstance()->getSettings();
+ $enabled = $settings->getSetting(
'enableStatementsParserFunction' );
+ $settings->setSetting( 'enableStatementsParserFunction', true );
+
+ $parserConfig = array( 'class' => 'Parser' );
+ $popt = new ParserOptions( User::newFromId( 0 ),
Language::factory( 'en' ) );
+
+ $parser = new Parser( $parserConfig );
+ $pout = $parser->parse( $wikiText, Title::newFromText( $title
), $popt, Parser::OT_HTML );
+
+ $settings->setSetting( 'enableStatementsParserFunction',
$enabled );
+ return $pout->getText();
+ }
+
+}
diff --git
a/client/tests/phpunit/includes/DataAccess/WikibaseDataAccessTestItemSetUpHelper.php
b/client/tests/phpunit/includes/DataAccess/WikibaseDataAccessTestItemSetUpHelper.php
index 510122f..6e2605d 100644
---
a/client/tests/phpunit/includes/DataAccess/WikibaseDataAccessTestItemSetUpHelper.php
+++
b/client/tests/phpunit/includes/DataAccess/WikibaseDataAccessTestItemSetUpHelper.php
@@ -115,6 +115,8 @@
$this->createTestItem( new ItemId( 'Q32488' ), array(), array(
$statement1, $statement3 ), array() );
+ $this->createTestItem( new ItemId( 'Q32489' ), array(), array(
$statement1, $statement1 ), array() );
+
// Create another test item to test arbitrary access
$this->createTestItem( new ItemId( 'Q199024' ), array( 'de' =>
'Arbitrary access \o/' ) );
diff --git
a/client/tests/phpunit/includes/Hooks/ParserFunctionRegistrantTest.php
b/client/tests/phpunit/includes/Hooks/ParserFunctionRegistrantTest.php
index 1c4bfb9..0e71558 100644
--- a/client/tests/phpunit/includes/Hooks/ParserFunctionRegistrantTest.php
+++ b/client/tests/phpunit/includes/Hooks/ParserFunctionRegistrantTest.php
@@ -22,17 +22,27 @@
public function parserFunctionsProvider() {
return [
[
- false,
+ '$allowDataTransclusion' => false,
+ '$enableStatementsParserFunction' => true,
[
'noexternallanglinks',
]
],
[
- true,
+ '$allowDataTransclusion' => true,
+ '$enableStatementsParserFunction' => true,
[
'noexternallanglinks',
'property',
'statements',
+ ]
+ ],
+ [
+ '$allowDataTransclusion' => true,
+ '$enableStatementsParserFunction' => false,
+ [
+ 'noexternallanglinks',
+ 'property'
]
],
];
@@ -41,13 +51,20 @@
/**
* @dataProvider parserFunctionsProvider
*/
- public function testRegisterParserFunctions( $allowDataTransclusion,
array $expected ) {
+ public function testRegisterParserFunctions(
+ $allowDataTransclusion,
+ $enableStatementsParserFunction,
+ array $expected
+ ) {
$parser = new Parser( [ 'class' => 'Parser' ] );
// TODO: Remove the feature flag when not needed any more!
$settings = WikibaseClient::getDefaultInstance()->getSettings();
$enabled = $settings->getSetting(
'enableStatementsParserFunction' );
- $settings->setSetting( 'enableStatementsParserFunction', true );
+ $settings->setSetting(
+ 'enableStatementsParserFunction',
+ $enableStatementsParserFunction
+ );
$registrant = new ParserFunctionRegistrant(
$allowDataTransclusion );
$registrant->register( $parser );
--
To view, visit https://gerrit.wikimedia.org/r/317328
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3b11c4faeaa98a7ef45809a7409174a1e59c12c1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits