Skip to content

Commit

Permalink
PostProcHandler to recognize different printout, refs 2572 (#2575)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Jul 29, 2017
1 parent 6d08d8e commit 3a85c79
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ParserFunctions/AskParserFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private function doFetchResultsFromFunctionParameters( array $functionParams, ar
$queryHash = $query->getHash();

if ( $this->postProcHandler !== null && isset( $extraKeys[self::IS_ANNOTATION] ) ) {
$this->postProcHandler->addQueryRef( $queryHash );
$this->postProcHandler->addQueryRef( $query );
}

$this->circularReferenceGuard->mark( $queryHash );
Expand Down
12 changes: 9 additions & 3 deletions src/PostProcHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SMW;

use SMWQuery as Query;
use SMW\Query\QueryRefFinder;
use ParserOutput;
use Title;
use WebRequest;
Expand Down Expand Up @@ -109,9 +108,16 @@ public function getHtml( Title $title, WebRequest $webRequest ) {
/**
* @since 3.0
*
* @param string $queryRef
* @param Query $query
*/
public function addQueryRef( $queryRef ) {
public function addQueryRef( Query $query ) {

// Query:getHash returns a hash based on a fingerprint
// (when $smwgQueryResultCacheType is set) that eliminates duplicate
// queries, yet for the post processing it is necessary to know each
// single query (same-condition, different printout) to allow running
// alternating updates as in case of cascading value dependencies
$queryRef = HashBuilder::createFromArray( $query->toArray() );

$data = $this->parserOutput->getExtensionData( self::PROC_POST_QUERYREF );

Expand Down
16 changes: 12 additions & 4 deletions tests/phpunit/Unit/PostProcHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function testGetHtml() {
/**
* @dataProvider queryRefProvider
*/
public function testAddQueryRef( $gExtensionData, $sExtensionData, $ref ) {
public function testAddQueryRef( $gExtensionData, $sExtensionData, $query ) {

$this->parserOutput->expects( $this->once() )
->method( 'getExtensionData' )
Expand All @@ -89,21 +89,29 @@ public function testAddQueryRef( $gExtensionData, $sExtensionData, $ref ) {

$instance = new PostProcHandler( $this->parserOutput );

$instance->addQueryRef( $ref );
$instance->addQueryRef( $query );
}

public function queryRefProvider() {

$query = $this->getMockBuilder( '\SMWQuery' )
->disableOriginalConstructor()
->getMock();

$query->expects( $this->any() )
->method( 'toArray' )
->will( $this->returnValue( array( 'Foo' ) ) );

$provider[] =[
null,
[ 'Foo' => true ],
'Foo'
$query
];

$provider[] =[
[ 'Bar' => true ],
[ 'Bar' => true, 'Foo' => true ],
'Foo'
$query
];

return $provider;
Expand Down

0 comments on commit 3a85c79

Please sign in to comment.