Jonas Kress (WMDE) has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/345329 )

Change subject: Add section header for senses.
......................................................................


Add section header for senses.

Mainly copy and paste from the forms counterpart except for the dummy
list of forms.

Bug: T161523
Change-Id: Ie4da7e27d37f56fad4cdd80383e17e6ecc0c5acf
---
M i18n/en.json
M i18n/qqq.json
M src/View/LexemeView.php
M src/View/LexemeViewFactory.php
A src/View/SensesView.php
A tests/browser/features/senses.feature
A tests/browser/features/step_definitions/senses_steps.rb
M tests/browser/features/support/pages/lexeme_page.rb
M tests/phpunit/mediawiki/View/LexemeViewTest.php
A tests/phpunit/mediawiki/View/SensesViewTest.php
10 files changed, 148 insertions(+), 9 deletions(-)

Approvals:
  Jonas Kress (WMDE): Looks good to me, approved
  jenkins-bot: Verified



diff --git a/i18n/en.json b/i18n/en.json
index f7efd91..fecfd10 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -14,5 +14,6 @@
        "wikibase-lexeme-view-lexical-category": "$1",
        "wikibase-lexeme-view-language-lexical-category": "$1 in $2",
        "wikibase-lexeme-view-forms": "Forms",
+       "wikibase-lexeme-view-senses": "Senses",
        "wikibase-lexeme-summary-wbeditentity-update": "Changed a lexeme"
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 97d9735..29d7c15 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -19,5 +19,6 @@
        "wikibase-lexeme-view-lexical-category": "Description when there is the 
lexical category but not language",
        "wikibase-lexeme-view-language-lexical-category": "Description when 
both lexical category and language are present\n{{Identical|In}}",
        "wikibase-lexeme-view-forms": "Subheading for the forms section on a 
lexeme page.\n{{Identical|Form}}",
+       "wikibase-lexeme-view-senses": "Subheading for the senses section on a 
lexeme page.\n{{Identical|Sense}}",
        "wikibase-lexeme-summary-wbeditentity-update": "Auto-generated edit 
summary when editing a lexeme"
 }
diff --git a/src/View/LexemeView.php b/src/View/LexemeView.php
index 4f6c250..7af1a9f 100644
--- a/src/View/LexemeView.php
+++ b/src/View/LexemeView.php
@@ -36,6 +36,11 @@
        private $formsView;
 
        /**
+        * @var SensesView
+        */
+       private $sensesView;
+
+       /**
         * @var StatementSectionsView
         */
        private $statementSectionsView;
@@ -56,6 +61,7 @@
         * @param LanguageDirectionalityLookup $languageDirectionalityLookup
         * @param string $languageCode
         * @param LexemeFormsView $formsView
+        * @param SensesView $sensesView
         * @param StatementSectionsView $statementSectionsView
         * @param HtmlTermRenderer $htmlTermRenderer
         * @param LabelDescriptionLookup $labelDescriptionLookup
@@ -66,6 +72,7 @@
                LanguageDirectionalityLookup $languageDirectionalityLookup,
                $languageCode,
                LexemeFormsView $formsView,
+               SensesView $sensesView,
                StatementSectionsView $statementSectionsView,
                HtmlTermRenderer $htmlTermRenderer,
                LabelDescriptionLookup $labelDescriptionLookup
@@ -78,6 +85,7 @@
                );
 
                $this->formsView = $formsView;
+               $this->sensesView = $sensesView;
                $this->statementSectionsView = $statementSectionsView;
                $this->htmlTermRenderer = $htmlTermRenderer;
                $this->labelDescriptionLookup = $labelDescriptionLookup;
@@ -105,7 +113,8 @@
                $html = $this->getHtmlForLexicalCategoryAndLanguage( $entity )
                        . $this->templateFactory->render( 'wikibase-toc' )
                        . $this->statementSectionsView->getHtml( 
$entity->getStatements() )
-                       . $this->formsView->getHtml( $forms );
+                       . $this->formsView->getHtml( $forms )
+                       . $this->sensesView->getHtml();
 
                return $html;
        }
