jenkins-bot has submitted this change and it was merged.
Change subject: Move parser output post-processing from View to Repo
......................................................................
Move parser output post-processing from View to Repo
Bug: T134170
Bug: T134171
Change-Id: Ia2e42846738b22d0d604cd524b2384c8407ac85d
---
M repo/WikibaseRepo.entitytypes.php
M repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php
M repo/includes/ParserOutput/DispatchingEntityViewFactory.php
M repo/includes/ParserOutput/EntityParserOutputGenerator.php
R repo/includes/ParserOutput/EntityViewPlaceholderExpander.php
A repo/includes/ParserOutput/PlaceholderEmittingEntityTermsView.php
R repo/includes/ParserOutput/TextInjector.php
M repo/tests/phpunit/includes/EntityTypesTest.php
M repo/tests/phpunit/includes/ParserOutput/DispatchingEntityViewFactoryTest.php
M repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorTest.php
R repo/tests/phpunit/includes/ParserOutput/EntityViewPlaceholderExpanderTest.php
A
repo/tests/phpunit/includes/ParserOutput/PlaceholderEmittingEntityTermsViewTest.php
R repo/tests/phpunit/includes/ParserOutput/TextInjectorTest.php
M view/src/EntityTermsView.php
M view/src/EntityView.php
A view/src/SimpleEntityTermsView.php
M view/src/ViewFactory.php
M view/tests/phpunit/ItemViewTest.php
M view/tests/phpunit/PropertyViewTest.php
R view/tests/phpunit/SimpleEntityTermsViewTest.php
M view/tests/phpunit/ViewFactoryTest.php
21 files changed, 488 insertions(+), 282 deletions(-)
Approvals:
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/repo/WikibaseRepo.entitytypes.php
b/repo/WikibaseRepo.entitytypes.php
index af53142..1fbe0d2 100644
--- a/repo/WikibaseRepo.entitytypes.php
+++ b/repo/WikibaseRepo.entitytypes.php
@@ -22,6 +22,7 @@
use Wikibase\LanguageFallbackChain;
use Wikibase\Repo\WikibaseRepo;
use Wikibase\View\EditSectionGenerator;
+use Wikibase\View\EntityTermsView;
return array(
'item' => array(
@@ -29,14 +30,16 @@
$languageCode,
LabelDescriptionLookup $labelDescriptionLookup,
LanguageFallbackChain $fallbackChain,
- EditSectionGenerator $editSectionGenerator
+ EditSectionGenerator $editSectionGenerator,
+ EntityTermsView $entityTermsView
) {
$viewFactory =
WikibaseRepo::getDefaultInstance()->getViewFactory();
return $viewFactory->newItemView(
$languageCode,
$labelDescriptionLookup,
$fallbackChain,
- $editSectionGenerator
+ $editSectionGenerator,
+ $entityTermsView
);
},
'content-model-id' => CONTENT_MODEL_WIKIBASE_ITEM,
@@ -53,14 +56,16 @@
$languageCode,
LabelDescriptionLookup $labelDescriptionLookup,
LanguageFallbackChain $fallbackChain,
- EditSectionGenerator $editSectionGenerator
+ EditSectionGenerator $editSectionGenerator,
+ EntityTermsView $entityTermsView
) {
$viewFactory =
WikibaseRepo::getDefaultInstance()->getViewFactory();
return $viewFactory->newPropertyView(
$languageCode,
$labelDescriptionLookup,
$fallbackChain,
- $editSectionGenerator
+ $editSectionGenerator,
+ $entityTermsView
);
},
'content-model-id' => CONTENT_MODEL_WIKIBASE_PROPERTY,
diff --git a/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php
b/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php
index fc1376a..2ca9873 100644
--- a/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php
+++ b/repo/includes/Hooks/OutputPageBeforeHTMLHookHandler.php
@@ -16,10 +16,10 @@
use Wikibase\Repo\BabelUserLanguageLookup;
use Wikibase\Repo\MediaWikiLanguageDirectionalityLookup;
use Wikibase\Repo\MediaWikiLocalizedTextProvider;
+use Wikibase\Repo\ParserOutput\EntityViewPlaceholderExpander;
+use Wikibase\Repo\ParserOutput\TextInjector;
use Wikibase\Repo\WikibaseRepo;
-use Wikibase\View\EntityViewPlaceholderExpander;
use Wikibase\View\Template\TemplateFactory;
-use Wikibase\View\TextInjector;
/**
* Handler for the "OutputPageBeforeHTML" hook.
diff --git a/repo/includes/ParserOutput/DispatchingEntityViewFactory.php
b/repo/includes/ParserOutput/DispatchingEntityViewFactory.php
index 8b654dc..2c40517 100644
--- a/repo/includes/ParserOutput/DispatchingEntityViewFactory.php
+++ b/repo/includes/ParserOutput/DispatchingEntityViewFactory.php
@@ -7,6 +7,7 @@
use Wikibase\LanguageFallbackChain;
use Wikibase\View\EditSectionGenerator;
use Wikibase\View\EntityView;
+use Wikibase\View\EntityTermsView;
use Wikimedia\Assert\Assert;
/**
@@ -41,6 +42,7 @@
* @param LabelDescriptionLookup $labelDescriptionLookup
* @param LanguageFallbackChain $languageFallbackChain
* @param EditSectionGenerator $editSectionGenerator
+ * @param EntityTermsView $entityTermsView
*
* @throws OutOfBoundsException
* @return EntityView
@@ -50,7 +52,8 @@
$languageCode,
LabelDescriptionLookup $labelDescriptionLookup,
LanguageFallbackChain $languageFallbackChain,
- EditSectionGenerator $editSectionGenerator
+ EditSectionGenerator $editSectionGenerator,
+ EntityTermsView $entityTermsView
) {
if ( !isset( $this->entityViewFactoryCallbacks[$entityType] ) )
{
throw new OutOfBoundsException( "No EntityView is
registered for entity type '$entityType'" );
@@ -61,7 +64,8 @@
$languageCode,
$labelDescriptionLookup,
$languageFallbackChain,
- $editSectionGenerator
+ $editSectionGenerator,
+ $entityTermsView
);
Assert::postcondition(
diff --git a/repo/includes/ParserOutput/EntityParserOutputGenerator.php
b/repo/includes/ParserOutput/EntityParserOutputGenerator.php
index 88d46aa..b5321bc 100644
--- a/repo/includes/ParserOutput/EntityParserOutputGenerator.php
+++ b/repo/includes/ParserOutput/EntityParserOutputGenerator.php
@@ -279,12 +279,29 @@
$this->textProvider
) : new EmptyEditSectionGenerator();
+ $termsListView = new TermsListView(
+ TemplateFactory::getDefaultInstance(),
+ new LanguageNameLookup( $this->languageCode ),
+ new MediaWikiLocalizedTextProvider( $this->languageCode
),
+ new MediaWikiLanguageDirectionalityLookup()
+ );
+
+ $textInjector = new TextInjector();
+ $entityTermsView = new PlaceholderEmittingEntityTermsView(
+ $this->templateFactory,
+ $editSectionGenerator,
+ $this->textProvider,
+ $termsListView,
+ $textInjector
+ );
+
$entityView = $this->entityViewFactory->newEntityView(
$entity->getType(),
$this->languageCode,
$labelDescriptionLookup,
$this->languageFallbackChain,
- $editSectionGenerator
+ $editSectionGenerator,
+ $entityTermsView
);
// Set the display title to display the label together with the
item's id
@@ -293,18 +310,15 @@
$html = $entityView->getHtml( $entity );
$parserOutput->setText( $html );
- $parserOutput->setExtensionData( 'wikibase-view-chunks',
$entityView->getPlaceholders() );
+ $parserOutput->setExtensionData( 'wikibase-view-chunks',
$textInjector->getMarkers() );
- $parserOutput->setExtensionData( 'wikibase-terms-list-items',
$this->getTermsListItems( $entity ) );
+ $parserOutput->setExtensionData(
+ 'wikibase-terms-list-items',
+ $this->getTermsListItems( $entity, $termsListView )
+ );
}
- private function getTermsListItems( EntityDocument $entity ) {
- $termsListView = new TermsListView(
- TemplateFactory::getDefaultInstance(),
- new LanguageNameLookup( $this->languageCode ),
- new MediaWikiLocalizedTextProvider( $this->languageCode
),
- new MediaWikiLanguageDirectionalityLookup()
- );
+ private function getTermsListItems( EntityDocument $entity,
TermsListView $termsListView ) {
$allLanguages = [];
if ( $entity instanceof AliasesProvider ) {
$aliasLanguages = array_keys(
$entity->getAliasGroups()->toTextArray() );
diff --git a/view/src/EntityViewPlaceholderExpander.php
b/repo/includes/ParserOutput/EntityViewPlaceholderExpander.php
similarity index 95%
rename from view/src/EntityViewPlaceholderExpander.php
rename to repo/includes/ParserOutput/EntityViewPlaceholderExpander.php
index 25a1cd0..dc20e3a 100644
--- a/view/src/EntityViewPlaceholderExpander.php
+++ b/repo/includes/ParserOutput/EntityViewPlaceholderExpander.php
@@ -1,6 +1,6 @@
<?php
-namespace Wikibase\View;
+namespace Wikibase\Repo\ParserOutput;
use InvalidArgumentException;
use MWException;
@@ -10,18 +10,16 @@
use Wikibase\DataModel\Term\DescriptionsProvider;
use Wikibase\DataModel\Term\LabelsProvider;
use Wikibase\Lib\LanguageNameLookup;
+use Wikibase\View\LanguageDirectionalityLookup;
+use Wikibase\View\LocalizedTextProvider;
+use Wikibase\View\TermsListView;
use Wikibase\View\Template\TemplateFactory;
/**
- * Utility for expanding the placeholders left in the HTML by EntityView.
+ * Utility for expanding placeholders left in the HTML
*
* This is used to inject any non-cacheable information into the HTML
* that was cached as part of the ParserOutput.
- *
- * @note This class encapsulated knowledge about which placeholders are used by
- * EntityView, and with what meaning.
- *
- * @see EntityView
*
* @since 0.5
*
diff --git a/repo/includes/ParserOutput/PlaceholderEmittingEntityTermsView.php
b/repo/includes/ParserOutput/PlaceholderEmittingEntityTermsView.php
new file mode 100644
index 0000000..dffafed
--- /dev/null
+++ b/repo/includes/ParserOutput/PlaceholderEmittingEntityTermsView.php
@@ -0,0 +1,83 @@
+<?php
+
+namespace Wikibase\Repo\ParserOutput;
+
+use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Term\AliasGroupList;
+use Wikibase\DataModel\Term\AliasesProvider;
+use Wikibase\DataModel\Term\DescriptionsProvider;
+use Wikibase\DataModel\Term\LabelsProvider;
+use Wikibase\DataModel\Term\TermList;
+use Wikibase\View\EditSectionGenerator;
+use Wikibase\View\LocalizedTextProvider;
+use Wikibase\View\SimpleEntityTermsView;
+use Wikibase\View\TermsListView;
+use Wikibase\View\Template\TemplateFactory;
+
+/**
+ * An EntityTermsView that returns placeholders for some parts of the HTML
+ *
+ * @since 0.5
+ *
+ * @license GPL-2.0+
+ * @author Adrian Heine <[email protected]>
+ */
+class PlaceholderEmittingEntityTermsView extends SimpleEntityTermsView {
+
+ /**
+ * @var TemplateFactory
+ */
+ private $templateFactory;
+
+ /**
+ * @var TextInjector
+ */
+ private $textInjector;
+
+ /**
+ * @param TemplateFactory $templateFactory
+ * @param EditSectionGenerator $sectionEditLinkGenerator
+ * @param LocalizedTextProvider $textProvider
+ */
+ public function __construct(
+ TemplateFactory $templateFactory,
+ EditSectionGenerator $sectionEditLinkGenerator,
+ LocalizedTextProvider $textProvider,
+ TermsListView $termsListView,
+ TextInjector $textInjector
+ ) {
+ parent::__construct( $templateFactory,
$sectionEditLinkGenerator, $termsListView, $textProvider );
+ $this->templateFactory = $templateFactory;
+ $this->textInjector = $textInjector;
+ }
+
+ /**
+ * @param string $mainLanguageCode Desired language of the label,
description and aliases in the
+ * title and header section. Not necessarily identical to the
interface language.
+ * @param LabelsProvider $labelsProvider
+ * @param DescriptionsProvider $descriptionsProvider
+ * @param AliasesProvider|null $aliasesProvider
+ * @param EntityId|null $entityId the id of the entity
+ *
+ * @return string HTML
+ */
+ public function getHtml(
+ $mainLanguageCode,
+ LabelsProvider $labelsProvider,
+ DescriptionsProvider $descriptionsProvider,
+ AliasesProvider $aliasesProvider = null,
+ EntityId $entityId = null
+ ) {
+ $cssClasses = $this->textInjector->newMarker(
+
'entityViewPlaceholder-entitytermsview-entitytermsforlanguagelistview-class'
+ );
+
+ return $this->templateFactory->render(
'wikibase-entitytermsview',
+ $this->getHeadingHtml( $mainLanguageCode,
$descriptionsProvider, $aliasesProvider ),
+ $this->textInjector->newMarker( 'termbox' ),
+ $cssClasses,
+ $this->getHtmlForLabelDescriptionAliasesEditSection(
$mainLanguageCode, $entityId )
+ );
+ }
+
+}
diff --git a/view/src/TextInjector.php
b/repo/includes/ParserOutput/TextInjector.php
similarity index 97%
rename from view/src/TextInjector.php
rename to repo/includes/ParserOutput/TextInjector.php
index 800719b..f85ea5e 100644
--- a/view/src/TextInjector.php
+++ b/repo/includes/ParserOutput/TextInjector.php
@@ -1,6 +1,6 @@
<?php
-namespace Wikibase\View;
+namespace Wikibase\Repo\ParserOutput;
/**
* Helper for injecting text by substituting placeholders.
diff --git a/repo/tests/phpunit/includes/EntityTypesTest.php
b/repo/tests/phpunit/includes/EntityTypesTest.php
index f9e4741..855f1f1 100644
--- a/repo/tests/phpunit/includes/EntityTypesTest.php
+++ b/repo/tests/phpunit/includes/EntityTypesTest.php
@@ -7,6 +7,7 @@
use Wikibase\LanguageFallbackChain;
use Wikibase\Repo\Content\EntityHandler;
use Wikibase\View\EditSectionGenerator;
+use Wikibase\View\EntityTermsView;
use Wikibase\View\EntityView;
/**
@@ -50,12 +51,15 @@
$this->assertInternalType( 'callable', $callback );
+ $entityTermsView = $this->getMock( EntityTermsView::class );
+
$entityView = call_user_func(
$callback,
'en',
$this->getMock( LabelDescriptionLookup::class ),
- new LanguageFallbackChain( array() ),
- $this->getMock( EditSectionGenerator::class )
+ new LanguageFallbackChain( [] ),
+ $this->getMock( EditSectionGenerator::class ),
+ $entityTermsView
);
$this->assertInstanceOf( EntityView::class, $entityView );
diff --git
a/repo/tests/phpunit/includes/ParserOutput/DispatchingEntityViewFactoryTest.php
b/repo/tests/phpunit/includes/ParserOutput/DispatchingEntityViewFactoryTest.php
index 4916e55..cd81a3f 100644
---
a/repo/tests/phpunit/includes/ParserOutput/DispatchingEntityViewFactoryTest.php
+++
b/repo/tests/phpunit/includes/ParserOutput/DispatchingEntityViewFactoryTest.php
@@ -10,6 +10,7 @@
use Wikibase\LanguageFallbackChain;
use Wikibase\Repo\ParserOutput\DispatchingEntityViewFactory;
use Wikibase\View\EditSectionGenerator;
+use Wikibase\View\EntityTermsView;
use Wikibase\View\EntityView;
/**
@@ -36,13 +37,15 @@
$factory = new DispatchingEntityViewFactory(
array()
);
+ $entityTermsView = $this->getMock( EntityTermsView::class );
$factory->newEntityView(
'unknown',
'en',
$this->getMock( LabelDescriptionLookup::class ),
new LanguageFallbackChain( array() ),
- $this->getMock( EditSectionGenerator::class )
+ $this->getMock( EditSectionGenerator::class ),
+ $entityTermsView
);
}
@@ -57,13 +60,15 @@
}
)
);
+ $entityTermsView = $this->getMock( EntityTermsView::class );
$factory->newEntityView(
'foo',
'en',
$this->getMock( LabelDescriptionLookup::class ),
new LanguageFallbackChain( array() ),
- $this->getMock( EditSectionGenerator::class )
+ $this->getMock( EditSectionGenerator::class ),
+ $entityTermsView
);
}
@@ -71,6 +76,7 @@
$labelDescriptionLookup = $this->getMock(
LabelDescriptionLookup::class );
$languageFallbackChain = new LanguageFallbackChain( array() );
$editSectionGenerator = $this->getMock(
EditSectionGenerator::class );
+ $entityTermsView = $this->getMock( EntityTermsView::class );
$entityView = $this->getMockBuilder( EntityView::class )
->disableOriginalConstructor()
->getMockForAbstractClass();
@@ -81,12 +87,20 @@
$languageCodeParam,
LabelDescriptionLookup
$labelDescriptionLookupParam,
LanguageFallbackChain
$languageFallbackChainParam,
- EditSectionGenerator
$editSectionGeneratorParam
- ) use ( $labelDescriptionLookup,
$languageFallbackChain, $editSectionGenerator, $entityView ) {
+ EditSectionGenerator
$editSectionGeneratorParam,
+ EntityTermsView $entityTermsViewParam
+ ) use(
+ $labelDescriptionLookup,
+ $languageFallbackChain,
+ $editSectionGenerator,
+ $entityTermsView,
+ $entityView
+ ) {
$this->assertEquals( 'en',
$languageCodeParam );
$this->assertSame(
$labelDescriptionLookup, $labelDescriptionLookupParam );
$this->assertSame(
$languageFallbackChain, $languageFallbackChainParam );
$this->assertSame(
$editSectionGenerator, $editSectionGeneratorParam );
+ $this->assertSame( $entityTermsView,
$entityTermsViewParam );
return $entityView;
}
@@ -98,7 +112,8 @@
'en',
$labelDescriptionLookup,
$languageFallbackChain,
- $editSectionGenerator
+ $editSectionGenerator,
+ $entityTermsView
);
$this->assertSame( $entityView, $newEntityView );
diff --git
a/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorTest.php
b/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorTest.php
index bdcb692..3c871ad 100644
---
a/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorTest.php
+++
b/repo/tests/phpunit/includes/ParserOutput/EntityParserOutputGeneratorTest.php
@@ -50,11 +50,7 @@
$this->assertSame( '<TITLE>', $parserOutput->getTitleText(),
'title text' );
$this->assertSame( '<HTML>', $parserOutput->getText(), 'html
text' );
- $this->assertSame(
- '<PLACEHOLDERS>',
- $parserOutput->getExtensionData( 'wikibase-view-chunks'
),
- 'view chunks'
- );
+ $this->assertSame( [], $parserOutput->getExtensionData(
'wikibase-view-chunks' ), 'view chunks' );
$this->assertArrayHasKey(
'en',
@@ -251,7 +247,6 @@
->setMethods( array(
'getTitleHtml',
'getHtml',
- 'getPlaceholders',
) )
->disableOriginalConstructor()
->getMockForAbstractClass();
@@ -263,10 +258,6 @@
$entityView->expects( $this->any() )
->method( 'getHtml' )
->will( $this->returnValue( '<HTML>' ) );
-
- $entityView->expects( $this->any() )
- ->method( 'getPlaceholders' )
- ->will( $this->returnValue( '<PLACEHOLDERS>' ) );
return $entityView;
}
diff --git a/view/tests/phpunit/EntityViewPlaceholderExpanderTest.php
b/repo/tests/phpunit/includes/ParserOutput/EntityViewPlaceholderExpanderTest.php
similarity index 94%
rename from view/tests/phpunit/EntityViewPlaceholderExpanderTest.php
rename to
repo/tests/phpunit/includes/ParserOutput/EntityViewPlaceholderExpanderTest.php
index 129b91b..0bf2fd7 100644
--- a/view/tests/phpunit/EntityViewPlaceholderExpanderTest.php
+++
b/repo/tests/phpunit/includes/ParserOutput/EntityViewPlaceholderExpanderTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Wikibase\View\Tests;
+namespace Wikibase\Repo\Tests\ParserOutput;
use PHPUnit_Framework_TestCase;
use User;
@@ -8,13 +8,13 @@
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Term\AliasesProvider;
use Wikibase\Lib\LanguageNameLookup;
-use Wikibase\View\EntityViewPlaceholderExpander;
+use Wikibase\Repo\ParserOutput\EntityViewPlaceholderExpander;
use Wikibase\View\DummyLocalizedTextProvider;
use Wikibase\View\LanguageDirectionalityLookup;
use Wikibase\View\Template\TemplateFactory;
/**
- * @covers Wikibase\View\EntityViewPlaceholderExpander
+ * @covers Wikibase\Repo\ParserOutput\EntityViewPlaceholderExpander
*
* @uses Wikibase\View\TermsListView
* @uses Wikibase\View\Template\Template
@@ -22,7 +22,6 @@
* @uses Wikibase\View\Template\TemplateRegistry
*
* @group Wikibase
- * @group WikibaseView
*
* @license GPL-2.0+
* @author Daniel Kinzler
diff --git
a/repo/tests/phpunit/includes/ParserOutput/PlaceholderEmittingEntityTermsViewTest.php
b/repo/tests/phpunit/includes/ParserOutput/PlaceholderEmittingEntityTermsViewTest.php
new file mode 100644
index 0000000..921d192
--- /dev/null
+++
b/repo/tests/phpunit/includes/ParserOutput/PlaceholderEmittingEntityTermsViewTest.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Wikibase\Repo\Tests\ParserOutput;
+
+use PHPUnit_Framework_TestCase;
+use Wikibase\DataModel\Entity\Property;
+use Wikibase\Repo\ParserOutput\PlaceholderEmittingEntityTermsView;
+use Wikibase\Repo\ParserOutput\TextInjector;
+use Wikibase\View\EditSectionGenerator;
+use Wikibase\View\LocalizedTextProvider;
+use Wikibase\View\Template\TemplateFactory;
+use Wikibase\View\TermsListView;
+
+/**
+ * @covers Wikibase\Repo\ParserOutput\PlaceholderEmittingEntityTermsView
+ *
+ * @license GNU GPL v2+
+ * @author Adrian Heine <[email protected]>
+ */
+class PlaceholderEmittingEntityTermsViewTest extends
PHPUnit_Framework_TestCase {
+
+ private function newEntityTermsView( TextInjector $textInjector ) {
+ $termsListView = $this->getMockBuilder( TermsListView::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ return new PlaceholderEmittingEntityTermsView(
+ TemplateFactory::getDefaultInstance(),
+ $this->getMock( EditSectionGenerator::class ),
+ $this->getMock( LocalizedTextProvider::class ),
+ $termsListView,
+ $textInjector
+ );
+ }
+
+ public function testGetHtml() {
+ $textInjector = new TextInjector();
+ $property = new Property( null, null, 'string' );
+
+ $entityTermsView = $this->newEntityTermsView( $textInjector );
+
+ $result = $entityTermsView->getHtml(
+ 'lkt',
+ $property,
+ $property,
+ $property
+ );
+
+ $this->assertEquals(
+ array_values( $textInjector->getMarkers() ),
+ [ [
'entityViewPlaceholder-entitytermsview-entitytermsforlanguagelistview-class' ],
[ 'termbox' ] ]
+ );
+ }
+
+}
diff --git a/view/tests/phpunit/TextInjectorTest.php
b/repo/tests/phpunit/includes/ParserOutput/TextInjectorTest.php
similarity index 87%
rename from view/tests/phpunit/TextInjectorTest.php
rename to repo/tests/phpunit/includes/ParserOutput/TextInjectorTest.php
index 4d1ac49..06ba794 100644
--- a/view/tests/phpunit/TextInjectorTest.php
+++ b/repo/tests/phpunit/includes/ParserOutput/TextInjectorTest.php
@@ -1,14 +1,14 @@
<?php
-namespace Wikibase\View\Tests;
+namespace Wikibase\Repo\ParserOutput\Tests;
-use Wikibase\View\TextInjector;
+use Wikibase\Repo\ParserOutput\TextInjector;
/**
- * @covers Wikibase\View\TextInjector
+ * @covers Wikibase\Repo\ParserOutput\TextInjector
*
* @group Wikibase
- * @group WikibaseView
+ * @group WikibaseRepo
*
* @license GPL-2.0+
* @author Daniel Kinzler
diff --git a/view/src/EntityTermsView.php b/view/src/EntityTermsView.php
index 07e012a..f93a6bf 100644
--- a/view/src/EntityTermsView.php
+++ b/view/src/EntityTermsView.php
@@ -3,12 +3,9 @@
namespace Wikibase\View;
use Wikibase\DataModel\Entity\EntityId;
-use Wikibase\DataModel\Term\AliasGroupList;
use Wikibase\DataModel\Term\AliasesProvider;
use Wikibase\DataModel\Term\DescriptionsProvider;
use Wikibase\DataModel\Term\LabelsProvider;
-use Wikibase\DataModel\Term\TermList;
-use Wikibase\View\Template\TemplateFactory;
/**
* Generates HTML to display the terms of an entity.
@@ -16,42 +13,9 @@
* @since 0.5
*
* @license GPL-2.0+
- * @author Thiemo Mättig
- * @author Bene* < [email protected] >
- * @author H. Snater < [email protected] >
* @author Adrian Heine <[email protected]>
*/
-class EntityTermsView {
-
- /**
- * @var TemplateFactory
- */
- private $templateFactory;
-
- /**
- * @var EditSectionGenerator
- */
- private $sectionEditLinkGenerator;
-
- /**
- * @var LocalizedTextProvider
- */
- private $textProvider;
-
- /**
- * @param TemplateFactory $templateFactory
- * @param EditSectionGenerator $sectionEditLinkGenerator
- * @param LocalizedTextProvider $textProvider
- */
- public function __construct(
- TemplateFactory $templateFactory,
- EditSectionGenerator $sectionEditLinkGenerator,
- LocalizedTextProvider $textProvider
- ) {
- $this->sectionEditLinkGenerator = $sectionEditLinkGenerator;
- $this->templateFactory = $templateFactory;
- $this->textProvider = $textProvider;
- }
+interface EntityTermsView {
/**
* @param string $mainLanguageCode Desired language of the label,
description and aliases in the
@@ -60,8 +24,6 @@
* @param DescriptionsProvider $descriptionsProvider
* @param AliasesProvider|null $aliasesProvider
* @param EntityId|null $entityId the id of the entity
- * @param string $termBoxHtml
- * @param TextInjector $textInjector
*
* @return string HTML
*/
@@ -70,51 +32,8 @@
LabelsProvider $labelsProvider,
DescriptionsProvider $descriptionsProvider,
AliasesProvider $aliasesProvider = null,
- EntityId $entityId = null,
- $termBoxHtml,
- TextInjector $textInjector
- ) {
- $marker = $textInjector->newMarker(
-
'entityViewPlaceholder-entitytermsview-entitytermsforlanguagelistview-class'
- );
-
- return $this->templateFactory->render(
'wikibase-entitytermsview',
- $this->getHeadingHtml( $mainLanguageCode,
$descriptionsProvider, $aliasesProvider ),
- $termBoxHtml,
- $marker,
- $this->getHtmlForLabelDescriptionAliasesEditSection(
$mainLanguageCode, $entityId )
- );
- }
-
- private function getHeadingHtml(
- $languageCode,
- DescriptionsProvider $descriptionsProvider,
- AliasesProvider $aliasesProvider = null
- ) {
- $headingPartsHtml = '';
-
- $descriptions = $descriptionsProvider->getDescriptions();
- $headingPartsHtml .= $this->templateFactory->render(
- 'wikibase-entitytermsview-heading-part',
- 'description',
- $descriptions->hasTermForLanguage( $languageCode ) ? ''
: 'wb-empty',
- $this->getDescriptionHtml( $languageCode, $descriptions
)
- );
-
- if ( $aliasesProvider !== null ) {
- $aliasGroups = $aliasesProvider->getAliasGroups();
- $headingPartsHtml .= $this->templateFactory->render(
- 'wikibase-entitytermsview-heading-part',
- 'aliases',
- $aliasGroups->hasGroupForLanguage(
$languageCode ) ? '' : 'wb-empty',
- $this->getHtmlForAliases( $languageCode,
$aliasGroups )
- );
- }
-
- return $this->templateFactory->render(
'wikibase-entitytermsview-heading',
- $headingPartsHtml
- );
- }
+ EntityId $entityId = null
+ );
/**
* @param string $mainLanguageCode Desired language of the label,
description and aliases in the
@@ -128,79 +47,6 @@
$mainLanguageCode,
LabelsProvider $labelsProvider,
EntityId $entityId = null
- ) {
- $labels = $labelsProvider->getLabels();
- $idInParenthesesHtml = '';
-
- if ( $entityId !== null ) {
- $id = $entityId->getSerialization();
- $idInParenthesesHtml = htmlspecialchars(
$this->textProvider->get( 'parentheses', [ $id ] ) );
- }
-
- if ( $labels->hasTermForLanguage( $mainLanguageCode ) ) {
- return $this->templateFactory->render( 'wikibase-title',
- '',
- htmlspecialchars( $labels->getByLanguage(
$mainLanguageCode )->getText() ),
- $idInParenthesesHtml
- );
- } else {
- return $this->templateFactory->render( 'wikibase-title',
- 'wb-empty',
- htmlspecialchars( $this->textProvider->get(
'wikibase-label-empty' ) ),
- $idInParenthesesHtml
- );
- }
- }
-
- /**
- * @param string $languageCode The language of the description
- * @param TermList $descriptions The list of descriptions to render
- *
- * @return string HTML
- */
- private function getDescriptionHtml( $languageCode, TermList
$descriptions ) {
- if ( $descriptions->hasTermForLanguage( $languageCode ) ) {
- $text = $descriptions->getByLanguage( $languageCode
)->getText();
- } else {
- $text = $this->textProvider->get(
'wikibase-description-empty' );
- }
- return htmlspecialchars( $text );
- }
-
- /**
- * @param string $languageCode The language of the aliases
- * @param AliasGroupList $aliasGroups the list of alias groups to render
- *
- * @return string HTML
- */
- private function getHtmlForAliases( $languageCode, AliasGroupList
$aliasGroups ) {
- if ( !$aliasGroups->hasGroupForLanguage( $languageCode ) ) {
- return '';
- }
-
- $aliasesHtml = '';
- $aliases = $aliasGroups->getByLanguage( $languageCode
)->getAliases();
- foreach ( $aliases as $alias ) {
- $aliasesHtml .= $this->templateFactory->render(
- 'wikibase-entitytermsview-aliases-alias',
- htmlspecialchars( $alias )
- );
- }
- $aliasesHtml = $this->templateFactory->render(
'wikibase-entitytermsview-aliases', $aliasesHtml );
- return $aliasesHtml;
- }
-
- /**
- * @param string $languageCode The language for which terms should be
edited
- * @param EntityId|null $entityId
- *
- * @return string HTML
- */
- private function getHtmlForLabelDescriptionAliasesEditSection(
$languageCode, EntityId $entityId = null ) {
- return
$this->sectionEditLinkGenerator->getLabelDescriptionAliasesEditSection(
- $languageCode,
- $entityId
- );
- }
+ );
}
diff --git a/view/src/EntityView.php b/view/src/EntityView.php
index 812cdc5..f93f86f 100644
--- a/view/src/EntityView.php
+++ b/view/src/EntityView.php
@@ -44,11 +44,6 @@
protected $languageCode;
/**
- * @var TextInjector
- */
- private $textInjector;
-
- /**
* @param TemplateFactory $templateFactory
* @param EntityTermsView $entityTermsView
* @param LanguageDirectionalityLookup $languageDirectionalityLookup
@@ -64,27 +59,11 @@
$this->languageDirectionalityLookup =
$languageDirectionalityLookup;
$this->languageCode = $languageCode;
- $this->textInjector = new TextInjector();
$this->templateFactory = $templateFactory;
}
/**
- * Returns the placeholder map build while generating HTML.
- * The map returned here may be used with TextInjector.
- *
- * @return array[] string -> array
- */
- public function getPlaceholders() {
- return $this->textInjector->getMarkers();
- }
-
- /**
* Builds and returns the HTML representing a whole WikibaseEntity.
- *
- * @note: The HTML returned by this method may contain placeholders.
Such placeholders can be
- * expanded with the help of TextInjector::inject() calling back to
- * EntityViewPlaceholderExpander::getHtmlForPlaceholder()
- * @note: In order to keep the list of placeholders small, this calls
resetPlaceholders().
*
* @since 0.1
*
@@ -163,22 +142,11 @@
$entity,
$entity,
$entity instanceof AliasesProvider ? $entity :
null,
- $id,
- $this->getHtmlForTermBox(),
- $this->textInjector
+ $id
);
}
return '';
- }
-
- /**
- * @return string HTML
- */
- private function getHtmlForTermBox() {
- // Placeholder for a termbox for the present item.
- // EntityViewPlaceholderExpander must know about the parameters
used here.
- return $this->textInjector->newMarker( 'termbox' );
}
}
diff --git a/view/src/SimpleEntityTermsView.php
b/view/src/SimpleEntityTermsView.php
new file mode 100644
index 0000000..08d432b
--- /dev/null
+++ b/view/src/SimpleEntityTermsView.php
@@ -0,0 +1,211 @@
+<?php
+
+namespace Wikibase\View;
+
+use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Term\AliasGroupList;
+use Wikibase\DataModel\Term\AliasesProvider;
+use Wikibase\DataModel\Term\DescriptionsProvider;
+use Wikibase\DataModel\Term\LabelsProvider;
+use Wikibase\DataModel\Term\TermList;
+use Wikibase\View\Template\TemplateFactory;
+
+/**
+ * Generates HTML to display the terms of an entity.
+ *
+ * @since 0.5
+ *
+ * @license GPL-2.0+
+ * @author Thiemo Mättig
+ * @author Bene* < [email protected] >
+ * @author H. Snater < [email protected] >
+ * @author Adrian Heine <[email protected]>
+ */
+class SimpleEntityTermsView implements EntityTermsView {
+
+ /**
+ * @var TemplateFactory
+ */
+ private $templateFactory;
+
+ /**
+ * @var EditSectionGenerator
+ */
+ private $sectionEditLinkGenerator;
+
+ /**
+ * @var TermsListView
+ */
+ private $termsListView;
+
+ /**
+ * @var LocalizedTextProvider
+ */
+ private $textProvider;
+
+ /**
+ * @param TemplateFactory $templateFactory
+ * @param EditSectionGenerator $sectionEditLinkGenerator
+ * @param TermsListView $termsListView
+ * @param LocalizedTextProvider $textProvider
+ */
+ public function __construct(
+ TemplateFactory $templateFactory,
+ EditSectionGenerator $sectionEditLinkGenerator,
+ TermsListView $termsListView,
+ LocalizedTextProvider $textProvider
+ ) {
+ $this->sectionEditLinkGenerator = $sectionEditLinkGenerator;
+ $this->templateFactory = $templateFactory;
+ $this->termsListView = $termsListView;
+ $this->textProvider = $textProvider;
+ }
+
+ /**
+ * @param string $mainLanguageCode Desired language of the label,
description and aliases in the
+ * title and header section. Not necessarily identical to the
interface language.
+ * @param LabelsProvider $labelsProvider
+ * @param DescriptionsProvider $descriptionsProvider
+ * @param AliasesProvider|null $aliasesProvider
+ * @param EntityId|null $entityId the id of the entity
+ *
+ * @return string HTML
+ */
+ public function getHtml(
+ $mainLanguageCode,
+ LabelsProvider $labelsProvider,
+ DescriptionsProvider $descriptionsProvider,
+ AliasesProvider $aliasesProvider = null,
+ EntityId $entityId = null
+ ) {
+ return $this->templateFactory->render(
'wikibase-entitytermsview',
+ $this->getHeadingHtml( $mainLanguageCode,
$descriptionsProvider, $aliasesProvider ),
+ $this->termsListView->getHtml(
+ $labelsProvider,
+ $descriptionsProvider,
+ $aliasesProvider,
+ [ $mainLanguageCode ]
+ ),
+ '',
+ $this->getHtmlForLabelDescriptionAliasesEditSection(
$mainLanguageCode, $entityId )
+ );
+ }
+
+ protected function getHeadingHtml(
+ $languageCode,
+ DescriptionsProvider $descriptionsProvider,
+ AliasesProvider $aliasesProvider = null
+ ) {
+ $headingPartsHtml = '';
+
+ $descriptions = $descriptionsProvider->getDescriptions();
+ $headingPartsHtml .= $this->templateFactory->render(
+ 'wikibase-entitytermsview-heading-part',
+ 'description',
+ $descriptions->hasTermForLanguage( $languageCode ) ? ''
: 'wb-empty',
+ $this->getDescriptionHtml( $languageCode, $descriptions
)
+ );
+
+ if ( $aliasesProvider !== null ) {
+ $aliasGroups = $aliasesProvider->getAliasGroups();
+ $headingPartsHtml .= $this->templateFactory->render(
+ 'wikibase-entitytermsview-heading-part',
+ 'aliases',
+ $aliasGroups->hasGroupForLanguage(
$languageCode ) ? '' : 'wb-empty',
+ $this->getHtmlForAliases( $languageCode,
$aliasGroups )
+ );
+ }
+
+ return $this->templateFactory->render(
'wikibase-entitytermsview-heading',
+ $headingPartsHtml
+ );
+ }
+
+ /**
+ * @param string $mainLanguageCode Desired language of the label,
description and aliases in the
+ * title and header section. Not necessarily identical to the
interface language.
+ * @param LabelsProvider $labelsProvider
+ * @param EntityId|null $entityId
+ *
+ * @return string HTML
+ */
+ public function getTitleHtml(
+ $mainLanguageCode,
+ LabelsProvider $labelsProvider,
+ EntityId $entityId = null
+ ) {
+ $labels = $labelsProvider->getLabels();
+ $idInParenthesesHtml = '';
+
+ if ( $entityId !== null ) {
+ $id = $entityId->getSerialization();
+ $idInParenthesesHtml = htmlspecialchars(
$this->textProvider->get( 'parentheses', [ $id ] ) );
+ }
+
+ if ( $labels->hasTermForLanguage( $mainLanguageCode ) ) {
+ return $this->templateFactory->render( 'wikibase-title',
+ '',
+ htmlspecialchars( $labels->getByLanguage(
$mainLanguageCode )->getText() ),
+ $idInParenthesesHtml
+ );
+ } else {
+ return $this->templateFactory->render( 'wikibase-title',
+ 'wb-empty',
+ htmlspecialchars( $this->textProvider->get(
'wikibase-label-empty' ) ),
+ $idInParenthesesHtml
+ );
+ }
+ }
+
+ /**
+ * @param string $languageCode The language of the description
+ * @param TermList $descriptions The list of descriptions to render
+ *
+ * @return string HTML
+ */
+ private function getDescriptionHtml( $languageCode, TermList
$descriptions ) {
+ if ( $descriptions->hasTermForLanguage( $languageCode ) ) {
+ $text = $descriptions->getByLanguage( $languageCode
)->getText();
+ } else {
+ $text = $this->textProvider->get(
'wikibase-description-empty' );
+ }
+ return htmlspecialchars( $text );
+ }
+
+ /**
+ * @param string $languageCode The language of the aliases
+ * @param AliasGroupList $aliasGroups the list of alias groups to render
+ *
+ * @return string HTML
+ */
+ private function getHtmlForAliases( $languageCode, AliasGroupList
$aliasGroups ) {
+ if ( !$aliasGroups->hasGroupForLanguage( $languageCode ) ) {
+ return '';
+ }
+
+ $aliasesHtml = '';
+ $aliases = $aliasGroups->getByLanguage( $languageCode
)->getAliases();
+ foreach ( $aliases as $alias ) {
+ $aliasesHtml .= $this->templateFactory->render(
+ 'wikibase-entitytermsview-aliases-alias',
+ htmlspecialchars( $alias )
+ );
+ }
+ $aliasesHtml = $this->templateFactory->render(
'wikibase-entitytermsview-aliases', $aliasesHtml );
+ return $aliasesHtml;
+ }
+
+ /**
+ * @param string $languageCode The language for which terms should be
edited
+ * @param EntityId|null $entityId
+ *
+ * @return string HTML
+ */
+ protected function getHtmlForLabelDescriptionAliasesEditSection(
$languageCode, EntityId $entityId = null ) {
+ return
$this->sectionEditLinkGenerator->getLabelDescriptionAliasesEditSection(
+ $languageCode,
+ $entityId
+ );
+ }
+
+}
diff --git a/view/src/ViewFactory.php b/view/src/ViewFactory.php
index e6940e1..b384581 100644
--- a/view/src/ViewFactory.php
+++ b/view/src/ViewFactory.php
@@ -179,6 +179,7 @@
* @param LabelDescriptionLookup $labelDescriptionLookup
* @param LanguageFallbackChain $fallbackChain
* @param EditSectionGenerator $editSectionGenerator
+ * @param EntityTermsView $entityTermsView
*
* @return ItemView
*/
@@ -186,10 +187,9 @@
$languageCode,
LabelDescriptionLookup $labelDescriptionLookup,
LanguageFallbackChain $fallbackChain,
- EditSectionGenerator $editSectionGenerator
+ EditSectionGenerator $editSectionGenerator,
+ EntityTermsView $entityTermsView
) {
- $entityTermsView = $this->newEntityTermsView(
$editSectionGenerator );
-
$statementSectionsView = $this->newStatementSectionsView(
$languageCode,
$labelDescriptionLookup,
@@ -228,6 +228,7 @@
* @param LabelDescriptionLookup $labelDescriptionLookup
* @param LanguageFallbackChain $fallbackChain
* @param EditSectionGenerator $editSectionGenerator
+ * @param EntityTermsView $entityTermsView
*
* @return PropertyView
*/
@@ -235,10 +236,9 @@
$languageCode,
LabelDescriptionLookup $labelDescriptionLookup,
LanguageFallbackChain $fallbackChain,
- EditSectionGenerator $editSectionGenerator
+ EditSectionGenerator $editSectionGenerator,
+ EntityTermsView $entityTermsView
) {
- $entityTermsView = $this->newEntityTermsView(
$editSectionGenerator );
-
$statementSectionsView = $this->newStatementSectionsView(
$languageCode,
$labelDescriptionLookup,
@@ -312,9 +312,15 @@
* @return EntityTermsView
*/
public function newEntityTermsView( EditSectionGenerator
$editSectionGenerator ) {
- return new EntityTermsView(
+ return new SimpleEntityTermsView(
$this->templateFactory,
$editSectionGenerator,
+ new TermsListView(
+ $this->templateFactory,
+ $this->languageNameLookup,
+ $this->textProvider,
+ $this->languageDirectionalityLookup
+ ),
$this->textProvider
);
}
diff --git a/view/tests/phpunit/ItemViewTest.php
b/view/tests/phpunit/ItemViewTest.php
index 54bff61..e5dcb6e 100644
--- a/view/tests/phpunit/ItemViewTest.php
+++ b/view/tests/phpunit/ItemViewTest.php
@@ -22,7 +22,6 @@
* @uses Wikibase\View\Template\Template
* @uses Wikibase\View\Template\TemplateFactory
* @uses Wikibase\View\Template\TemplateRegistry
- * @uses Wikibase\View\TextInjector
*
* @group Wikibase
* @group WikibaseView
@@ -64,9 +63,7 @@
$templateFactory = TemplateFactory::getDefaultInstance();
$itemView = new ItemView(
$templateFactory,
- $this->getMockBuilder( EntityTermsView::class )
- ->disableOriginalConstructor()
- ->getMock(),
+ $this->getMock( EntityTermsView::class ),
$this->getMock( LanguageDirectionalityLookup::class ),
$this->getMockBuilder( StatementSectionsView::class )
->disableOriginalConstructor()
diff --git a/view/tests/phpunit/PropertyViewTest.php
b/view/tests/phpunit/PropertyViewTest.php
index 537253f..162a1c4 100644
--- a/view/tests/phpunit/PropertyViewTest.php
+++ b/view/tests/phpunit/PropertyViewTest.php
@@ -23,7 +23,6 @@
* @uses Wikibase\View\Template\Template
* @uses Wikibase\View\Template\TemplateFactory
* @uses Wikibase\View\Template\TemplateRegistry
- * @uses Wikibase\View\TextInjector
*
* @group Wikibase
* @group WikibaseView
@@ -78,9 +77,7 @@
$templateFactory = TemplateFactory::getDefaultInstance();
$propertyView = new PropertyView(
$templateFactory,
- $this->getMockBuilder( EntityTermsView::class )
- ->disableOriginalConstructor()
- ->getMock(),
+ $this->getMock( EntityTermsView::class ),
$this->getMock( LanguageDirectionalityLookup::class ),
$this->getMockBuilder( StatementSectionsView::class )
->disableOriginalConstructor()
diff --git a/view/tests/phpunit/EntityTermsViewTest.php
b/view/tests/phpunit/SimpleEntityTermsViewTest.php
similarity index 86%
rename from view/tests/phpunit/EntityTermsViewTest.php
rename to view/tests/phpunit/SimpleEntityTermsViewTest.php
index eb6b986..42d6dd1 100644
--- a/view/tests/phpunit/EntityTermsViewTest.php
+++ b/view/tests/phpunit/SimpleEntityTermsViewTest.php
@@ -5,19 +5,20 @@
use PHPUnit_Framework_TestCase;
use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Term\Fingerprint;
+use Wikibase\Lib\LanguageNameLookup;
use Wikibase\View\EditSectionGenerator;
-use Wikibase\View\EntityTermsView;
use Wikibase\View\DummyLocalizedTextProvider;
+use Wikibase\View\SimpleEntityTermsView;
use Wikibase\View\Template\TemplateFactory;
-use Wikibase\View\TextInjector;
+use Wikibase\View\TermsListView;
/**
- * @covers Wikibase\View\EntityTermsView
+ * @covers Wikibase\View\SimpleEntityTermsView
*
* @uses Wikibase\View\Template\Template
* @uses Wikibase\View\Template\TemplateFactory
* @uses Wikibase\View\Template\TemplateRegistry
- * @uses Wikibase\View\TextInjector
+ * @uses Wikibase\View\TermsListView
*
* @group Wikibase
* @group WikibaseView
@@ -26,7 +27,7 @@
* @author Bene* < [email protected] >
* @author Thiemo Mättig
*/
-class EntityTermsViewTest extends PHPUnit_Framework_TestCase {
+class SimpleEntityTermsViewTest extends PHPUnit_Framework_TestCase {
private function getEntityTermsView( $editSectionCalls = 0 ) {
$editSectionGenerator = $this->getMock(
EditSectionGenerator::class );
@@ -34,10 +35,17 @@
->method( 'getLabelDescriptionAliasesEditSection' )
->will( $this->returnValue( '<EDITSECTION>' ) );
- return new EntityTermsView(
+ $textProvider = new DummyLocalizedTextProvider( 'lkt' );
+
+ $termsListView = $this->getMockBuilder( TermsListView::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ return new SimpleEntityTermsView(
TemplateFactory::getDefaultInstance(),
$editSectionGenerator,
- new DummyLocalizedTextProvider()
+ $termsListView,
+ $textProvider
);
}
@@ -52,7 +60,7 @@
public function testGetHtml_containsDescriptionAndAliases() {
$entityTermsView = $this->getEntityTermsView( 1 );
$fingerprint = $this->getFingerprint();
- $html = $entityTermsView->getHtml( 'en', $fingerprint,
$fingerprint, $fingerprint, null, '', new TextInjector() );
+ $html = $entityTermsView->getHtml( 'en', $fingerprint,
$fingerprint, $fingerprint, null, '' );
$this->assertContains( '<DESCRIPTION>', $html );
$this->assertContains( '<ALIAS1>', $html );
@@ -74,7 +82,7 @@
*/
public function testGetHtml_isEditable( Fingerprint $fingerprint,
ItemId $entityId, $languageCode ) {
$entityTermsView = $this->getEntityTermsView( 1 );
- $html = $entityTermsView->getHtml( $languageCode, $fingerprint,
$fingerprint, $fingerprint, $entityId, '', new TextInjector() );
+ $html = $entityTermsView->getHtml( $languageCode, $fingerprint,
$fingerprint, $fingerprint, $entityId, '' );
$this->assertContains( '<EDITSECTION>', $html );
}
@@ -85,7 +93,7 @@
$fingerprint->setAliasGroup( 'en', array( '<a href="#">evil
html</a>', '<b>bold</b>', '<i>italic</i>' ) );
$view = $this->getEntityTermsView( 1 );
- $html = $view->getHtml( 'en', $fingerprint, $fingerprint,
$fingerprint, null, '', new TextInjector() );
+ $html = $view->getHtml( 'en', $fingerprint, $fingerprint,
$fingerprint, null, '' );
$this->assertContains( 'evil html', $html, 'make sure it works'
);
$this->assertNotContains( 'href="#"', $html );
@@ -98,7 +106,7 @@
public function testGetHtml_isMarkedAsEmptyValue() {
$entityTermsView = $this->getEntityTermsView( 1 );
$fingerprint = new Fingerprint();
- $html = $entityTermsView->getHtml( 'en', $fingerprint,
$fingerprint, $fingerprint, null, '', new TextInjector() );
+ $html = $entityTermsView->getHtml( 'en', $fingerprint,
$fingerprint, $fingerprint, null, '' );
$this->assertContains( 'wb-empty', $html );
$this->assertContains( '(wikibase-description-empty)', $html );
@@ -108,7 +116,7 @@
public function testGetHtml_isNotMarkedAsEmpty() {
$entityTermsView = $this->getEntityTermsView( 1 );
$fingerprint = $this->getFingerprint();
- $html = $entityTermsView->getHtml( 'en', $fingerprint,
$fingerprint, $fingerprint, null, '', new TextInjector() );
+ $html = $entityTermsView->getHtml( 'en', $fingerprint,
$fingerprint, $fingerprint, null, '' );
$this->assertNotContains( 'wb-empty', $html );
$this->assertNotContains( '(wikibase-description-empty)', $html
);
@@ -120,7 +128,7 @@
$fingerprint->removeDescription( 'en' );
$view = $this->getEntityTermsView( 1 );
- $html = $view->getHtml( 'en', $fingerprint, $fingerprint,
$fingerprint, null, '', new TextInjector() );
+ $html = $view->getHtml( 'en', $fingerprint, $fingerprint,
$fingerprint, null, '' );
$this->assertContains( 'wb-empty', $html );
$this->assertContains( '(wikibase-description-empty)', $html );
@@ -132,7 +140,7 @@
$fingerprint->removeAliasGroup( 'en' );
$view = $this->getEntityTermsView( 1 );
- $html = $view->getHtml( 'en', $fingerprint, $fingerprint,
$fingerprint, null, '', new TextInjector() );
+ $html = $view->getHtml( 'en', $fingerprint, $fingerprint,
$fingerprint, null, '' );
$this->assertContains( 'wb-empty', $html );
$this->assertNotContains( '(wikibase-description-empty)', $html
);
@@ -140,7 +148,7 @@
}
public function testGetTitleHtml_containsLabel() {
- $entityTermsView = $this->getEntityTermsView();
+ $entityTermsView = $this->getEntityTermsView( 0 );
$fingerprint = $this->getFingerprint();
$html = $entityTermsView->getTitleHtml( 'en', $fingerprint,
null );
@@ -151,7 +159,7 @@
* @dataProvider entityFingerprintProvider
*/
public function testGetTitleHtml_withEntityId( Fingerprint
$fingerprint, ItemId $entityId ) {
- $entityTermsView = $this->getEntityTermsView();
+ $entityTermsView = $this->getEntityTermsView( 0 );
$html = $entityTermsView->getTitleHtml( 'en', $fingerprint,
$entityId );
$idString = $entityId->getSerialization();
@@ -159,14 +167,14 @@
}
public function testGetTitleHtml_withoutEntityId() {
- $entityTermsView = $this->getEntityTermsView();
+ $entityTermsView = $this->getEntityTermsView( 0 );
$html = $entityTermsView->getTitleHtml( 'en', new
Fingerprint(), null );
$this->assertNotContains( '(parentheses', $html );
}
public function testGetTitleHtml_labelIsEscaped() {
- $entityTermsView = $this->getEntityTermsView();
+ $entityTermsView = $this->getEntityTermsView( 0 );
$fingerprint = new Fingerprint();
$fingerprint->setLabel( 'en', '<a href="#">evil html</a>' );
$html = $entityTermsView->getTitleHtml( 'en', $fingerprint,
null );
@@ -180,7 +188,7 @@
$fingerprint = $this->getFingerprint();
$fingerprint->removeLabel( 'en' );
- $entityTermsView = $this->getEntityTermsView();
+ $entityTermsView = $this->getEntityTermsView( 0 );
$html = $entityTermsView->getTitleHtml( 'en', $fingerprint,
null );
$this->assertContains( 'wb-empty', $html );
@@ -190,7 +198,7 @@
public function testGetTitleHtml_isNotMarkedAsEmpty() {
$fingerprint = $this->getFingerprint();
- $entityTermsView = $this->getEntityTermsView();
+ $entityTermsView = $this->getEntityTermsView( 0 );
$html = $entityTermsView->getTitleHtml( 'en', $fingerprint,
null );
$this->assertNotContains( 'wb-empty', $html );
diff --git a/view/tests/phpunit/ViewFactoryTest.php
b/view/tests/phpunit/ViewFactoryTest.php
index 2029e0a..7607bd2 100644
--- a/view/tests/phpunit/ViewFactoryTest.php
+++ b/view/tests/phpunit/ViewFactoryTest.php
@@ -42,7 +42,6 @@
* @uses Wikibase\View\Template\Template
* @uses Wikibase\View\Template\TemplateFactory
* @uses Wikibase\View\Template\TemplateRegistry
- * @uses Wikibase\View\TextInjector
*
* @group Wikibase
* @group WikibaseView
@@ -105,22 +104,28 @@
}
public function testNewItemView() {
- $itemView = $this->newViewFactory()->newItemView(
+ $factory = $this->newViewFactory();
+ $editSectionGenerator = $this->getMock(
EditSectionGenerator::class );
+ $itemView = $factory->newItemView(
'de',
$this->getMock( LabelDescriptionLookup::class ),
new LanguageFallbackChain( array() ),
- $this->getMock( EditSectionGenerator::class )
+ $editSectionGenerator,
+ $factory->newEntityTermsView( $editSectionGenerator )
);
$this->assertInstanceOf( ItemView::class, $itemView );
}
public function testNewPropertyView() {
- $propertyView = $this->newViewFactory()->newPropertyView(
+ $factory = $this->newViewFactory();
+ $editSectionGenerator = $this->getMock(
EditSectionGenerator::class );
+ $propertyView = $factory->newPropertyView(
'de',
$this->getMock( LabelDescriptionLookup::class ),
new LanguageFallbackChain( array() ),
- $this->getMock( EditSectionGenerator::class )
+ $editSectionGenerator,
+ $factory->newEntityTermsView( $editSectionGenerator )
);
$this->assertInstanceOf( PropertyView::class, $propertyView );
--
To view, visit https://gerrit.wikimedia.org/r/286421
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia2e42846738b22d0d604cd524b2384c8407ac85d
Gerrit-PatchSet: 7
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Heine <[email protected]>
Gerrit-Reviewer: Adrian Heine <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[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