Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/196635

Change subject: Use HtmlTimeFormatter in TimeDetailsFormatter
......................................................................

Use HtmlTimeFormatter in TimeDetailsFormatter

This solves two problems:

Diffs for TimeValues should use the same formatter in their heading
(above the details) as in the actual Statements.

This heading formatter used in the detail formatter should be injectable
so it can be mocked in the test.

Change-Id: I578e4ad33a32a68a5d35fe3a48259c5cd861755d
---
M lib/includes/formatters/TimeDetailsFormatter.php
M lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
2 files changed, 34 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/35/196635/1

diff --git a/lib/includes/formatters/TimeDetailsFormatter.php 
b/lib/includes/formatters/TimeDetailsFormatter.php
index 3939c03..c4d029b 100644
--- a/lib/includes/formatters/TimeDetailsFormatter.php
+++ b/lib/includes/formatters/TimeDetailsFormatter.php
@@ -23,17 +23,25 @@
 class TimeDetailsFormatter extends ValueFormatterBase {
 
        /**
-        * @var ValueFormatter
+        * @var ValueFormatter A TimeValue formatter that outputs HTML.
         */
        private $timeFormatter;
 
        /**
         * @param FormatterOptions|null $options
+        * @param ValueFormatter|null $timeFormatter A TimeValue formatter that 
outputs a single line of
+        * HTML, suitable for headings.
         */
-       public function __construct( FormatterOptions $options = null ) {
+       public function __construct(
+               FormatterOptions $options = null,
+               ValueFormatter $timeFormatter = null
+       ) {
                parent::__construct( $options );
 
-               $this->timeFormatter = new MwTimeIsoFormatter( $this->options );
+               $this->timeFormatter = $timeFormatter ?: new HtmlTimeFormatter(
+                       $this->options,
+                       new MwTimeIsoFormatter( $this->options )
+               );
        }
 
        /**
@@ -53,7 +61,7 @@
                }
 
                $html = '';
-               $html .= Html::element(
+               $html .= Html::rawElement(
                        'h4',
                        array( 'class' => 'wb-details wb-time-details 
wb-time-rendered' ),
                        $this->timeFormatter->format( $value )
diff --git a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php 
b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
index 637b0c7..517a7cd 100644
--- a/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
+++ b/lib/tests/phpunit/formatters/TimeDetailsFormatterTest.php
@@ -11,6 +11,7 @@
 
 /**
  * @covers Wikibase\Lib\TimeDetailsFormatter
+ * @uses DataValues\TimeValue
  *
  * @group ValueFormatters
  * @group WikibaseLib
@@ -23,15 +24,30 @@
 class TimeDetailsFormatterTest extends \PHPUnit_Framework_TestCase {
 
        /**
+        * @return TimeDetailsFormatter
+        */
+       private function getFormatter() {
+               $options = new FormatterOptions();
+               $options->setOption( ValueFormatter::OPT_LANG, 'qqx' );
+
+               $timeFormatter = $this->getMockBuilder( 
'ValueFormatters\ValueFormatter' )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $timeFormatter->expects( $this->any() )
+                       ->method( 'format' )
+                       ->will( $this->returnValue( '<a>HTML</a>' ) );
+
+               return new TimeDetailsFormatter( $options, $timeFormatter );
+       }
+
+       /**
         * @dataProvider quantityFormatProvider
         * @param TimeValue $value
         * @param string $pattern
         */
        public function testFormat( TimeValue $value, $pattern ) {
-               $options = new FormatterOptions( array(
-                       ValueFormatter::OPT_LANG => 'qqx',
-               ) );
-               $formatter = new TimeDetailsFormatter( $options );
+               $formatter = $this->getFormatter();
 
                $html = $formatter->format( $value );
                $this->assertRegExp( $pattern, $html );
@@ -46,7 +62,7 @@
                                new TimeValue( '+2001-01-01T00:00:00Z', 60, 0, 
1, TimeValue::PRECISION_MONTH, $gregorian ),
                                '@' . implode( '.*',
                                        array(
-                                               
'<h4[^<>]*>[^<>]*2001[^<>]*</h4>',
+                                               '<h4[^<>]*><a>HTML</a></h4>',
                                                
'<td[^<>]*>\+0*2001-01-01T00:00:00</td>',
                                                '<td[^<>]*>\+01:00</td>',
                                                
'<td[^<>]*>\(valueview-expert-timevalue-calendar-gregorian\)</td>',
@@ -104,7 +120,7 @@
        }
 
        public function testFormatError() {
-               $formatter = new TimeDetailsFormatter( new FormatterOptions() );
+               $formatter = $this->getFormatter();
                $value = new NumberValue( 23 );
 
                $this->setExpectedException( 'InvalidArgumentException' );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I578e4ad33a32a68a5d35fe3a48259c5cd861755d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

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

Reply via email to