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

Change subject: Introduce Wikibase\View\HtmlSnakFormatterFactory
......................................................................


Introduce Wikibase\View\HtmlSnakFormatterFactory

Change-Id: I077c324a7c76977f68353a3cf0584b6559e8be1a
---
M repo/includes/View/EntityViewFactory.php
A repo/includes/WikibaseHtmlSnakFormatterFactory.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
A repo/tests/phpunit/includes/WikibaseHtmlSnakFormatterFactoryTest.php
A view/src/HtmlSnakFormatterFactory.php
6 files changed, 176 insertions(+), 64 deletions(-)

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



diff --git a/repo/includes/View/EntityViewFactory.php 
b/repo/includes/View/EntityViewFactory.php
index 836cabb..c46b6cc 100644
--- a/repo/includes/View/EntityViewFactory.php
+++ b/repo/includes/View/EntityViewFactory.php
@@ -6,17 +6,15 @@
 use InvalidArgumentException;
 use Language;
 use SiteStore;
-use ValueFormatters\FormatterOptions;
-use ValueFormatters\ValueFormatter;
 use Wikibase\LanguageFallbackChain;
 use Wikibase\Lib\EntityIdFormatter;
 use Wikibase\Lib\LanguageNameLookup;
-use Wikibase\Lib\OutputFormatSnakFormatterFactory;
 use Wikibase\Lib\SnakFormatter;
 use Wikibase\Lib\Store\EntityLookup;
 use Wikibase\Lib\Store\LabelLookup;
 use Wikibase\Template\TemplateFactory;
 use Wikibase\View\EntityIdFormatterFactory;
+use Wikibase\View\HtmlSnakFormatterFactory;
 
 /**
  * @since 0.5
@@ -27,9 +25,9 @@
 class EntityViewFactory {
 
        /**
-        * @var OutputFormatSnakFormatterFactory
+        * @var HtmlSnakFormatterFactory
         */
