jenkins-bot has submitted this change and it was merged.
Change subject: \SMW\TableResultPrinter add tests
......................................................................
\SMW\TableResultPrinter add tests
Change-Id: I88337f9cf14abd84bf95770c29e6fdcf86f63743
---
M SemanticMediaWiki.settings.php
M includes/Setup.php
M includes/queryprinters/CsvResultPrinter.php
M includes/queryprinters/JsonResultPrinter.php
R includes/queryprinters/TableResultPrinter.php
M tests/phpunit/includes/queryprinters/AggregatablePrinterTest.php
M tests/phpunit/includes/queryprinters/CsvResultPrinterTest.php
M tests/phpunit/includes/queryprinters/JsonResultPrinterTest.php
A tests/phpunit/includes/queryprinters/TableResultPrinterTest.php
9 files changed, 479 insertions(+), 49 deletions(-)
Approvals:
Mwjames: Looks good to me, approved
jenkins-bot: Verified
diff --git a/SemanticMediaWiki.settings.php b/SemanticMediaWiki.settings.php
index 1e77c58..ea15804 100644
--- a/SemanticMediaWiki.settings.php
+++ b/SemanticMediaWiki.settings.php
@@ -340,11 +340,11 @@
# 'broadtable' should not be disabled either in order not to break Special:ask.
##
$smwgResultFormats = array(
- 'table' => 'SMWTableResultPrinter',
+ 'table' => 'SMW\TableResultPrinter',
'list' => 'SMW\ListResultPrinter',
'ol' => 'SMW\ListResultPrinter',
'ul' => 'SMW\ListResultPrinter',
- 'broadtable' => 'SMWTableResultPrinter',
+ 'broadtable' => 'SMW\TableResultPrinter',
'category' => 'SMWCategoryResultPrinter',
'embedded' => 'SMWEmbeddedResultPrinter',
'template' => 'SMW\ListResultPrinter',
diff --git a/includes/Setup.php b/includes/Setup.php
index d2ce429..61e7a0f 100644
--- a/includes/Setup.php
+++ b/includes/Setup.php
@@ -180,7 +180,8 @@
$wgAutoloadClasses['SMWExportPrinter'] = $qpDir .
'SMW_ExportPrinter.php';
$wgAutoloadClasses['SMWIExportPrinter'] = $qpDir .
'SMW_IExportPrinter.php';
$wgAutoloadClasses['SMWIResultPrinter'] = $qpDir .
'SMW_IResultPrinter.php';
- $wgAutoloadClasses['SMWTableResultPrinter'] = $qpDir .
'SMW_QP_Table.php';
+ $wgAutoloadClasses['SMWTableResultPrinter'] = $qpDir .
'TableResultPrinter.php';
+ $wgAutoloadClasses['SMW\TableResultPrinter'] = $qpDir .
'TableResultPrinter.php'; // 1.9
$wgAutoloadClasses['SMWCategoryResultPrinter'] = $qpDir .
'SMW_QP_Category.php';
$wgAutoloadClasses['SMWEmbeddedResultPrinter'] = $qpDir .
'SMW_QP_Embedded.php';
$wgAutoloadClasses['SMWCsvResultPrinter'] = $qpDir .
'CsvResultPrinter.php';
diff --git a/includes/queryprinters/CsvResultPrinter.php
b/includes/queryprinters/CsvResultPrinter.php
index 360581c..fa3a083 100644
--- a/includes/queryprinters/CsvResultPrinter.php
+++ b/includes/queryprinters/CsvResultPrinter.php
@@ -42,7 +42,17 @@
class CsvResultPrinter extends \SMWExportPrinter {
/**
+ * @codeCoverageIgnore
+ *
+ * @return string
+ */
+ public function getName() {
+ return $this->msg( 'smw_printername_csv' )->text();
+ }
+
+ /**
* @see SMWIExportPrinter::getMimeType
+ * @codeCoverageIgnore
*
* @since 1.8
*
@@ -69,10 +79,6 @@
public function getQueryMode( $context ) {
return ( $context == SMWQueryProcessor::SPECIAL_PAGE ) ?
SMWQuery::MODE_INSTANCES : SMWQuery::MODE_NONE;
- }
-
- public function getName() {
- return $this->msg( 'smw_printername_csv' )->text();
}
protected function getResultText( SMWQueryResult $res, $outputmode ) {
@@ -123,6 +129,7 @@
/**
* @see SMWResultPrinter::getParamDefinitions
+ * @codeCoverageIgnore
*
* @since 1.8
*
@@ -161,7 +168,8 @@
/**
* SMWCsvResultPrinter
+ * @codeCoverageIgnore
*
* @deprecated since SMW 1.9
*/
-class_alias( 'SMW\CsvResultPrinter', 'SMWCsvResultPrinter' );
\ No newline at end of file
+class_alias( 'SMW\CsvResultPrinter', 'SMWCsvResultPrinter' );
diff --git a/includes/queryprinters/JsonResultPrinter.php
b/includes/queryprinters/JsonResultPrinter.php
index 5b43622..8e18cda 100644
--- a/includes/queryprinters/JsonResultPrinter.php
+++ b/includes/queryprinters/JsonResultPrinter.php
@@ -46,6 +46,7 @@
/**
* Returns human readable label for this printer
+ * @codeCoverageIgnore
*
* @return string
*/
@@ -134,6 +135,7 @@
/**
* @see SMWResultPrinter::getParamDefinitions
+ * @codeCoverageIgnore
*
* @since 1.8
*
@@ -160,7 +162,8 @@
/**
* SMWJSONResultPrinter
+ * @codeCoverageIgnore
*
* @deprecated since SMW 1.9
*/
-class_alias( 'SMW\JsonResultPrinter', 'SMWJSONResultPrinter' );
\ No newline at end of file
+class_alias( 'SMW\JsonResultPrinter', 'SMWJSONResultPrinter' );
diff --git a/includes/queryprinters/SMW_QP_Table.php
b/includes/queryprinters/TableResultPrinter.php
similarity index 74%
rename from includes/queryprinters/SMW_QP_Table.php
rename to includes/queryprinters/TableResultPrinter.php
index d8d8e68..c19db72 100644
--- a/includes/queryprinters/SMW_QP_Table.php
+++ b/includes/queryprinters/TableResultPrinter.php
@@ -1,29 +1,73 @@
<?php
+namespace SMW;
+
+use SMWResultArray;
+use SMWQueryResult;
+use SMWQueryProcessor;
+use SMWPrintRequest;
+
/**
- * Print query results in tables.
+ * Print query results in tables
*
- * @author Markus Krötzsch
- * @author Jeroen De Dauw < [email protected] >
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 1.5.3
*
* @file
- * @ingroup SMWQuery
+ *
+ * @license GNU GPL v2 or later
+ * @author Markus Krötzsch
+ * @author Jeroen De Dauw < [email protected] >
+ * @author mwjames
*/
-class SMWTableResultPrinter extends SMWResultPrinter {
+/**
+ * Print query results in tables
+ *
+ * @ingroup QueryPrinter
+ */
+class TableResultPrinter extends ResultPrinter {
+
+ /**
+ * @note grep search smw_printername_table, smw_printername_broadtable
+ * @codeCoverageIgnore
+ *
+ * @return string
+ */
public function getName() {
- // Give grep a chance to find the usages:
- // smw_printername_table, smw_printername_broadtable
- return wfMessage( 'smw_printername_' . $this->mFormat )->text();
+ return $this->msg( 'smw_printername_' . $this->mFormat
)->text();
}
+ /**
+ * Returns a table
+ *
+ * @param SMWQueryResult $res
+ * @param $outputmode integer
+ *
+ * @return string
+ */
protected function getResultText( SMWQueryResult $res, $outputmode ) {
$result = '';
$this->isHTML = ( $outputmode === SMW_OUTPUT_HTML );
- $this->tableFormatter = new \SMW\TableFormatter( $this->isHTML
);
+ $this->tableFormatter = new TableFormatter( $this->isHTML );
$columnClasses = array();
+
if ( $this->mShowHeaders != SMW_HEADERS_HIDE ) { // building
headers
$headers = array();
@@ -65,6 +109,7 @@
// @note A table is only transposable if header elements are
visible
// $this->mShowHeaders !== SMW_HEADERS_HIDE &&
$this->params['transpose']
+ // if transpose is enabled, please adopt the unit test as well
return $this->tableFormatter->transpose( false )->getTable(
$tableAttrs );
}
@@ -162,6 +207,7 @@
/**
* @see SMWResultPrinter::getParamDefinitions
+ * @codeCoverageIgnore
*
* @since 1.8
*
@@ -188,3 +234,11 @@
return $params;
}
}
+
+/**
+ * SMWTableResultPrinter
+ * @codeCoverageIgnore
+ *
+ * @deprecated since SMW 1.9
+ */
+class_alias( 'SMW\TableResultPrinter', 'SMWTableResultPrinter' );
diff --git a/tests/phpunit/includes/queryprinters/AggregatablePrinterTest.php
b/tests/phpunit/includes/queryprinters/AggregatablePrinterTest.php
index b403767..1ed5dc7 100644
--- a/tests/phpunit/includes/queryprinters/AggregatablePrinterTest.php
+++ b/tests/phpunit/includes/queryprinters/AggregatablePrinterTest.php
@@ -56,26 +56,44 @@
}
/**
+ * Helper method that returns a SMWQueryResult object
+ *
+ * @since 1.9
+ *
+ * @return SMWQueryResult
+ */
+ private function getMockQueryResult( $error = 'Bar' ) {
+
+ $queryResult = $this->getMockBuilder( 'SMWQueryResult' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $queryResult->expects( $this->any() )
+ ->method( 'getErrors' )
+ ->will( $this->returnValue( array( $error ) ) );
+
+ return $queryResult;
+ }
+
+ /**
+ * Helper method that returns a AggregatablePrinter object
+ *
+ * @return AggregatablePrinter
+ */
+ private function getInstance( $parameters = array() ) {
+ return $this->getMockForAbstractClass( $this->getClass(),
array( 'table' ) );
+ }
+
+ /**
* @test AggregatablePrinter::getResultText
*
* @since 1.9
*/
public function testGetResultTextErrorMessage() {
+
$expectedMessage = wfMessage( 'smw-qp-aggregatable-empty-data'
)->inContentLanguage()->text();
- $queryString = '[[Lula query]]';
- // Build SMWQuery object
- $qp = new \SMWQueryParser( $GLOBALS['smwgQFeatures'] );
- $qp->setDefaultNamespaces( $GLOBALS['smwgQDefaultNamespaces'] );
- $desc = $qp->getQueryDescription( $queryString );
- $query = new \SMWQuery( $desc );
- $query->setQueryString( $queryString );
-
- // Get SMWQueryResult object
- $queryResult = smwfGetStore()->getQueryResult( $query );
-
- // Access abstract class
- $abstractInstance = $this->getMockForAbstractClass(
$this->getClass(), array( 'table' ) );
+ $queryResult = $this->getMockQueryResult( $expectedMessage );
// Make protected method accessible
$reflection = new ReflectionClass( $this->getClass() );
@@ -83,9 +101,9 @@
$method->setAccessible( true );
// Invoke the instance
- $result = $method->invokeArgs( $abstractInstance, array(
$queryResult, SMW_OUTPUT_HTML ) );
+ $result = $method->invoke( $this->getInstance(), $queryResult,
SMW_OUTPUT_HTML );
- $this->assertEquals( '', $result );
+ $this->assertEmpty( $result );
foreach( $queryResult->getErrors() as $error ) {
$this->assertEquals( $expectedMessage, $error );
@@ -98,12 +116,10 @@
* @since 1.9
*/
public function testAddNumbersForDataItem() {
+
$values = array();
$expected = array();
$keys = array( 'test', 'foo', 'bar' );
-
- // Access abstract class
- $abstractInstance = $this->getMockForAbstractClass(
$this->getClass(), array( 'table' ) );
// Make protected method accessible
$reflection = new ReflectionClass( $this->getClass() );
@@ -126,7 +142,7 @@
$this->assertEquals( SMWDataItem::TYPE_NUMBER,
$dataItem->getDIType() );
// Invoke the instance
- $result = $method->invokeArgs( $abstractInstance,
array( $dataItem, &$values, $name ) );
+ $result = $method->invokeArgs( $this->getInstance(),
array( $dataItem, &$values, $name ) );
$this->assertInternalType( 'integer', $values[$name] );
$this->assertEquals( $expected[$name], $values[$name] );
diff --git a/tests/phpunit/includes/queryprinters/CsvResultPrinterTest.php
b/tests/phpunit/includes/queryprinters/CsvResultPrinterTest.php
index 550274c..c9ab19b 100644
--- a/tests/phpunit/includes/queryprinters/CsvResultPrinterTest.php
+++ b/tests/phpunit/includes/queryprinters/CsvResultPrinterTest.php
@@ -3,6 +3,7 @@
namespace SMW\Test;
use SMW\CsvResultPrinter;
+use SMW\ResultPrinter;
use ReflectionClass;
@@ -68,21 +69,43 @@
}
/**
- * Helper method that returns a CsvResultPrinter object
+ * Helper method sets result printer parameters
*
- * @return CsvResultPrinter
+ * @param ResultPrinter $instance
+ * @param array $parameters
+ *
+ * @return ResultPrinter
*/
- private function getInstance( $parameters = array() ) {
- $format = 'csv';
-
- $instance = new CsvResultPrinter( $format );
+ private function setParameters( ResultPrinter $instance, array
$parameters ) {
$reflector = new ReflectionClass( $this->getClass() );
$params = $reflector->getProperty( 'params' );
$params->setAccessible( true );
$params->setValue( $instance, $parameters );
+ if ( isset( $parameters['searchlabel'] ) ) {
+ $searchlabel = $reflector->getProperty( 'mSearchlabel'
);
+ $searchlabel->setAccessible( true );
+ $searchlabel->setValue( $instance,
$parameters['searchlabel'] );
+ }
+
+ if ( isset( $parameters['headers'] ) ) {
+ $searchlabel = $reflector->getProperty( 'mShowHeaders'
);
+ $searchlabel->setAccessible( true );
+ $searchlabel->setValue( $instance,
$parameters['headers'] );
+ }
+
return $instance;
+
+ }
+
+ /**
+ * Helper method that returns a CsvResultPrinter object
+ *
+ * @return CsvResultPrinter
+ */
+ private function getInstance( $parameters = array() ) {
+ return $this->setParameters( new CsvResultPrinter( 'csv' ),
$parameters );
}
/**
diff --git a/tests/phpunit/includes/queryprinters/JsonResultPrinterTest.php
b/tests/phpunit/includes/queryprinters/JsonResultPrinterTest.php
index ee0a4f3..d04c282 100644
--- a/tests/phpunit/includes/queryprinters/JsonResultPrinterTest.php
+++ b/tests/phpunit/includes/queryprinters/JsonResultPrinterTest.php
@@ -3,6 +3,7 @@
namespace SMW\Test;
use SMW\JsonResultPrinter;
+use SMW\ResultPrinter;
use ReflectionClass;
@@ -76,14 +77,14 @@
}
/**
- * Helper method that returns a JsonResultPrinter object
+ * Helper method sets result printer parameters
*
- * @return JsonResultPrinter
+ * @param ResultPrinter $instance
+ * @param array $parameters
+ *
+ * @return ResultPrinter
*/
- private function getInstance( $parameters = array() ) {
- $format = 'json';
-
- $instance = new JsonResultPrinter( $format );
+ private function setParameters( ResultPrinter $instance, array
$parameters ) {
$reflector = new ReflectionClass( $this->getClass() );
$params = $reflector->getProperty( 'params' );
@@ -96,7 +97,23 @@
$searchlabel->setValue( $instance,
$parameters['searchlabel'] );
}
+ if ( isset( $parameters['headers'] ) ) {
+ $searchlabel = $reflector->getProperty( 'mShowHeaders'
);
+ $searchlabel->setAccessible( true );
+ $searchlabel->setValue( $instance,
$parameters['headers'] );
+ }
+
return $instance;
+
+ }
+
+ /**
+ * Helper method that returns a JsonResultPrinter object
+ *
+ * @return JsonResultPrinter
+ */
+ private function getInstance( $parameters = array() ) {
+ return $this->setParameters( new JsonResultPrinter( 'json' ),
$parameters );
}
/**
diff --git a/tests/phpunit/includes/queryprinters/TableResultPrinterTest.php
b/tests/phpunit/includes/queryprinters/TableResultPrinterTest.php
new file mode 100644
index 0000000..0c769c3
--- /dev/null
+++ b/tests/phpunit/includes/queryprinters/TableResultPrinterTest.php
@@ -0,0 +1,308 @@
+<?php
+
+namespace SMW\Test;
+
+use SMW\TableResultPrinter;
+use SMW\ResultPrinter;
+use SMWPrintRequest;
+
+use ReflectionClass;
+
+/**
+ * Tests for the TableResultPrinter class
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 1.9
+ *
+ * @file
+ *
+ * @license GNU GPL v2+
+ * @author mwjames
+ */
+
+/**
+ * @covers \SMW\TableResultPrinter
+ *
+ * @ingroup Test
+ *
+ * @group SMW
+ * @group SMWExtension
+ */
+class TableResultPrinterTest extends SemanticMediaWikiTestCase {
+
+ /**
+ * Returns the name of the class to be tested
+ *
+ * @return string|false
+ */
+ public function getClass() {
+ return '\SMW\TableResultPrinter';
+ }
+
+ /**
+ * Helper method that returns a SMWPrintRequest object
+ *
+ * @since 1.9
+ *
+ * @return SMWPrintRequest
+ */
+ private function getMockPrintRequest( $text = 'Foo' ) {
+
+ $printRequest = $this->getMockBuilder( 'SMWPrintRequest' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $printRequest->expects( $this->any() )
+ ->method( 'getText' )
+ ->will( $this->returnValue( $text ) );
+
+ $printRequest->expects( $this->any() )
+ ->method( 'getMode' )
+ ->will( $this->returnValue( SMWPrintRequest::PRINT_THIS
) );
+
+ $printRequest->expects( $this->any() )
+ ->method( 'getParameter' )
+ ->will( $this->returnValue( 'center' ) );
+
+ return $printRequest;
+ }
+
+
+ /**
+ * Helper method that returns a SMWDataValue object
+ *
+ * @since 1.9
+ *
+ * @return SMWDataValue
+ */
+ private function getMockDataValue( $text = null ) {
+
+ $dataItem = $this->getSubject();
+ $typeId = '_wpg';
+
+ $dataValue = $this->getMockBuilder( 'SMWWikiPageValue' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $dataValue->expects( $this->any() )
+ ->method( 'getDataItem' )
+ ->will( $this->returnValue( $dataItem ) );
+
+ $dataValue->expects( $this->any() )
+ ->method( 'getTypeID' )
+ ->will( $this->returnValue( $typeId ) );
+
+ $dataValue->expects( $this->any() )
+ ->method( 'getShortText' )
+ ->will( $this->returnValue( $text === null ?
$dataItem->getTitle()->getText() : $text ) );
+
+ return $dataValue;
+ }
+
+ /**
+ * Helper method that returns a SMWResultArray object
+ *
+ * @since 1.9
+ *
+ * @return SMWResultArray
+ */
+ private function getMockResultArray( $text = 'Bar' ) {
+
+ $resultArray = $this->getMockBuilder( 'SMWResultArray' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $resultArray->expects( $this->any() )
+ ->method( 'getText' )
+ ->will( $this->returnValue( $text ) );
+
+ $resultArray->expects( $this->exactly( 2 ) )
+ ->method( 'getPrintRequest' )
+ ->will( $this->returnValue(
$this->getMockPrintRequest() ) );
+
+ $resultArray->expects( $this->any() )
+ ->method( 'getNextDataValue' )
+ ->will( $this->onConsecutiveCalls(
$this->getMockDataValue( $text ), false ) );
+
+ return $resultArray;
+ }
+
+ /**
+ * Helper method that returns a SMWQueryResult object
+ *
+ * @since 1.9
+ *
+ * @return SMWQueryResult
+ */
+ private function getMockQueryResult( array $printRequests, array
$resultArray ) {
+
+ $queryResult = $this->getMockBuilder( 'SMWQueryResult' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $queryResult->expects( $this->any() )
+ ->method( 'getCount' )
+ ->will( $this->returnValue( count( $resultArray ) ) );
+
+ $queryResult->expects( $this->any() )
+ ->method( 'getPrintRequests' )
+ ->will( $this->returnValue( $printRequests ) );
+
+ $queryResult->expects( $this->any() )
+ ->method( 'hasFurtherResults' )
+ ->will( $this->returnValue( true ) );
+
+ $queryResult->expects( $this->any() )
+ ->method( 'getLink' )
+ ->will( $this->returnValue( new \SMWInfolink( true,
'Lala' , 'Lula' ) ) );
+
+ // Word of caution, onConsecutiveCalls is used in order to
ensure
+ // that a while() loop is not trapped in an infinite loop and
returns
+ // a false at the end
+ $queryResult->expects( $this->any() )
+ ->method( 'getNext' )
+ ->will( $this->onConsecutiveCalls( $resultArray , false
) );
+
+ return $queryResult;
+ }
+
+ /**
+ * Helper method sets result printer parameters
+ *
+ * @param ResultPrinter $instance
+ * @param array $parameters
+ *
+ * @return ResultPrinter
+ */
+ private function setParameters( ResultPrinter $instance, array
$parameters ) {
+
+ $reflector = new ReflectionClass( $this->getClass() );
+ $params = $reflector->getProperty( 'params' );
+ $params->setAccessible( true );
+ $params->setValue( $instance, $parameters );
+
+ if ( isset( $parameters['searchlabel'] ) ) {
+ $searchlabel = $reflector->getProperty( 'mSearchlabel'
);
+ $searchlabel->setAccessible( true );
+ $searchlabel->setValue( $instance,
$parameters['searchlabel'] );
+ }
+
+ if ( isset( $parameters['headers'] ) ) {
+ $searchlabel = $reflector->getProperty( 'mShowHeaders'
);
+ $searchlabel->setAccessible( true );
+ $searchlabel->setValue( $instance,
$parameters['headers'] );
+ }
+
+ return $instance;
+
+ }
+
+ /**
+ * Helper method that returns a TableResultPrinter object
+ *
+ * @return TableResultPrinter
+ */
+ private function getInstance( $parameters = array() ) {
+ return $this->setParameters( new TableResultPrinter( 'table' ),
$parameters );
+ }
+
+ /**
+ * @test TableResultPrinter::__construct
+ *
+ * @since 1.9
+ */
+ public function testConstructor() {
+ $this->assertInstanceOf( $this->getClass(),
$this->getInstance() );
+ }
+
+ /**
+ * @test TableResultPrinter::getResultText
+ *
+ * @since 1.9
+ */
+ public function testGetResultText() {
+
+ $random = array(
+ 'pr-1' => 'PR-' . $this->getRandomString(),
+ 'pr-2' => 'PR-' . $this->getRandomString(),
+ 'ra-1' => 'RA-' . $this->getRandomString(),
+ 'ra-2' => 'RA-' . $this->getRandomString(),
+ );
+
+ $parameters = array(
+ 'headers' => SMW_HEADERS_PLAIN,
+ 'class' => 'tableClass',
+ 'format' => 'table',
+ 'offset' => 0,
+ 'transpose' => false
+ );
+
+ // Table matcher, expecting randomly generate strings
+ // to be present in a certain order and context
+ $matcher = array(
+ 'tag' => 'table', 'attributes' => array( 'class' =>
$parameters['class'] ),
+ 'descendant' => array(
+ 'tag' => 'th', 'content' => $random['pr-1'],
'attributes' => array( 'class' => $random['pr-1'] ),
+ 'tag' => 'th', 'content' => $random['pr-2'],
'attributes' => array( 'class' => $random['pr-2'] ),
+ ),
+ 'descendant' => array(
+ 'tag' => 'tr',
+ 'child' => array(
+ 'tag' => 'td', 'content' =>
$random['ra-1'], 'attributes' => array( 'class' => $random['pr-1'] ),
+ 'tag' => 'td', 'content' =>
$random['ra-2'], 'attributes' => array( 'class' => $random['pr-2'] )
+ )
+ ),
+ 'descendant' => array(
+ 'tag' => 'tr', 'attributes' => array( 'class'
=> 'smwfooter' ),
+ 'child' => array(
+ 'tag' => 'td', 'attributes' => array(
'class' => 'sortbottom' ),
+ )
+ )
+ );
+
+ // Set-up and inject necessary objects
+ $instance = $this->getInstance( $parameters );
+
+ $printRequests = array(
+ $this->getMockPrintRequest( $random['pr-1'] ),
+ $this->getMockPrintRequest( $random['pr-2'] )
+ );
+ $resultArray = array(
+ $this->getMockResultArray( $random['ra-1'] ),
+ $this->getMockResultArray( $random['ra-2'] )
+ );
+
+ // Access protected methods and properties
+ $reflector = new ReflectionClass( $this->getClass() );
+
+ $property = $reflector->getProperty( 'fullParams' );
+ $property->setAccessible( true );
+ $property->setValue( $instance, array() );
+
+ $method = $reflector->getMethod( 'linkFurtherResults' );
+ $method->setAccessible( true );
+ $method->invoke( $instance, $this->getMockQueryResult(
$printRequests, $resultArray ) );
+
+ $method = $reflector->getMethod( 'getResultText' );
+ $method->setAccessible( true );
+
+ $result = $method->invoke( $instance,
$this->getMockQueryResult( $printRequests, $resultArray ), SMW_OUTPUT_FILE );
+ $this->assertInternalType( 'string', $result );
+ $this->assertTag( $matcher, $result );
+
+ }
+}
--
To view, visit https://gerrit.wikimedia.org/r/71177
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I88337f9cf14abd84bf95770c29e6fdcf86f63743
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