jenkins-bot has submitted this change and it was merged.
Change subject: \SMW\QueryData use HashIdGenerator instead
......................................................................
\SMW\QueryData use HashIdGenerator instead
Change-Id: I94db16e56a30108c0ed3428cb10248d915b28197
---
M includes/parserhooks/AskParserFunction.php
M includes/query/QueryData.php
M tests/phpunit/includes/query/QueryDataTest.php
3 files changed, 75 insertions(+), 80 deletions(-)
Approvals:
Mwjames: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/parserhooks/AskParserFunction.php
b/includes/parserhooks/AskParserFunction.php
index 8512054..a1b6287 100644
--- a/includes/parserhooks/AskParserFunction.php
+++ b/includes/parserhooks/AskParserFunction.php
@@ -144,11 +144,8 @@
// Add query data from the query
// Suppose the the query returns with an error, right now we
store
// the query itself even though it returned with unqualified
data
- $this->queryData->setQueryId( $rawParams );
- $this->queryData->add(
- $this->query,
- $this->params
- );
+ $this->queryData->setQueryId( new HashIdGenerator( $rawParams )
);
+ $this->queryData->add( $this->query, $this->params );
// Store query data to the semantic data instance
$this->parserData->getData()->addPropertyObjectValue(
diff --git a/includes/query/QueryData.php b/includes/query/QueryData.php
index e60706c..3c3a0a7 100644
--- a/includes/query/QueryData.php
+++ b/includes/query/QueryData.php
@@ -68,25 +68,20 @@
}
/**
- * Set QueryId
+ * Sets QueryId
*
- * Creates an unique id ( e.g. _QUERYbda2acc317b66b564e39f45e3a18fff3)
- * which normally is based on parameters used in a #ask/#set query
+ * Generates an unique id (e.g. _QUERYbda2acc317b66b564e39f45e3a18fff3)
*
* @since 1.9
*
- * @param array $qualifiers
+ * @param IdGenerator $generator
*/
- public function setQueryId( array $qualifiers ) {
- $this->queryId = str_replace(
- '_',
- '_QUERY',
- $this->subobject->getAnonymousIdentifier( implode( '|',
$qualifiers ) )
- );
+ public function setQueryId( IdGenerator $generator ) {
+ $this->queryId = '_QUERY' . $generator->generateId();
}
/**
- * Returns query data property
+ * Returns the query meta data property
*
* @since 1.9
*
@@ -97,7 +92,7 @@
}
/**
- * Returns query data subobject container
+ * Returns the query data subobject container
*
* @since 1.9
*
diff --git a/tests/phpunit/includes/query/QueryDataTest.php
b/tests/phpunit/includes/query/QueryDataTest.php
index 7039bbc..e41d88e 100644
--- a/tests/phpunit/includes/query/QueryDataTest.php
+++ b/tests/phpunit/includes/query/QueryDataTest.php
@@ -2,6 +2,7 @@
namespace SMW\Test;
+use SMW\HashIdGenerator;
use SMW\QueryData;
use SMWQueryProcessor;
@@ -111,29 +112,29 @@
/**
* @test QueryData::add
- * @dataProvider getDataProvider
+ * @dataProvider queryDataProvider
*
* @since 1.9
*
* @param array $params
* @param array $expected
*/
- public function testInstantiatedQueryData( array $params, array
$expected ) {
+ public function testAddQueryData( array $params, array $expected ) {
$title = $this->getTitle();
$instance = $this->getInstance( $title );
list( $query, $formattedParams ) = $this->getQueryProcessor(
$params );
- $instance->setQueryId( $params );
+ $instance->setQueryId( new HashIdGenerator( $params ) );
$instance->add( $query, $formattedParams );
// Check the returned instance
- $this->assertInstanceOf( 'SMWSemanticData',
$instance->getContainer()->getSemanticData() );
+ $this->assertInstanceOf( '\SMW\SemanticData',
$instance->getContainer()->getSemanticData() );
$this->assertSemanticData(
$instance->getContainer()->getSemanticData(), $expected );
}
/**
* @test QueryData::add (Test instance exception)
- * @dataProvider getDataProvider
+ * @dataProvider queryDataProvider
*
* @since 1.9
*
@@ -159,69 +160,71 @@
*
* @return array
*/
- public function getDataProvider() {
- return array(
+ public function queryDataProvider() {
- // #0
- // {{#ask: [[Modification date::+]]
- // |?Modification date
- // |format=list
- // }}
- array(
- array(
- '',
- '[[Modification date::+]]',
- '?Modification date',
- 'format=list'
- ),
- array(
- 'propertyCount' => 4,
- 'propertyKey' => array( '_ASKST',
'_ASKSI', '_ASKDE', '_ASKFO' ),
- 'propertyValue' => array( 'list', 1, 1,
'[[Modification date::+]]' )
- )
- ),
+ $provider = array();
- // #1
- // {{#ask: [[Modification date::+]][[Category:Foo]]
- // |?Modification date
- // |?Has title
- // |format=list
- // }}
+ // #0
+ // {{#ask: [[Modification date::+]]
+ // |?Modification date
+ // |format=list
+ // }}
+ $provider[] = array(
array(
- array(
- '',
- '[[Modification
date::+]][[Category:Foo]]',
- '?Modification date',
- '?Has title',
- 'format=list'
- ),
- array(
- 'propertyCount' => 4,
- 'propertyKey' => array( '_ASKST',
'_ASKSI', '_ASKDE', '_ASKFO' ),
- 'propertyValue' => array( 'list', 2, 1,
'[[Modification date::+]] [[Category:Foo]]' )
- )
+ '',
+ '[[Modification date::+]]',
+ '?Modification date',
+ 'format=list'
),
-
- // #2 Unknown format, default table
- // {{#ask: [[Modification date::+]][[Category:Foo]]
- // |?Modification date
- // |?Has title
- // |format=bar
- // }}
array(
- array(
- '',
- '[[Modification
date::+]][[Category:Foo]]',
- '?Modification date',
- '?Has title',
- 'format=bar'
- ),
- array(
- 'propertyCount' => 4,
- 'propertyKey' => array( '_ASKST',
'_ASKSI', '_ASKDE', '_ASKFO' ),
- 'propertyValue' => array( 'table', 2,
1, '[[Modification date::+]] [[Category:Foo]]' )
- )
- ),
+ 'propertyCount' => 4,
+ 'propertyKey' => array( '_ASKST', '_ASKSI',
'_ASKDE', '_ASKFO' ),
+ 'propertyValue' => array( 'list', 1, 1,
'[[Modification date::+]]' )
+ )
);
+
+ // #1
+ // {{#ask: [[Modification date::+]][[Category:Foo]]
+ // |?Modification date
+ // |?Has title
+ // |format=list
+ // }}
+ $provider[] = array(
+ array(
+ '',
+ '[[Modification date::+]][[Category:Foo]]',
+ '?Modification date',
+ '?Has title',
+ 'format=list'
+ ),
+ array(
+ 'propertyCount' => 4,
+ 'propertyKey' => array( '_ASKST', '_ASKSI',
'_ASKDE', '_ASKFO' ),
+ 'propertyValue' => array( 'list', 2, 1,
'[[Modification date::+]] [[Category:Foo]]' )
+ )
+ );
+
+ // #2 Unknown format, default table
+ // {{#ask: [[Modification date::+]][[Category:Foo]]
+ // |?Modification date
+ // |?Has title
+ // |format=bar
+ // }}
+ $provider[] = array(
+ array(
+ '',
+ '[[Modification date::+]][[Category:Foo]]',
+ '?Modification date',
+ '?Has title',
+ 'format=bar'
+ ),
+ array(
+ 'propertyCount' => 4,
+ 'propertyKey' => array( '_ASKST', '_ASKSI',
'_ASKDE', '_ASKFO' ),
+ 'propertyValue' => array( 'table', 2, 1,
'[[Modification date::+]] [[Category:Foo]]' )
+ )
+ );
+
+ return $provider;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/75286
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I94db16e56a30108c0ed3428cb10248d915b28197
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SemanticMediaWiki
Gerrit-Branch: master
Gerrit-Owner: Mwjames <[email protected]>
Gerrit-Reviewer: Mwjames <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits