jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/353976 )
Change subject: EntityIdFormatter → ConstraintParameterRenderer
......................................................................
EntityIdFormatter → ConstraintParameterRenderer
All services that need to format entity IDs for their parameters now get
a ConstraintParameterRenderer instead of an EntityIdFormatter. This
removes some code duplication, because ConstraintParameterRenderer
already knows how to format an HTML list, or how to do the
try-parse-catch-htmlentities dance for an entity ID string, so the
corresponding copied code in the individual checkers / helpers can be
removed.
ConstraintReportFactory’s EntityIdFormatter is no longer necessary and
therefore removed.
All test cases are also updated to inject a ConstraintParameterRenderer
into the classes they test instead of just an EntityIdFormatter.
Change-Id: I86adfb5afeef0836fc7b489fc1b5eaa9733acdff
---
M api/CheckConstraints.php
M includes/ConstraintCheck/Checker/ConflictsWithChecker.php
M includes/ConstraintCheck/Checker/InverseChecker.php
M includes/ConstraintCheck/Checker/OneOfChecker.php
M includes/ConstraintCheck/Checker/SymmetricChecker.php
M includes/ConstraintCheck/Helper/TypeCheckerHelper.php
M includes/ConstraintReportFactory.php
M tests/phpunit/Checker/ConnectionChecker/ConflictsWithCheckerTest.php
M tests/phpunit/Checker/ConnectionChecker/InverseCheckerTest.php
M tests/phpunit/Checker/ConnectionChecker/SymmetricCheckerTest.php
M tests/phpunit/Checker/OneOfChecker/OneOfCheckerTest.php
M tests/phpunit/Checker/TypeChecker/TypeCheckerHelperTest.php
M tests/phpunit/Checker/TypeChecker/TypeCheckerTest.php
M tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
M tests/phpunit/DelegatingConstraintCheckerTest.php
15 files changed, 137 insertions(+), 137 deletions(-)
Approvals:
Jonas Kress (WMDE): Looks good to me, approved
jenkins-bot: Verified
diff --git a/api/CheckConstraints.php b/api/CheckConstraints.php
index 85a039d..e18fbb8 100644
--- a/api/CheckConstraints.php
+++ b/api/CheckConstraints.php
@@ -116,7 +116,6 @@
$repo->getEntityLookup(),
$statementGuidParser,
MediaWikiServices::getInstance()->getMainConfig(),
- $entityIdFormatter,
$constraintParameterRenderer
);
diff --git a/includes/ConstraintCheck/Checker/ConflictsWithChecker.php
b/includes/ConstraintCheck/Checker/ConflictsWithChecker.php
index 749a9b5..07e9781 100644
--- a/includes/ConstraintCheck/Checker/ConflictsWithChecker.php
+++ b/includes/ConstraintCheck/Checker/ConflictsWithChecker.php
@@ -5,7 +5,6 @@
use InvalidArgumentException;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\DataModel\Services\EntityId\EntityIdFormatter;
use Wikibase\DataModel\Services\Lookup\EntityLookup;
use Wikibase\DataModel\Statement\StatementListProvider;
use WikibaseQuality\ConstraintReport\Constraint;
@@ -13,6 +12,7 @@
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConnectionCheckerHelper;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
use Wikibase\DataModel\Statement\Statement;
/**
@@ -38,26 +38,26 @@
private $connectionCheckerHelper;
/**
- * @var EntityIdFormatter
+ * @var ConstraintParameterRenderer
*/
- private $entityIdFormatter;
+ private $constraintParameterRenderer;
/**
* @param EntityLookup $lookup
* @param ConstraintParameterParser $helper
* @param ConnectionCheckerHelper $connectionCheckerHelper
- * @param EntityIdFormatter $entityIdFormatter
+ * @param ConstraintParameterRenderer $constraintParameterRenderer
*/
public function __construct(
EntityLookup $lookup,
ConstraintParameterParser $helper,
ConnectionCheckerHelper $connectionCheckerHelper,
- EntityIdFormatter $entityIdFormatter
+ ConstraintParameterRenderer $constraintParameterRenderer
) {
$this->entityLookup = $lookup;
$this->constraintParameterParser = $helper;
$this->connectionCheckerHelper = $connectionCheckerHelper;
- $this->entityIdFormatter = $entityIdFormatter;
+ $this->constraintParameterRenderer =
$constraintParameterRenderer;
}
/**
@@ -87,12 +87,6 @@
$parameters['item'] =
$this->constraintParameterParser->parseParameterArray( explode( ',',
$constraintParameters[ 'item' ] ) );
};
- try {
- $conflictingProperty =
$this->entityIdFormatter->formatEntityId( new PropertyId(
$constraintParameters['property'] ) );
- } catch ( InvalidArgumentException $e ) {
- $conflictingProperty = htmlspecialchars(
$constraintParameters['property'] );
- }
-
/*
* 'Conflicts with' can be defined with
* a) a property only
@@ -102,8 +96,8 @@
if ( $this->connectionCheckerHelper->hasProperty(
$entity->getStatements(), $constraintParameters['property'] ) ) {
$message = wfMessage(
"wbqc-violation-message-conflicts-with-property" )
->rawParams(
-
$this->entityIdFormatter->formatEntityId( $statement->getPropertyId() ),
- $conflictingProperty
+
$this->constraintParameterRenderer->formatEntityId( $statement->getPropertyId()
),
+
$this->constraintParameterRenderer->formatPropertyId(
$constraintParameters['property'] )
)
->escaped();
$status = CheckResult::STATUS_VIOLATION;
@@ -116,9 +110,9 @@
if ( $result !== null ) {
$message = wfMessage(
"wbqc-violation-message-conflicts-with-claim" )
->rawParams(
-
$this->entityIdFormatter->formatEntityId( $statement->getPropertyId() ),
- $conflictingProperty,
-
$this->entityIdFormatter->formatEntityId( $result )
+
$this->constraintParameterRenderer->formatEntityId( $statement->getPropertyId()
),
+
$this->constraintParameterRenderer->formatPropertyId(
$constraintParameters['property'] ),
+
$this->constraintParameterRenderer->formatEntityId( $result )
)
->escaped();
$status = CheckResult::STATUS_VIOLATION;
diff --git a/includes/ConstraintCheck/Checker/InverseChecker.php
b/includes/ConstraintCheck/Checker/InverseChecker.php
index 7b32c05..cc7a67c 100644
--- a/includes/ConstraintCheck/Checker/InverseChecker.php
+++ b/includes/ConstraintCheck/Checker/InverseChecker.php
@@ -2,11 +2,8 @@
namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker;
-use InvalidArgumentException;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Entity\EntityIdValue;
-use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\DataModel\Services\EntityId\EntityIdFormatter;
use Wikibase\DataModel\Services\Lookup\EntityLookup;
use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Statement\StatementListProvider;
@@ -15,6 +12,7 @@
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConnectionCheckerHelper;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
use Wikibase\DataModel\Statement\Statement;
/**
@@ -40,26 +38,26 @@
private $connectionCheckerHelper;
/**
- * @var EntityIdFormatter
+ * @var ConstraintParameterRenderer
*/
- private $entityIdFormatter;
+ private $constraintParameterRenderer;
/**
* @param EntityLookup $lookup
* @param ConstraintParameterParser $helper
* @param ConnectionCheckerHelper $connectionCheckerHelper
- * @param EntityIdFormatter $entityIdFormatter should return HTML
+ * @param ConstraintParameterRenderer $constraintParameterRenderer
*/
public function __construct(
EntityLookup $lookup,
ConstraintParameterParser $helper,
ConnectionCheckerHelper $connectionCheckerHelper,
- EntityIdFormatter $entityIdFormatter
+ ConstraintParameterRenderer $constraintParameterRenderer
) {
$this->entityLookup = $lookup;
$this->constraintParameterParser = $helper;
$this->connectionCheckerHelper = $connectionCheckerHelper;
- $this->entityIdFormatter = $entityIdFormatter;
+ $this->constraintParameterRenderer =
$constraintParameterRenderer;
}
/**
@@ -124,16 +122,11 @@
$message = '';
$status = CheckResult::STATUS_COMPLIANCE;
} else {
- try {
- $inverseProperty =
$this->entityIdFormatter->formatEntityId( new PropertyId( $property ) );
- } catch ( InvalidArgumentException $e ) {
- $inverseProperty = htmlspecialchars( $property
);
- }
$message = wfMessage( 'wbqc-violation-message-inverse' )
->rawParams(
-
$this->entityIdFormatter->formatEntityId( $targetItem->getId() ),
- $inverseProperty,
-
$this->entityIdFormatter->formatEntityId( $entity->getId() )
+
$this->constraintParameterRenderer->formatEntityId( $targetItem->getId() ),
+
$this->constraintParameterRenderer->formatPropertyId( $property ),
+
$this->constraintParameterRenderer->formatEntityId( $entity->getId() )
)
->escaped();
$status = CheckResult::STATUS_VIOLATION;
diff --git a/includes/ConstraintCheck/Checker/OneOfChecker.php
b/includes/ConstraintCheck/Checker/OneOfChecker.php
index 3773057..8c36ebf 100644
--- a/includes/ConstraintCheck/Checker/OneOfChecker.php
+++ b/includes/ConstraintCheck/Checker/OneOfChecker.php
@@ -2,17 +2,15 @@
namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Checker;
-use InvalidArgumentException;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Entity\EntityIdValue;
-use Wikibase\DataModel\Entity\ItemId;
-use Wikibase\DataModel\Services\EntityId\EntityIdFormatter;
use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Statement\StatementListProvider;
use WikibaseQuality\ConstraintReport\Constraint;
use WikibaseQuality\ConstraintReport\ConstraintCheck\ConstraintChecker;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
use Wikibase\DataModel\Statement\Statement;
/**
@@ -28,32 +26,20 @@
private $helper;
/**
- * @var EntityIdFormatter
+ * @var ConstraintParameterRenderer
*/
- private $entityIdFormatter;
+ private $constraintParameterRenderer;
/**
* @param ConstraintParameterParser $helper
- * @param EntityIdFormatter $entityIdFormatter should return HTML
+ * @param ConstraintParameterRenderer $constraintParameterRenderer
*/
public function __construct(
ConstraintParameterParser $helper,
- EntityIdFormatter $entityIdFormatter
+ ConstraintParameterRenderer $constraintParameterRenderer
) {
$this->helper = $helper;
- $this->entityIdFormatter = $entityIdFormatter;
- }
-
- /**
- * @var string $item
- * @return string HTML
- */
- private function formatValue( $item ) {
- try {
- return $this->entityIdFormatter->formatEntityId( new
ItemId( $item ) );
- } catch ( InvalidArgumentException $e ) {
- return htmlspecialchars( $item );
- }
+ $this->constraintParameterRenderer =
$constraintParameterRenderer;
}
/**
@@ -114,21 +100,9 @@
$status = CheckResult::STATUS_COMPLIANCE;
} else {
$message = wfMessage( "wbqc-violation-message-one-of" );
- $message->rawParams(
- $this->entityIdFormatter->formatEntityId(
$statement->getPropertyId() )
- );
+ $message->rawParams(
$this->constraintParameterRenderer->formatEntityId( $statement->getPropertyId()
) );
$message->numParams( count( $items ) );
- $message->rawParams(
- '<ul>'
- . implode( array_map(
- function ( $item ) {
- return '<li>' .
$this->formatValue( $item ) . '</li>';
- },
- $items
- ) )
- . '</ul>'
- );
- $message->rawParams( array_map( [ $this, 'formatValue'
], $items ) );
+ $message->rawParams(
$this->constraintParameterRenderer->formatItemIdList( $items ) );
$message = $message->escaped();
$status = CheckResult::STATUS_VIOLATION;
}
diff --git a/includes/ConstraintCheck/Checker/SymmetricChecker.php
b/includes/ConstraintCheck/Checker/SymmetricChecker.php
index ebbd984..111ee59 100644
--- a/includes/ConstraintCheck/Checker/SymmetricChecker.php
+++ b/includes/ConstraintCheck/Checker/SymmetricChecker.php
@@ -4,7 +4,6 @@
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Entity\EntityIdValue;
-use Wikibase\DataModel\Services\EntityId\EntityIdFormatter;
use Wikibase\DataModel\Services\Lookup\EntityLookup;
use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Statement\StatementListProvider;
@@ -13,6 +12,7 @@
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConnectionCheckerHelper;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Result\CheckResult;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
use Wikibase\DataModel\Statement\Statement;
/**
@@ -38,26 +38,26 @@
private $connectionCheckerHelper;
/**
- * @var EntityIdFormatter
+ * @var ConstraintParameterRenderer
*/
- private $entityIdFormatter;
+ private $constraintParameterRenderer;
/**
* @param EntityLookup $lookup
* @param ConstraintParameterParser $helper
* @param ConnectionCheckerHelper $connectionCheckerHelper
- * @param EntityIdFormatter $entityIdFormatter should return HTML
+ * @param ConstraintParameterRenderer $constraintParameterRenderer
*/
public function __construct(
EntityLookup $lookup,
ConstraintParameterParser $helper,
ConnectionCheckerHelper $connectionCheckerHelper,
- EntityIdFormatter $entityIdFormatter
+ ConstraintParameterRenderer $constraintParameterRenderer
) {
$this->entityLookup = $lookup;
$this->constraintParameterParser = $helper;
$this->connectionCheckerHelper = $connectionCheckerHelper;
- $this->entityIdFormatter = $entityIdFormatter;
+ $this->constraintParameterRenderer =
$constraintParameterRenderer;
}
/**
@@ -114,9 +114,9 @@
} else {
$message = wfMessage(
'wbqc-violation-message-symmetric' )
->rawParams(
-
$this->entityIdFormatter->formatEntityId( $targetItem->getId() ),
-
$this->entityIdFormatter->formatEntityId( $propertyId ),
-
$this->entityIdFormatter->formatEntityId( $entity->getId() )
+
$this->constraintParameterRenderer->formatEntityId( $targetItem->getId() ),
+
$this->constraintParameterRenderer->formatEntityId( $propertyId ),
+
$this->constraintParameterRenderer->formatEntityId( $entity->getId() )
)
->escaped();
$status = CheckResult::STATUS_VIOLATION;
diff --git a/includes/ConstraintCheck/Helper/TypeCheckerHelper.php
b/includes/ConstraintCheck/Helper/TypeCheckerHelper.php
index 6caab30..3e101a0 100644
--- a/includes/ConstraintCheck/Helper/TypeCheckerHelper.php
+++ b/includes/ConstraintCheck/Helper/TypeCheckerHelper.php
@@ -3,18 +3,16 @@
namespace WikibaseQuality\ConstraintReport\ConstraintCheck\Helper;
use Config;
-use InvalidArgumentException;
use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\EntityIdValue;
-use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\DataModel\Services\EntityId\EntityIdFormatter;
use Wikibase\DataModel\Services\Lookup\EntityLookup;
use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Snak\Snak;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Statement\StatementList;
use Wikibase\DataModel\Statement\StatementListProvider;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
/**
* Class for helper functions for range checkers.
@@ -38,23 +36,23 @@
private $config;
/**
- * @var EntityIdFormatter
+ * @var ConstraintParameterRenderer
*/
- private $entityIdFormatter;
+ private $constraintParameterRenderer;
/**
* @param EntityLookup $lookup
* @param Config $config
- * @param EntityIdFormatter $entityIdFormatter should return HTML
+ * @param ConstraintParameterRenderer $constraintParameterRenderer
*/
public function __construct(
EntityLookup $lookup,
Config $config,
- EntityIdFormatter $entityIdFormatter
+ ConstraintParameterRenderer $constraintParameterRenderer
) {
$this->entityLookup = $lookup;
$this->config = $config;
- $this->entityIdFormatter = $entityIdFormatter;
+ $this->constraintParameterRenderer =
$constraintParameterRenderer;
}
/**
@@ -149,18 +147,6 @@
}
/**
- * @param string $class item ID serialization (any other string is
HTML-escaped and returned without formatting)
- * @return string HTML
- */
- private function formatClass( $classId ) {
- try {
- return $this->entityIdFormatter->formatEntityId( new
ItemId( $classId ) );
- } catch ( InvalidArgumentException $e ) {
- return htmlspecialchars( $classId );
- }
- }
-
- /**
* @param PropertyId $propertyId ID of the property that introduced the
constraint
* @param EntityId $entityId ID of the entity that does not have the
required type
* @param string[] $classes item ID serializations of the classes that
$entityId should have
@@ -178,21 +164,11 @@
$message = wfMessage( 'wbqc-violation-message-' . $checker .
'-' . $relation );
$message->rawParams(
- $this->entityIdFormatter->formatEntityId( $propertyId ),
- $this->entityIdFormatter->formatEntityId( $entityId )
+ $this->constraintParameterRenderer->formatPropertyId(
$propertyId ),
+ $this->constraintParameterRenderer->formatEntityId(
$entityId )
);
$message->numParams( count( $classes ) );
- $message->rawParams(
- '<ul>'
- . implode( array_map(
- function ( $class ) {
- return '<li>' . $this->formatClass(
$class ) . '</li>';
- },
- $classes
- ) )
- . '</ul>'
- );
- $message->rawParams( array_map( [ $this, "formatClass" ],
$classes ) );
+ $message->rawParams(
$this->constraintParameterRenderer->formatItemIdList( $classes ) );
return $message->escaped();
}
diff --git a/includes/ConstraintReportFactory.php
b/includes/ConstraintReportFactory.php
index 74e168e..04be725 100644
--- a/includes/ConstraintReportFactory.php
+++ b/includes/ConstraintReportFactory.php
@@ -5,7 +5,6 @@
use Config;
use MediaWiki\MediaWikiServices;
use ValueFormatters\FormatterOptions;
-use Wikibase\DataModel\Services\EntityId\EntityIdFormatter;
use Wikibase\DataModel\Services\Lookup\EntityLookup;
use Wikibase\Lib\SnakFormatter;
use Wikibase\Repo\WikibaseRepo;
@@ -73,11 +72,6 @@
private $config;
/**
- * @var EntityIdFormatter
- */
- private $entityIdFormatter;
-
- /**
* @var ConstraintParameterRenderer
*/
private $constraintParameterRenderer;
@@ -102,7 +96,6 @@
$wikibaseRepo->getEntityLookup(),
$wikibaseRepo->getStatementGuidParser(),
MediaWikiServices::getInstance()->getMainConfig(),
- $entityIdFormatter,
new ConstraintParameterRenderer(
$entityIdFormatter,
$wikibaseRepo->getValueFormatterFactory()->getValueFormatter(
@@ -120,13 +113,11 @@
EntityLookup $lookup,
StatementGuidParser $statementGuidParser,
Config $config,
- EntityIdFormatter $entityIdFormatter,
ConstraintParameterRenderer $constraintParameterRenderer
) {
$this->lookup = $lookup;
$this->statementGuidParser = $statementGuidParser;
$this->config = $config;
- $this->entityIdFormatter = $entityIdFormatter;
$this->constraintParameterRenderer =
$constraintParameterRenderer;
}
@@ -153,14 +144,14 @@
$constraintParameterParser = new
ConstraintParameterParser();
$connectionCheckerHelper = new
ConnectionCheckerHelper();
$rangeCheckerHelper = new RangeCheckerHelper();
- $typeCheckerHelper = new TypeCheckerHelper(
$this->lookup, $this->config, $this->entityIdFormatter );
+ $typeCheckerHelper = new TypeCheckerHelper(
$this->lookup, $this->config, $this->constraintParameterRenderer );
$this->constraintCheckerMap = [
- 'Conflicts with' => new ConflictsWithChecker(
$this->lookup, $constraintParameterParser, $connectionCheckerHelper,
$this->entityIdFormatter ),
+ 'Conflicts with' => new ConflictsWithChecker(
$this->lookup, $constraintParameterParser, $connectionCheckerHelper,
$this->constraintParameterRenderer ),
'Item' => new ItemChecker( $this->lookup,
$constraintParameterParser, $connectionCheckerHelper ),
'Target required claim' => new
TargetRequiredClaimChecker( $this->lookup, $constraintParameterParser,
$connectionCheckerHelper ),
- 'Symmetric' => new SymmetricChecker(
$this->lookup, $constraintParameterParser, $connectionCheckerHelper,
$this->entityIdFormatter ),
- 'Inverse' => new InverseChecker( $this->lookup,
$constraintParameterParser, $connectionCheckerHelper, $this->entityIdFormatter
),
+ 'Symmetric' => new SymmetricChecker(
$this->lookup, $constraintParameterParser, $connectionCheckerHelper,
$this->constraintParameterRenderer ),
+ 'Inverse' => new InverseChecker( $this->lookup,
$constraintParameterParser, $connectionCheckerHelper,
$this->constraintParameterRenderer ),
'Qualifier' => new QualifierChecker(
$constraintParameterParser ),
'Qualifiers' => new QualifiersChecker(
$constraintParameterParser ),
'Mandatory qualifiers' => new
MandatoryQualifiersChecker( $constraintParameterParser ),
@@ -173,7 +164,7 @@
'Unique value' => new UniqueValueChecker(),
'Format' => new FormatChecker(
$constraintParameterParser ),
'Commons link' => new CommonsLinkChecker(
$constraintParameterParser ),
- 'One of' => new OneOfChecker(
$constraintParameterParser, $this->entityIdFormatter ),
+ 'One of' => new OneOfChecker(
$constraintParameterParser, $this->constraintParameterRenderer ),
];
}
diff --git
a/tests/phpunit/Checker/ConnectionChecker/ConflictsWithCheckerTest.php
b/tests/phpunit/Checker/ConnectionChecker/ConflictsWithCheckerTest.php
index ad02eed..5f4cac5 100644
--- a/tests/phpunit/Checker/ConnectionChecker/ConflictsWithCheckerTest.php
+++ b/tests/phpunit/Checker/ConnectionChecker/ConflictsWithCheckerTest.php
@@ -2,6 +2,7 @@
namespace WikibaseQuality\ConstraintReport\Test\ConnectionChecker;
+use ValueFormatters\ValueFormatter;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Snak\PropertyValueSnak;
use Wikibase\DataModel\Entity\EntityIdValue;
@@ -12,6 +13,7 @@
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ConflictsWithChecker;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConnectionCheckerHelper;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
use WikibaseQuality\Tests\Helper\JsonFileEntityLookup;
/**
@@ -43,6 +45,11 @@
private $connectionCheckerHelper;
/**
+ * @var ConstraintParameterRenderer
+ */
+ private $constraintParameterRenderer;
+
+ /**
* @var ConflictsWithChecker
*/
private $checker;
@@ -52,13 +59,25 @@
$this->lookup = new JsonFileEntityLookup( __DIR__ );
$this->helper = new ConstraintParameterParser();
$this->connectionCheckerHelper = new ConnectionCheckerHelper();
- $this->checker = new ConflictsWithChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper, new PlainEntityIdFormatter() );
+ $valueFormatter = $this->getMock( ValueFormatter::class );
+ $valueFormatter->method( 'format' )->willReturn( '' );
+ $this->constraintParameterRenderer = new
ConstraintParameterRenderer(
+ new PlainEntityIdFormatter(),
+ $valueFormatter
+ );
+ $this->checker = new ConflictsWithChecker(
+ $this->lookup,
+ $this->helper,
+ $this->connectionCheckerHelper,
+ $this->constraintParameterRenderer
+ );
}
protected function tearDown() {
unset( $this->lookup );
unset( $this->helper );
unset( $this->connectionCheckerHelper );
+ unset( $this->constraintParameterRenderer );
unset( $this->checker );
parent::tearDown();
}
@@ -79,7 +98,7 @@
public function testConflictsWithConstraintProperty() {
$entity = $this->lookup->getEntity( new ItemId( 'Q5' ) );
- $this->checker = new ConflictsWithChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper, new PlainEntityIdFormatter() );
+ $this->checker = new ConflictsWithChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper,
$this->constraintParameterRenderer );
$value = new EntityIdValue( new ItemId( 'Q100' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P188' ), $value ) );
@@ -94,7 +113,7 @@
public function testConflictsWithConstraintPropertyButNotItem() {
$entity = $this->lookup->getEntity( new ItemId( 'Q5' ) );
- $this->checker = new ConflictsWithChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper, new PlainEntityIdFormatter() );
+ $this->checker = new ConflictsWithChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper,
$this->constraintParameterRenderer );
$value = new EntityIdValue( new ItemId( 'Q100' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P188' ), $value ) );
@@ -110,7 +129,7 @@
public function testConflictsWithConstraintPropertyAndItem() {
$entity = $this->lookup->getEntity( new ItemId( 'Q5' ) );
- $this->checker = new ConflictsWithChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper, new PlainEntityIdFormatter() );
+ $this->checker = new ConflictsWithChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper,
$this->constraintParameterRenderer );
$value = new EntityIdValue( new ItemId( 'Q100' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P188' ), $value ) );
@@ -126,7 +145,7 @@
public function testConflictsWithConstraintWithoutProperty() {
$entity = $this->lookup->getEntity( new ItemId( 'Q4' ) );
- $this->checker = new ConflictsWithChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper, new PlainEntityIdFormatter() );
+ $this->checker = new ConflictsWithChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper,
$this->constraintParameterRenderer );
$value = new EntityIdValue( new ItemId( 'Q100' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P188' ), $value ) );
@@ -139,7 +158,7 @@
public function testConflictsWithConstraintPropertyAndNoValue() {
$entity = $this->lookup->getEntity( new ItemId( 'Q6' ) );
- $this->checker = new ConflictsWithChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper, new PlainEntityIdFormatter() );
+ $this->checker = new ConflictsWithChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper,
$this->constraintParameterRenderer );
$value = new EntityIdValue( new ItemId( 'Q100' ) );
$statement = new Statement( new PropertyValueSnak( new
PropertyId( 'P188' ), $value ) );
diff --git a/tests/phpunit/Checker/ConnectionChecker/InverseCheckerTest.php
b/tests/phpunit/Checker/ConnectionChecker/InverseCheckerTest.php
index 4805892..62f535c 100644
--- a/tests/phpunit/Checker/ConnectionChecker/InverseCheckerTest.php
+++ b/tests/phpunit/Checker/ConnectionChecker/InverseCheckerTest.php
@@ -2,6 +2,7 @@
namespace WikibaseQuality\ConstraintReport\Test\ConnectionChecker;
+use ValueFormatters\ValueFormatter;
use Wikibase\DataModel\Services\EntityId\PlainEntityIdFormatter;
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
use Wikibase\DataModel\Statement\Statement;
@@ -14,6 +15,7 @@
use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\InverseChecker;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConnectionCheckerHelper;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
use WikibaseQuality\Tests\Helper\JsonFileEntityLookup;
/**
@@ -54,7 +56,17 @@
$this->lookup = new JsonFileEntityLookup( __DIR__ );
$this->helper = new ConstraintParameterParser();
$this->connectionCheckerHelper = new ConnectionCheckerHelper();
- $this->checker = new InverseChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper, new PlainEntityIdFormatter() );
+ $valueFormatter = $this->getMock( ValueFormatter::class );
+ $valueFormatter->method( 'format' )->willReturn( '' );
+ $this->checker = new InverseChecker(
+ $this->lookup,
+ $this->helper,
+ $this->connectionCheckerHelper,
+ new ConstraintParameterRenderer(
+ new PlainEntityIdFormatter(),
+ $valueFormatter
+ )
+ );
}
protected function tearDown() {
diff --git a/tests/phpunit/Checker/ConnectionChecker/SymmetricCheckerTest.php
b/tests/phpunit/Checker/ConnectionChecker/SymmetricCheckerTest.php
index d15d4a7..effc3e1 100644
--- a/tests/phpunit/Checker/ConnectionChecker/SymmetricCheckerTest.php
+++ b/tests/phpunit/Checker/ConnectionChecker/SymmetricCheckerTest.php
@@ -2,6 +2,7 @@
namespace WikibaseQuality\ConstraintReport\Test\ConnectionChecker;
+use ValueFormatters\ValueFormatter;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Services\EntityId\PlainEntityIdFormatter;
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
@@ -16,6 +17,7 @@
use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\SymmetricChecker;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConnectionCheckerHelper;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
use WikibaseQuality\Tests\Helper\JsonFileEntityLookup;
/**
@@ -56,7 +58,17 @@
$this->lookup = new JsonFileEntityLookup( __DIR__ );
$this->helper = new ConstraintParameterParser();
$this->connectionCheckerHelper = new ConnectionCheckerHelper();
- $this->checker = new SymmetricChecker( $this->lookup,
$this->helper, $this->connectionCheckerHelper, new PlainEntityIdFormatter() );
+ $valueFormatter = $this->getMock( ValueFormatter::class );
+ $valueFormatter->method( 'format' )->willReturn( '' );
+ $this->checker = new SymmetricChecker(
+ $this->lookup,
+ $this->helper,
+ $this->connectionCheckerHelper,
+ new ConstraintParameterRenderer(
+ new PlainEntityIdFormatter(),
+ $valueFormatter
+ )
+ );
}
protected function tearDown() {
diff --git a/tests/phpunit/Checker/OneOfChecker/OneOfCheckerTest.php
b/tests/phpunit/Checker/OneOfChecker/OneOfCheckerTest.php
index 400608d..b535c08 100644
--- a/tests/phpunit/Checker/OneOfChecker/OneOfCheckerTest.php
+++ b/tests/phpunit/Checker/OneOfChecker/OneOfCheckerTest.php
@@ -2,6 +2,7 @@
namespace WikibaseQuality\ConstraintReport\Test\OneOfChecker;
+use ValueFormatters\ValueFormatter;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Services\EntityId\PlainEntityIdFormatter;
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
@@ -15,6 +16,7 @@
use WikibaseQuality\ConstraintReport\Constraint;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\OneOfChecker;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
/**
* @covers
\WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\OneOfChecker
@@ -42,7 +44,15 @@
protected function setUp() {
parent::setUp();
$this->helper = new ConstraintParameterParser();
- $this->oneOfChecker = new OneOfChecker( $this->helper, new
PlainEntityIdFormatter() );
+ $valueFormatter = $this->getMock( ValueFormatter::class );
+ $valueFormatter->method( 'format' )->willReturn( '' );
+ $this->oneOfChecker = new OneOfChecker(
+ $this->helper,
+ new ConstraintParameterRenderer(
+ new PlainEntityIdFormatter(),
+ $valueFormatter
+ )
+ );
}
protected function tearDown() {
diff --git a/tests/phpunit/Checker/TypeChecker/TypeCheckerHelperTest.php
b/tests/phpunit/Checker/TypeChecker/TypeCheckerHelperTest.php
index e659d53..ec7cce4 100644
--- a/tests/phpunit/Checker/TypeChecker/TypeCheckerHelperTest.php
+++ b/tests/phpunit/Checker/TypeChecker/TypeCheckerHelperTest.php
@@ -3,6 +3,7 @@
namespace WikibaseQuality\ConstraintReport\Test\TypeChecker;
use PHPUnit_Framework_TestCase;
+use ValueFormatters\ValueFormatter;
use Wikibase\DataModel\Services\EntityId\PlainEntityIdFormatter;
use Wikibase\DataModel\Services\Lookup\EntityLookup;
use Wikibase\DataModel\Statement\Statement;
@@ -12,6 +13,7 @@
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Statement\StatementList;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\TypeCheckerHelper;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
use WikibaseQuality\ConstraintReport\Tests\DefaultConfig;
use WikibaseQuality\Tests\Helper\JsonFileEntityLookup;
@@ -33,10 +35,15 @@
* @return TypeCheckerHelper
*/
private function getHelper( EntityLookup $entityLookup = null ) {
+ $valueFormatter = $this->getMock( ValueFormatter::class );
+ $valueFormatter->method( 'format' )->willReturn( '' );
return new TypeCheckerHelper(
$entityLookup ?: new JsonFileEntityLookup( __DIR__ ),
$this->getDefaultConfig(),
- new PlainEntityIdFormatter()
+ new ConstraintParameterRenderer(
+ new PlainEntityIdFormatter(),
+ $valueFormatter
+ )
);
}
diff --git a/tests/phpunit/Checker/TypeChecker/TypeCheckerTest.php
b/tests/phpunit/Checker/TypeChecker/TypeCheckerTest.php
index 59ea713..0774aab 100644
--- a/tests/phpunit/Checker/TypeChecker/TypeCheckerTest.php
+++ b/tests/phpunit/Checker/TypeChecker/TypeCheckerTest.php
@@ -2,6 +2,7 @@
namespace WikibaseQuality\ConstraintReport\Test\TypeChecker;
+use ValueFormatters\ValueFormatter;
use Wikibase\DataModel\Services\EntityId\PlainEntityIdFormatter;
use Wikibase\DataModel\Statement\Statement;
use Wikibase\DataModel\Snak\PropertyValueSnak;
@@ -12,6 +13,7 @@
use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\TypeChecker;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\TypeCheckerHelper;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
use WikibaseQuality\ConstraintReport\Tests\DefaultConfig;
use WikibaseQuality\Tests\Helper\JsonFileEntityLookup;
@@ -48,13 +50,18 @@
protected function setUp() {
parent::setUp();
$this->lookup = new JsonFileEntityLookup( __DIR__ );
+ $valueFormatter = $this->getMock( ValueFormatter::class );
+ $valueFormatter->method( 'format' )->willReturn( '' );
$this->checker = new TypeChecker(
$this->lookup,
new ConstraintParameterParser(),
new TypeCheckerHelper(
$this->lookup,
$this->getDefaultConfig(),
- new PlainEntityIdFormatter()
+ new ConstraintParameterRenderer(
+ new PlainEntityIdFormatter(),
+ $valueFormatter
+ )
),
$this->getDefaultConfig()
);
diff --git a/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
b/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
index f5fc87e..2a8e3bd 100644
--- a/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
+++ b/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
@@ -2,6 +2,7 @@
namespace WikibaseQuality\ConstraintReport\Test\TypeChecker;
+use ValueFormatters\ValueFormatter;
use Wikibase\DataModel\Entity\EntityDocument;
use Wikibase\DataModel\Services\EntityId\PlainEntityIdFormatter;
use Wikibase\DataModel\Statement\Statement;
@@ -16,6 +17,7 @@
use WikibaseQuality\ConstraintReport\ConstraintCheck\Checker\ValueTypeChecker;
use
WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\ConstraintParameterParser;
use WikibaseQuality\ConstraintReport\ConstraintCheck\Helper\TypeCheckerHelper;
+use WikibaseQuality\ConstraintReport\ConstraintParameterRenderer;
use WikibaseQuality\ConstraintReport\Tests\DefaultConfig;
use WikibaseQuality\Tests\Helper\JsonFileEntityLookup;
@@ -53,13 +55,18 @@
parent::setUp();
$this->lookup = new JsonFileEntityLookup( __DIR__ );
+ $valueFormatter = $this->getMock( ValueFormatter::class );
+ $valueFormatter->method( 'format' )->willReturn( '' );
$this->checker = new ValueTypeChecker(
$this->lookup,
new ConstraintParameterParser(),
new TypeCheckerHelper(
$this->lookup,
$this->getDefaultConfig(),
- new PlainEntityIdFormatter()
+ new ConstraintParameterRenderer(
+ new PlainEntityIdFormatter(),
+ $valueFormatter
+ )
),
$this->getDefaultConfig()
);
diff --git a/tests/phpunit/DelegatingConstraintCheckerTest.php
b/tests/phpunit/DelegatingConstraintCheckerTest.php
index 4efe254..0438dcd 100644
--- a/tests/phpunit/DelegatingConstraintCheckerTest.php
+++ b/tests/phpunit/DelegatingConstraintCheckerTest.php
@@ -74,7 +74,6 @@
$this->lookup,
$this->statementGuidParser,
$this->getDefaultConfig(),
- $entityIdFormatter,
new ConstraintParameterRenderer(
$entityIdFormatter,
$valueFormatter
--
To view, visit https://gerrit.wikimedia.org/r/353976
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I86adfb5afeef0836fc7b489fc1b5eaa9733acdff
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[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