-       private $snakFormatterFactory;
+       private $htmlSnakFormatterFactory;
 
        /**
         * @var EntityIdFormatterFactory
@@ -78,7 +76,7 @@
 
        /**
         * @param EntityIdFormatterFactory $idFormatterFactory
-        * @param OutputFormatSnakFormatterFactory $snakFormatterFactory
+        * @param HtmlSnakFormatterFactory $htmlSnakFormatterFactory
         * @param EntityLookup $entityLookup
         * @param SiteStore $siteStore
         * @param DataTypeFactory $dataTypeFactory
@@ -90,7 +88,7 @@
         */
        public function __construct(
                EntityIdFormatterFactory $idFormatterFactory,
-               OutputFormatSnakFormatterFactory $snakFormatterFactory,
+               HtmlSnakFormatterFactory $htmlSnakFormatterFactory,
                EntityLookup $entityLookup,
                SiteStore $siteStore,
                DataTypeFactory $dataTypeFactory,
@@ -103,7 +101,7 @@
                $this->checkOutputFormat( 
$idFormatterFactory->getOutputFormat() );
 
                $this->idFormatterFactory = $idFormatterFactory;
-               $this->snakFormatterFactory = $snakFormatterFactory;
+               $this->htmlSnakFormatterFactory = $htmlSnakFormatterFactory;
                $this->entityLookup = $entityLookup;
                $this->siteStore = $siteStore;
                $this->dataTypeFactory = $dataTypeFactory;
@@ -134,7 +132,7 @@
         * @param string $entityType
         * @param string $languageCode
         * @param LabelLookup $labelLookup
-        * @param LanguageFallbackChain|null $fallbackChain
+        * @param LanguageFallbackChain $fallbackChain
         * @param bool $editable
         *
         * @throws InvalidArgumentException
@@ -144,7 +142,7 @@
                $entityType,
                $languageCode,
                LabelLookup $labelLookup,
-               LanguageFallbackChain $fallbackChain = null,
+               LanguageFallbackChain $fallbackChain,
                $editable = true
         ) {
                $editSectionGenerator = $editable ? new 
ToolbarEditSectionGenerator(
@@ -199,7 +197,7 @@
 
        /**
         * @param string $languageCode
-        * @param LanguageFallbackChain|null $fallbackChain
+        * @param LanguageFallbackChain $fallbackChain
         * @param LabelLookup $labelLookup
         * @param EditSectionGenerator $editSectionGenerator
         *
@@ -207,7 +205,7 @@
         */
        private function newStatementGroupListView(
                $languageCode,
-               LanguageFallbackChain $fallbackChain = null,
+               LanguageFallbackChain $fallbackChain,
                LabelLookup $labelLookup,
                EditSectionGenerator $editSectionGenerator
        ) {
@@ -215,7 +213,7 @@
 
                $snakHtmlGenerator = new SnakHtmlGenerator(
                        $this->templateFactory,
-                       $this->getSnakFormatter( $languageCode, $fallbackChain, 
$labelLookup ),
+                       $this->htmlSnakFormatterFactory->getSnakFormatter( 
$languageCode, $fallbackChain, $labelLookup ),
                        $propertyIdFormatter
                );
 
@@ -244,52 +242,6 @@
                        $editSectionGenerator,
                        $this->languageNameLookup,
                        $languageCode
-               );
-       }
-
-       /**
-        * @param $languageCode
-        * @param LanguageFallbackChain $languageFallbackChain
-        * @param LabelLookup $labelLookup
-        *
-        * @return FormatterOptions
-        */
-       private function getFormatterOptions(
-               $languageCode,
-               LanguageFallbackChain $languageFallbackChain = null,
-               LabelLookup $labelLookup = null
-       ) {
-               $formatterOptions = new FormatterOptions();
-               $formatterOptions->setOption( ValueFormatter::OPT_LANG, 
$languageCode );
-
-               if ( $languageFallbackChain ) {
-                       $formatterOptions->setOption( 'languages', 
$languageFallbackChain );
-               }
-
-               if ( $labelLookup ) {
-                       $formatterOptions->setOption( 'LabelLookup', 
$labelLookup );
-               }
-
-               return $formatterOptions;
-       }
-
-       /**
-        * @param string $languageCode
-        * @param LanguageFallbackChain|null $languageFallbackChain
-        * @param LabelLookup|null $labelLookup
-        *
-        * @return SnakFormatter
-        */
-       private function getSnakFormatter(
-               $languageCode,
-               LanguageFallbackChain $languageFallbackChain = null,
-               LabelLookup $labelLookup = null
-       ) {
-               $formatterOptions = $this->getFormatterOptions( $languageCode, 
$languageFallbackChain, $labelLookup );
-
-               return $this->snakFormatterFactory->getSnakFormatter(
-                       SnakFormatter::FORMAT_HTML_WIDGET,
-                       $formatterOptions
                );
        }
 
diff --git a/repo/includes/WikibaseHtmlSnakFormatterFactory.php 
b/repo/includes/WikibaseHtmlSnakFormatterFactory.php
new file mode 100644
index 0000000..1544bd9
--- /dev/null
+++ b/repo/includes/WikibaseHtmlSnakFormatterFactory.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace Wikibase\Repo;
+
+use ValueFormatters\FormatterOptions;
+use ValueFormatters\ValueFormatter;
+use Wikibase\LanguageFallbackChain;
+use Wikibase\Lib\OutputFormatSnakFormatterFactory;
+use Wikibase\Lib\SnakFormatter;
+use Wikibase\Lib\Store\LabelLookup;
+use Wikibase\View\HtmlSnakFormatterFactory;
+
+/**
+ * An HtmlSnakFormatterFactory implementation using an 
OutputFormatSnakFormatterFactory
+ *
+ * @author Adrian Heine < adrian.he...@wikimedia.de >
+ */
+class WikibaseHtmlSnakFormatterFactory implements HtmlSnakFormatterFactory {
+
+       /**
+        * @var OutputFormatSnakFormatterFactory
+        */
+       private $snakFormatterFactory;
+
+       /**
+        * @param OutputFormatSnakFormatterFactory $snakFormatterFactory
+        */
+       public function __construct( OutputFormatSnakFormatterFactory 
$snakFormatterFactory ) {
+               $this->snakFormatterFactory = $snakFormatterFactory;
+       }
+
+       /**
+        * @param string $languageCode
+        * @param LanguageFallbackChain $languageFallbackChain
+        * @param LabelLookup $labelLookup
+        *
+        * @return FormatterOptions
+        */
+       private function getFormatterOptions(
+               $languageCode,
+               LanguageFallbackChain $languageFallbackChain,
+               LabelLookup $labelLookup
+       ) {
+               $formatterOptions = new FormatterOptions( array(
+                       ValueFormatter::OPT_LANG => $languageCode,
+                       'languages' => $languageFallbackChain,
+                       'LabelLookup' => $labelLookup,
+               ) );
+               return $formatterOptions;
+       }
+
+       /**
+        * @param string $languageCode
+        * @param LanguageFallbackChain $languageFallbackChain
+        * @param LabelLookup $labelLookup
+        *
+        * @return SnakFormatter
+        */
+       public function getSnakFormatter(
+               $languageCode,
+               LanguageFallbackChain $languageFallbackChain,
+               LabelLookup $labelLookup
+       ) {
+               $formatterOptions = $this->getFormatterOptions( $languageCode, 
$languageFallbackChain, $labelLookup );
+
+               return $this->snakFormatterFactory->getSnakFormatter(
+                       SnakFormatter::FORMAT_HTML_WIDGET,
+                       $formatterOptions
+               );
+       }
+
+}
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 1e98ca7..0b31fd2 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -1014,7 +1014,7 @@
 
                $entityViewFactory = new EntityViewFactory(
                        $this->getEntityIdHtmlLinkFormatterFactory(),
-                       $this->getSnakFormatterFactory(),
+                       $this->getHtmlSnakFormatterFactory(),
                        $this->getEntityLookup(),
                        $this->getSiteStore(),
                        $this->getDataTypeFactory(),
@@ -1064,4 +1064,8 @@
                return new WikibaseContentLanguages();
        }
 
+       private function getHtmlSnakFormatterFactory() {
+               return new WikibaseHtmlSnakFormatterFactory( 
$this->getSnakFormatterFactory() );
+       }
+
 }