diff --git a/src/View/LexemeViewFactory.php b/src/View/LexemeViewFactory.php
index ae2ad50..34b05ea 100644
--- a/src/View/LexemeViewFactory.php
+++ b/src/View/LexemeViewFactory.php
@@ -67,10 +67,10 @@
 
        public function newLexemeView() {
                $languageDirectionalityLookup = new 
MediaWikiLanguageDirectionalityLookup();
+               $localizedTextProvider = new MediaWikiLocalizedTextProvider( 
$this->languageCode );
 
-               $formsView = new LexemeFormsView(
-                       new MediaWikiLocalizedTextProvider( $this->languageCode 
)
-               );
+               $formsView = new LexemeFormsView( $localizedTextProvider );
+               $sensesView = new SensesView( $localizedTextProvider );
 
                $wikibaseRepo = WikibaseRepo::getDefaultInstance();
                $statementSectionsView = 
$wikibaseRepo->getViewFactory()->newStatementSectionsView(
@@ -91,6 +91,7 @@
                        $languageDirectionalityLookup,
                        $this->languageCode,
                        $formsView,
+                       $sensesView,
                        $statementSectionsView,
                        $htmlTermRenderer,
                        $this->labelDescriptionLookup
diff --git a/src/View/SensesView.php b/src/View/SensesView.php
new file mode 100644
index 0000000..f0f5d74
--- /dev/null
+++ b/src/View/SensesView.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Wikibase\Lexeme\View;
+
+use Wikibase\View\LocalizedTextProvider;
+
+/**
+ * @license GPL-2.0+
+ */
+class SensesView {
+
+       /**
+        * @var LocalizedTextProvider
+        */
+       private $textProvider;
+
+       public function __construct( LocalizedTextProvider $textProvider ) {
+               $this->textProvider = $textProvider;
+       }
+
+       /**
+        * @return string HTML
+        */
+       public function getHtml() {
+               $html = '<h2 class="wb-section-heading section-heading">'
+                       . '<span class="mw-headline" id="senses">'
+                       . htmlspecialchars( $this->textProvider->get( 
'wikibase-lexeme-view-senses' ) )
+                       . '</span>'
+                       . '</h2>';
+
+               $html .= '<div class="wikibase-lexeme-senses">';
+               $html .= '</div>';
+
+               return $html;
+       }
+
+}
diff --git a/tests/browser/features/senses.feature 
b/tests/browser/features/senses.feature
new file mode 100644
index 0000000..38cca7c
--- /dev/null
+++ b/tests/browser/features/senses.feature
@@ -0,0 +1,12 @@
+@chrome @firefox @internet_explorer_10 @internet_explorer_11 @local_config 
@test.wikidata.org @wikidata.beta.wmflabs.org
+Feature: Senses of a Lexeme
+
+  Background:
+    Given I am on a Lexeme page
+      And The copyright warning has been dismissed
+      And Anonymous edit warnings are disabled
+
+  @integration
+  Scenario: Basic senses section
+    Then Senses header should be there
+     And Senses container should be there
diff --git a/tests/browser/features/step_definitions/senses_steps.rb 
b/tests/browser/features/step_definitions/senses_steps.rb
new file mode 100644
index 0000000..8005c50
--- /dev/null
+++ b/tests/browser/features/step_definitions/senses_steps.rb
@@ -0,0 +1,7 @@
+Then(/^Senses header should be there$/) do
+  expect(on(LexemePage).senses_header?).to be true
+end
+
+Then(/^Senses container should be there$/) do
+  expect(on(LexemePage).senses_container?).to be true
+end
diff --git a/tests/browser/features/support/pages/lexeme_page.rb 
b/tests/browser/features/support/pages/lexeme_page.rb
index 4390c27..41d9439 100644
--- a/tests/browser/features/support/pages/lexeme_page.rb
+++ b/tests/browser/features/support/pages/lexeme_page.rb
@@ -6,6 +6,8 @@
   div(:forms_container, class: 'wikibase-lexeme-forms')
   h3(:form_representation, class: 'wikibase-lexeme-form-representation')
   span(:form_id, class: 'wikibase-lexeme-form-id')
+  span(:senses_header, id: 'senses')
+  div(:senses_container, class: 'wikibase-lexeme-senses')
 
   def create_lexeme(lexeme_data)
     wb_api = MediawikiApi::Wikidata::WikidataClient.new URL.repo_api
diff --git a/tests/phpunit/mediawiki/View/LexemeViewTest.php 
b/tests/phpunit/mediawiki/View/LexemeViewTest.php
index bd0c8d0..aeafdab 100644
--- a/tests/phpunit/mediawiki/View/LexemeViewTest.php
+++ b/tests/phpunit/mediawiki/View/LexemeViewTest.php
@@ -15,6 +15,7 @@
 use Wikibase\Lexeme\DataModel\Lexeme;
 use Wikibase\Lexeme\DataModel\LexemeId;
 use Wikibase\Lexeme\View\LexemeFormsView;
+use Wikibase\Lexeme\View\SensesView;
 use Wikibase\Lexeme\View\LexemeView;
 use Wikibase\Lib\LanguageNameLookup;
 use Wikibase\Repo\ParserOutput\FallbackHintHtmlTermRenderer;
@@ -51,6 +52,20 @@
        }
 
        /**
+        * @return SensesView
+        */
+       private function newSensesViewMock() {
+               $view = $this->getMockBuilder( SensesView::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $view->method( 'getHtml' )
+                       ->will( $this->returnValue( 
"lexemeSensesView->getHtml\n" ) );
+
+               return $view;
+       }
+
+       /**
         * @param StatementList|null $expectedStatements
         *
         * @return StatementSectionsView
@@ -78,7 +93,7 @@
                $labelDescriptionLookup
                        ->method( 'getLabel' )
                        ->will(
-                               $this->returnCallback( function ( ItemId 
$itemId ) {
+                               $this->returnCallback( function( ItemId $itemId 
) {
                                        if ( $itemId->getSerialization() === 
'Q1' ) {
                                                return null;
                                        }
@@ -131,6 +146,7 @@
                        $languageDirectionalityLookup,
                        'en',
                        $this->newFormsViewMock(),
+                       $this->newSensesViewMock(),
                        $this->newStatementSectionsViewMock( 
$expectedStatements ),
                        $htmlTermRenderer,
                        $this->newLabelDescriptionLookup()
@@ -164,6 +180,7 @@
                $this->assertContains( 'id="wb-lexeme-' . ( $lexeme->getId() ?: 
'new' ) . '"', $html );
                $this->assertContains( 'class="wikibase-entityview wb-lexeme"', 
$html );
                $this->assertContains( 'lexemeFormsView->getHtml', $html );
+               $this->assertContains( 'lexemeSensesView->getHtml', $html );
                $this->assertContains( 'statementSectionsView->getHtml', $html 
);
        }
 
@@ -238,10 +255,12 @@
                $this->assertInternalType( 'string', $html );
                $this->assertContains(
                        '<div class="wikibase-entityview-main">'
-                               . $expectedHeadline
-                               . '<div id="toc"></div>'
-                               . 
"statementSectionsView->getHtml\nlexemeFormsView->getHtml\n"
-                               . '</div>',
+                       . $expectedHeadline
+                       . '<div id="toc"></div>'
+                       . "statementSectionsView->getHtml\n"
+                       . "lexemeFormsView->getHtml\n"
+                       . "lexemeSensesView->getHtml\n"
+                       . '</div>',
                        $html
                );
        }
diff --git a/tests/phpunit/mediawiki/View/SensesViewTest.php 
b/tests/phpunit/mediawiki/View/SensesViewTest.php
new file mode 100644
index 0000000..b9523b7
--- /dev/null
+++ b/tests/phpunit/mediawiki/View/SensesViewTest.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Wikibase\Lexeme\Tests\MediaWiki\View;
+
+use PHPUnit_Framework_TestCase;
+use Wikibase\Lexeme\View\SensesView;
+use Wikibase\View\DummyLocalizedTextProvider;
+
+/**
+ * @covers Wikibase\Lexeme\View\LexemeSensesView
+ *
+ * @group WikibaseLexeme
+ *
+ * @license GPL-2.0+
+ */
+class SensesViewTest extends PHPUnit_Framework_TestCase {
+
+       public function testHtmlContainsTheSensesHeadline() {
+               $view = $this->newSensesView();
+               $html = $view->getHtml( [] );
+
+               assertThat(
+                       $html,
+                       is( htmlPiece( havingChild(
+                               both( withTagName( 'h2' ) )
+                                       ->andAlso( havingChild(
+                                               both( withAttribute( 'id' 
)->havingValue( 'senses' ) )
+                                                       ->andAlso( 
havingTextContents( '(wikibase-lexeme-view-senses)' ) )
+                                       ) )
+                       ) ) )
+               );
+       }
+
+       public function testHtmlContainsSensesContainer() {
+               $view = $this->newSensesView();
+               $html = $view->getHtml( [] );
+
+               assertThat(
+                       $html,
+                       is( htmlPiece( havingChild( tagMatchingOutline(
+                               '<div class="wikibase-lexeme-senses">'
+                       ) ) ) )
+               );
+       }
+
+       private function newSensesView() {
+               return new SensesView( new DummyLocalizedTextProvider() );
+       }
+
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie4da7e27d37f56fad4cdd80383e17e6ecc0c5acf
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/WikibaseLexeme
Gerrit-Branch: master
Gerrit-Owner: Jakob <[email protected]>
Gerrit-Reviewer: Aleksey Bekh-Ivanov (WMDE) <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jakob <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: WMDE-leszek <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to