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

Change subject: Rewrite option handling in UnDeserializableValueFormatter
......................................................................


Rewrite option handling in UnDeserializableValueFormatter

This fixes a series of smaller issues with this class:

* Options should be strings, maybe ints, but never arrays or objects.
  You can not use such an option in an API call. This is what the
  options are made for. We do misuse the options in some cases, but I
  do not think this is necesarry here.

* The constant should be named OPT_...

* The name of an option should be specific to avoid conflicts with
  other formatters that use the same options object. The "lang" option
  in the base class is fine because it's used by many formatters. But
  the "message" option here is specific for this formatter.

Change-Id: I48a7b0d89ebd3f7e6f944e158f6dd2afa00b8eb7
---
M lib/includes/formatters/UnDeserializableValueFormatter.php
M lib/tests/phpunit/formatters/UnDeserializableValueFormatterTest.php
2 files changed, 7 insertions(+), 37 deletions(-)

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



diff --git a/lib/includes/formatters/UnDeserializableValueFormatter.php 
b/lib/includes/formatters/UnDeserializableValueFormatter.php
index 6cba065..41ef56f 100644
--- a/lib/includes/formatters/UnDeserializableValueFormatter.php
+++ b/lib/includes/formatters/UnDeserializableValueFormatter.php
@@ -3,7 +3,6 @@
 namespace Wikibase\Lib;
 
 use DataValues\DataValue;
-use Message;
 use ValueFormatters\FormatterOptions;
 use ValueFormatters\ValueFormatterBase;
 
@@ -17,7 +16,7 @@
  */
 class UnDeserializableValueFormatter extends ValueFormatterBase {
 
-       const MESSAGE = 'message';
+       const OPT_MESSAGE_KEY = 'unDeserializableMessage';
 
        /**
         * @param FormatterOptions|null $options
@@ -25,7 +24,7 @@
        public function __construct( FormatterOptions $options = null ) {
                parent::__construct( $options );
 
-               $this->defaultOption( self::MESSAGE, new Message( 
'wikibase-undeserializable-value' ) );
+               $this->defaultOption( self::OPT_MESSAGE_KEY, 
'wikibase-undeserializable-value' );
        }
 
        /**
@@ -38,13 +37,10 @@
         * @return string
         */
        public function format( $dataValue ) {
-               $langCode = $this->options->getOption( self::OPT_LANG );
+               $languageCode = $this->options->getOption( self::OPT_LANG );
+               $messageKey = $this->options->getOption( self::OPT_MESSAGE_KEY 
);
 
-               /** @var Message $msg */
-               $msg = $this->options->getOption( self::MESSAGE );
-               $msg = $msg->inLanguage( $langCode );
-
-               return $msg->text();
+               return wfMessage( $messageKey )->inLanguage( $languageCode 
)->text();
        }
 
 }
diff --git 
a/lib/tests/phpunit/formatters/UnDeserializableValueFormatterTest.php 
b/lib/tests/phpunit/formatters/UnDeserializableValueFormatterTest.php
index f66fd45..aac31b1 100644
--- a/lib/tests/phpunit/formatters/UnDeserializableValueFormatterTest.php
+++ b/lib/tests/phpunit/formatters/UnDeserializableValueFormatterTest.php
@@ -2,8 +2,6 @@
 
 namespace Wikibase\Lib\Test;
 
-use DataValues\UnDeserializableValue;
-use Message;
 use PHPUnit_Framework_TestCase;
 use ValueFormatters\FormatterOptions;
 use ValueFormatters\ValueFormatter;
@@ -20,38 +18,14 @@
  */
 class UnDeserializableValueFormatterTest extends PHPUnit_Framework_TestCase {
 
-       /**
-        * @return Message
-        */
-       private function getMessage() {
-               $message = $this->getMock( 'Message',
-                       array( 'text' ),
-                       array( 'wikibase-undeserializable-value' )
-               );
-
-               $message->expects( $this->any() )
-                       ->method( 'text' )
-                       ->will( $this->returnValue( 'bad value' ) );
-
-               return $message;
-       }
-
        public function testFormat() {
-               $message = $this->getMessage();
-
                $options = new FormatterOptions( array(
-                       ValueFormatter::OPT_LANG => 'en',
-                       UnDeserializableValueFormatter::MESSAGE => $message
+                       ValueFormatter::OPT_LANG => 'qqx',
                ) );
 
                $formatter = new UnDeserializableValueFormatter( $options );
-               $value = new UnDeserializableValue(
-                       'cookie',
-                       'string',
-                       'cannot understand!'
-               );
 
-               $this->assertEquals( $message->text(), $formatter->format( 
$value ) );
+               $this->assertSame( '(wikibase-undeserializable-value)', 
$formatter->format( null ) );
        }
 
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I48a7b0d89ebd3f7e6f944e158f6dd2afa00b8eb7
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jonas Kress (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