jenkins-bot has submitted this change and it was merged.

Change subject: Improve \SMW\CsvResultPrinterTest
......................................................................


Improve \SMW\CsvResultPrinterTest

Running a standard test

Change-Id: Ife3ea64ab33910ca71ee51a75ea2a4be3d6bd22d
---
M tests/phpunit/MockObjectRepository.php
M tests/phpunit/includes/queryprinters/CsvResultPrinterTest.php
2 files changed, 133 insertions(+), 21 deletions(-)

Approvals:
  Mwjames: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/phpunit/MockObjectRepository.php 
b/tests/phpunit/MockObjectRepository.php
index f6ccdd3..f412aba 100644
--- a/tests/phpunit/MockObjectRepository.php
+++ b/tests/phpunit/MockObjectRepository.php
@@ -413,6 +413,10 @@
                        ->will( $this->returnValue( $this->builder->setValue( 
'getShortText' ) ) );
 
                $dataValue->expects( $this->any() )
+                       ->method( 'getWikiValue' )
+                       ->will( $this->returnValue( $this->builder->setValue( 
'getWikiValue' ) ) );
+
+               $dataValue->expects( $this->any() )
                        ->method( 'getShortWikiText' )
                        ->will( $this->returnValue( $this->builder->setValue( 
'getShortWikiText' ) ) );
 
diff --git a/tests/phpunit/includes/queryprinters/CsvResultPrinterTest.php 
b/tests/phpunit/includes/queryprinters/CsvResultPrinterTest.php
index ef6856f..4ffed63 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 SMWDataItem;
 
 /**
  * Tests for the CsvResultPrinter class
@@ -35,27 +36,11 @@
        }
 
        /**
-        * Helper method that returns a SMWQueryResult object
-        *
-        * @since 1.9
-        *
-        * @return SMWQueryResult
-        */
-       private function getMockQueryResult() {
-
-               $queryResult = $this->getMockBuilder( 'SMWQueryResult' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
-               return $queryResult;
-       }
-
-       /**
         * Helper method that returns a CsvResultPrinter object
         *
         * @return CsvResultPrinter
         */
-       private function getInstance( $parameters = array() ) {
+       private function newInstance( $parameters = array() ) {
                return $this->setParameters( new CsvResultPrinter( 'csv' ), 
$parameters );
        }
 
@@ -65,7 +50,7 @@
         * @since 1.9
         */
        public function testConstructor() {
-               $this->assertInstanceOf( $this->getClass(), 
$this->getInstance() );
+               $this->assertInstanceOf( $this->getClass(), 
$this->newInstance() );
        }
 
        /**
@@ -75,10 +60,133 @@
         */
        public function testGetFileName() {
 
-               $filename = $this->getRandomString() . ' ' . 
$this->getRandomString();
-               $instance = $this->getInstance( array( 'filename' => $filename 
) );
+               $filename = 'FooQueey';
+               $instance = $this->newInstance( array( 'filename' => $filename 
) );
 
-               $this->assertEquals( $filename, $instance->getFileName( 
$this->getMockQueryResult() ) );
+               $this->assertEquals( $filename, $instance->getFileName( 
$this->newMockBuilder()->newObject( 'QueryResult' ) ) );
+       }
+
+       /**
+        * @test CsvResultPrinter::getResultText
+        * @dataProvider resultDataProvider
+        *
+        * @since 1.9
+        */
+       public function testGetResultText(  $setup, $expected  ) {
+
+               $instance  = $this->newInstance( $setup['parameters'] );
+               $reflector = $this->newReflector();
+
+               $property = $reflector->getProperty( 'fullParams' );
+               $property->setAccessible( true );
+               $property->setValue( $instance, array() );
+
+               $method = $reflector->getMethod( 'linkFurtherResults' );
+               $method->setAccessible( true );
+               $method->invoke( $instance, $setup['queryResult'] );
+
+               $method = $reflector->getMethod( 'getResultText' );
+               $method->setAccessible( true );
+
+               $result = $method->invoke( $instance, $setup['queryResult'], 
$setup['outputMode'] );
+
+               $this->assertInternalType(
+                       'string',
+                       $result,
+                       'Asserts that the result always returns a string'
+               );
+
+               $this->assertEquals(
+                       $expected['result'],
+                       $result,
+                       'Asserts that getResultText() yields the expected 
result'
+               );
+
+       }
+
+       /**
+        * @return array
+        */
+       public function resultDataProvider() {
+
+               $provider = array();
+
+               $setup = array(
+                       array( 'printRequest' => 'Foo', 'dataValue' => 'Quuey' 
),
+                       array( 'printRequest' => 'Bar', 'dataValue' => 'Quuey' 
),
+                       array( 'printRequest' => 'Bam', 'dataValue' => 'Xuuey' )
+               );
+
+               // #0
+               $parameters = array(
+                       'headers'   => SMW_HEADERS_PLAIN,
+                       'format'    => 'csv',
+                       'sep'       => ',',
+                       'showsep'   => false,
+                       'offset'    => 0
+               );
+
+               $provider[] = array(
+                       array(
+                               'parameters'  => $parameters,
+                               'queryResult' => $this->buildMockQueryResult( 
$setup ),
+                               'outputMode'  => SMW_OUTPUT_FILE
+                       ),
+                       array(
+                               'result'     => implode( ',', array(  'Foo', 
'Bar', 'Bam' ) ) . "\n" .  implode( ',', array(  'Quuey', 'Quuey', 'Xuuey' ) ) 
. "\n"
+                       )
+               );
+
+               return $provider;
+
+       }
+
+       /**
+        * @return QueryResult
+        */
+       private function buildMockQueryResult( $setup ) {
+
+               $printRequests = array();
+               $resultArray   = array();
+
+               foreach ( $setup as $value ) {
+
+                       $printRequest = $this->newMockBuilder()->newObject( 
'PrintRequest', array(
+                               'getText'  => $value['printRequest'],
+                               'getLabel' => $value['printRequest']
+                       ) );
+
+                       $printRequests[] = $printRequest;
+
+                       $dataItem = $this->newMockBuilder()->newObject( 
'DataItem', array(
+                               'getDIType'  => SMWDataItem::TYPE_WIKIPAGE,
+                       ) );
+
+                       $dataValue = $this->newMockBuilder()->newObject( 
'DataValue', array(
+                               'DataValueType'    => 'SMWWikiPageValue',
+                               'getTypeID'        => '_wpg',
+                               'getShortWikiText' => $value['dataValue'],
+                               'getWikiValue'     => $value['dataValue'],
+                               'getDataItem'      => $dataItem
+                       ) );
+
+                       $resultArray[] = $this->newMockBuilder()->newObject( 
'ResultArray', array(
+                               'getText'          => $value['printRequest'],
+                               'getPrintRequest'  => $printRequest,
+                               'getNextDataValue' => $dataValue,
+                               'getNextDataItem'  => $dataItem
+                       ) );
+
+               }
+
+               $queryResult = $this->newMockBuilder()->newObject( 
'QueryResult', array(
+                       'getPrintRequests'  => $printRequests,
+                       'getNext'           => $resultArray,
+                       'getLink'           => new \SMWInfolink( true, 'Lala' , 
'Lula' ),
+                       'hasFurtherResults' => true
+               ) );
+
+               return $queryResult;
        }
 
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/84971
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ife3ea64ab33910ca71ee51a75ea2a4be3d6bd22d
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

Reply via email to