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

Change subject: Fix #property parser function's default language
......................................................................


Fix #property parser function's default language

I used git bisect to find that this bug was introduced in
https://gerrit.wikimedia.org/r/243640

Change-Id: I76a9615fc723034ad22f395c6aa760c06345c589
Fixes: T116503
(cherry picked from commit e458e8c1c2c822fbaa52713e46c059e4d7182d1c)
---
M lib/includes/formatters/OutputFormatSnakFormatterFactory.php
M lib/includes/formatters/OutputFormatValueFormatterFactory.php
M lib/tests/phpunit/formatters/OutputFormatSnakFormatterFactoryTest.php
3 files changed, 43 insertions(+), 19 deletions(-)

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



diff --git a/lib/includes/formatters/OutputFormatSnakFormatterFactory.php 
b/lib/includes/formatters/OutputFormatSnakFormatterFactory.php
index 1dc158f..bf03a82 100644
--- a/lib/includes/formatters/OutputFormatSnakFormatterFactory.php
+++ b/lib/includes/formatters/OutputFormatSnakFormatterFactory.php
@@ -61,7 +61,6 @@
         * @return SnakFormatter
         */
        public function getSnakFormatter( $format, FormatterOptions $options ) {
-               $options->defaultOption( SnakFormatter::OPT_LANG, 'en' );
                $options->defaultOption( SnakFormatter::OPT_ON_ERROR, 
SnakFormatter::ON_ERROR_WARN );
 
                $this->valueFormatterFactory->applyLanguageDefaults( $options );
diff --git a/lib/includes/formatters/OutputFormatValueFormatterFactory.php 
b/lib/includes/formatters/OutputFormatValueFormatterFactory.php
index cf4200c..e3bb294 100644
--- a/lib/includes/formatters/OutputFormatValueFormatterFactory.php
+++ b/lib/includes/formatters/OutputFormatValueFormatterFactory.php
@@ -97,9 +97,7 @@
         * @todo: this shouldn't be public at all. Perhaps factor it out into a 
helper class.
         */
        public function applyLanguageDefaults( FormatterOptions $options ) {
-               if ( !$options->hasOption( ValueFormatter::OPT_LANG ) ) {
-                       $options->setOption( ValueFormatter::OPT_LANG, 
$this->defaultLanguage->getCode() );
-               }
+               $options->defaultOption( ValueFormatter::OPT_LANG, 
$this->defaultLanguage->getCode() );
 
                $lang = $options->getOption( ValueFormatter::OPT_LANG );
                if ( !is_string( $lang ) ) {
diff --git 
a/lib/tests/phpunit/formatters/OutputFormatSnakFormatterFactoryTest.php 
b/lib/tests/phpunit/formatters/OutputFormatSnakFormatterFactoryTest.php
index 0b45b3a..2bc85a6 100644
--- a/lib/tests/phpunit/formatters/OutputFormatSnakFormatterFactoryTest.php
+++ b/lib/tests/phpunit/formatters/OutputFormatSnakFormatterFactoryTest.php
@@ -7,6 +7,7 @@
 use DataValues\StringValue;
 use Language;
 use ValueFormatters\FormatterOptions;
+use ValueFormatters\ValueFormatter;
 use Wikibase\DataModel\Entity\PropertyId;
 use Wikibase\DataModel\Snak\PropertyValueSnak;
 use Wikibase\LanguageFallbackChainFactory;
@@ -31,26 +32,29 @@
                $self = $this;
                $callbacks = array(
                        'VT:string' => function( $format, FormatterOptions 
$options ) use ( $self ) {
-                               return $format === SnakFormatter::FORMAT_PLAIN 
? $self->makeMockValueFormatter() : null;
+                               return $format === SnakFormatter::FORMAT_PLAIN
+                                       ? $self->makeMockValueFormatter()
+                                       : null;
                        },
                );
-
-               $dataTypeFactory = new DataTypeFactory( array(
-                       'string' => 'string'
-               ) );
-
-               $dataTypeLookup = $this->getMock( 
'Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup' );
-               $dataTypeLookup->expects( $this->any() )
-                       ->method( 'getDataTypeIdForProperty' )
-                       ->will( $this->returnValue( 'string' ) );
-
                $valueFormatterFactory = new OutputFormatValueFormatterFactory(
                        $callbacks,
                        Language::factory( 'en' ),
                        new LanguageFallbackChainFactory()
                );
 
-               return new OutputFormatSnakFormatterFactory( 
$valueFormatterFactory, $dataTypeLookup, $dataTypeFactory );
+               $dataTypeLookup = $this->getMock(
+                       
'Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup'
+               );
+               $dataTypeLookup->expects( $this->any() )
+                       ->method( 'getDataTypeIdForProperty' )
+                       ->will( $this->returnValue( 'string' ) );
+
+               return new OutputFormatSnakFormatterFactory(
+                       $valueFormatterFactory,
+                       $dataTypeLookup,
+                       new DataTypeFactory( array( 'string' => 'string' ) )
+               );
        }
 
        public function makeMockValueFormatter() {
@@ -68,7 +72,6 @@
        }
 
        public function getSnakFormatterProvider() {
-
                return array(
                        'plain' => array(
                                SnakFormatter::FORMAT_PLAIN,
@@ -117,11 +120,35 @@
        /**
         * @dataProvider getSnakFormatterProvider_options
         */
-       public function testGetSnakFormatter_options( $options, $expectedType ) 
{
+       public function testGetSnakFormatter_options( array $options, 
$expectedType ) {
                $factory = $this->newOutputFormatSnakFormatterFactory();
-               $formatter = $factory->getSnakFormatter( 
SnakFormatter::FORMAT_WIKI, new FormatterOptions( $options ) );
+               $formatter = $factory->getSnakFormatter(
+                       SnakFormatter::FORMAT_WIKI,
+                       new FormatterOptions( $options )
+               );
 
                $this->assertInstanceOf( $expectedType, $formatter );
        }
 
+       public function testGetSnakFormatter_languageOption() {
+               $self = $this;
+               $callbacks = array(
+                       'VT:string' => function( $format, FormatterOptions 
$options ) use ( $self ) {
+                               $self->assertSame( 'de', $options->getOption( 
ValueFormatter::OPT_LANG ) );
+                       },
+               );
+               $valueFormatterFactory = new OutputFormatValueFormatterFactory(
+                       $callbacks,
+                       Language::factory( 'de' ),
+                       new LanguageFallbackChainFactory()
+               );
+
+               $factory = new OutputFormatSnakFormatterFactory(
+                       $valueFormatterFactory,
+                       $this->getMock( 
'Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup' ),
+                       new DataTypeFactory( array() )
+               );
+               $factory->getSnakFormatter( SnakFormatter::FORMAT_PLAIN, new 
FormatterOptions() );
+       }
+
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I76a9615fc723034ad22f395c6aa760c06345c589
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.27.0-wmf.5
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: JanZerebecki <[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

Reply via email to