diff --git a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php 
b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
index 717ed5e..489f45c 100644
--- a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
+++ b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
@@ -63,12 +63,15 @@
        public function testNewEntityView_withInvalidType() {
                $entityViewFactory = $this->getEntityViewFactory();
 
+               $languageFallback = new LanguageFallbackChain( array() );
+
                $this->setExpectedException( 'InvalidArgumentException' );
 
                $entityViewFactory->newEntityView(
                        'kittens',
                        'de',
-                       $this->getMock( 'Wikibase\Lib\Store\LabelLookup' )
+                       $this->getMock( 'Wikibase\Lib\Store\LabelLookup' ),
+                       $languageFallback
                );
        }
 
@@ -109,9 +112,7 @@
                        ->method( 'getFormat' )
                        ->will( $this->returnValue( SnakFormatter::FORMAT_HTML 
) );
 
-               $snakFormatterFactory = $this->getMockBuilder( 
'Wikibase\Lib\OutputFormatSnakFormatterFactory' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
+               $snakFormatterFactory = $this->getMock( 
'Wikibase\View\HtmlSnakFormatterFactory' );
 
                $snakFormatterFactory->expects( $this->any() )
                        ->method( 'getSnakFormatter' )
diff --git 
a/repo/tests/phpunit/includes/WikibaseHtmlSnakFormatterFactoryTest.php 
b/repo/tests/phpunit/includes/WikibaseHtmlSnakFormatterFactoryTest.php
new file mode 100644
index 0000000..6f8c17b
--- /dev/null
+++ b/repo/tests/phpunit/includes/WikibaseHtmlSnakFormatterFactoryTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Wikibase\Repo\Test;
+
+use PHPUnit_Framework_TestCase;
+use ValueFormatters\FormatterOptions;
+use ValueFormatters\ValueFormatter;
+use Wikibase\LanguageFallbackChain;
+use Wikibase\Lib\SnakFormatter;
+use Wikibase\Repo\WikibaseHtmlSnakFormatterFactory;
+
+/**
+ * @covers Wikibase\Repo\WikibaseHtmlSnakFormatterFactory
+ *
+ * @group Wikibase
+ * @group WikibaseRepo
+ *
+ * @license GPL 2+
+ * @author Adrian Heine <adrian.he...@wikimedia.de>
+ */
+class WikibaseHtmlSnakFormatterFactoryTest extends PHPUnit_Framework_TestCase {
+
+       public function testGetSnakFormatter() {
+               $snakFormatter = $this->getMock( 'Wikibase\Lib\SnakFormatter' );
+               $languageFallbackChain = new LanguageFallbackChain( array() );
+               $labelLookup = $this->getMock( 'Wikibase\Lib\Store\LabelLookup' 
);
+
+               $outputFormatSnakFormatterFactory = $this->getMockBuilder( 
'Wikibase\Lib\OutputFormatSnakFormatterFactory' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $outputFormatSnakFormatterFactory->expects( $this->once() )
+                       ->method( 'getSnakFormatter' )
+                       ->with(
+                               SnakFormatter::FORMAT_HTML_WIDGET,
+                               new FormatterOptions( array(
+                                       ValueFormatter::OPT_LANG => 'en',
+                                       'languages' => $languageFallbackChain,
+                                       'LabelLookup' => $labelLookup
+                               ) )
+                       )
+                       ->will( $this->returnValue( $snakFormatter ) );
+
+               $factory = new WikibaseHtmlSnakFormatterFactory( 
$outputFormatSnakFormatterFactory );
+
+               $snakFormatterReturned = $factory->getSnakFormatter(
+                       'en',
+                       $languageFallbackChain,
+                       $labelLookup
+               );
+               $this->assertEquals( $snakFormatter, $snakFormatterReturned );
+       }
+
+}
diff --git a/view/src/HtmlSnakFormatterFactory.php 
b/view/src/HtmlSnakFormatterFactory.php
new file mode 100644
index 0000000..7ea8fef
--- /dev/null
+++ b/view/src/HtmlSnakFormatterFactory.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Wikibase\View;
+
+use Wikibase\LanguageFallbackChain;
+use Wikibase\Lib\SnakFormatter;
+use Wikibase\Lib\Store\LabelLookup;
+
+/**
+ * A factory constructing SnakFormatters that output HTML.
+ * @since 0.5
+ * @author Adrian Heine < adrian.he...@wikimedia.de >
+ */
+interface HtmlSnakFormatterFactory {
+
+       /**
+        * @param string $languageCode
+        * @param LanguageFallbackChain $languageFallbackChain
+        * @param LabelLookup $labelLookup
+        *
+        * @return SnakFormatter
+        */
+       public function getSnakFormatter(
+               $languageCode,
+               LanguageFallbackChain $languageFallbackChain,
+               LabelLookup $labelLookup
+       );
+
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I077c324a7c76977f68353a3cf0584b6559e8be1a
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <adrian.he...@wikimedia.de>
Gerrit-Reviewer: Adrian Lang <adrian.he...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to