jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/362395 )
Change subject: Add {class,relation}Parameter to ConstraintParameters
......................................................................
Add {class,relation}Parameter to ConstraintParameters
The ConstraintParameters test trait gains two methods to generate class
and relation parameters, and the tests for the “type” and “value type”
checkers are updated to use them. This means that the tests will
continue to work when we remove support for constraints imported from
templates.
Tests that were dedicated to constraint statements are removed, since
the new methods always use constraint statement-style parameters.
(ConstraintParameterParser tests ensure that both template and statement
parameters are supported.)
Bug: T172378
Change-Id: I507bbdeda6b638e7ae28cbc59a1ea9fb6cefa72d
---
M tests/phpunit/Checker/TypeChecker/TypeCheckerTest.php
M tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
M tests/phpunit/ConstraintParameters.php
3 files changed, 161 insertions(+), 196 deletions(-)
Approvals:
WMDE-leszek: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/phpunit/Checker/TypeChecker/TypeCheckerTest.php
b/tests/phpunit/Checker/TypeChecker/TypeCheckerTest.php
index 16ef71e..2a2a21d 100644
--- a/tests/phpunit/Checker/TypeChecker/TypeCheckerTest.php
+++ b/tests/phpunit/Checker/TypeChecker/TypeCheckerTest.php
@@ -65,172 +65,130 @@
public function testTypeConstraintInstanceValid() {
$entity = $this->lookup->getEntity( new ItemId( 'Q1' ) );
- $constraintParameters = [
- 'class' => 'Q100,Q101',
- 'relation' => 'instance'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertCompliance( $checkResult );
}
public function testTypeConstraintInstanceValidWithIndirection() {
$entity = $this->lookup->getEntity( new ItemId( 'Q2' ) );
- $constraintParameters = [
- 'class' => 'Q100,Q101',
- 'relation' => 'instance'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertCompliance( $checkResult );
}
public function testTypeConstraintInstanceValidWithMoreIndirection() {
$entity = $this->lookup->getEntity( new ItemId( 'Q3' ) );
- $constraintParameters = [
- 'class' => 'Q100,Q101',
- 'relation' => 'instance'
- ];
- $checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
- $this->assertCompliance( $checkResult );
- }
-
- public function testTypeConstraintInstanceValidWithStatement() {
- $entity = $this->lookup->getEntity( new ItemId( 'Q1' ) );
- $snakSerializer =
WikibaseRepo::getDefaultInstance()->getBaseDataModelSerializerFactory()->newSnakSerializer();
- $classId = $this->getDefaultConfig()->get(
'WBQualityConstraintsClassId' );
- $relationId = $this->getDefaultConfig()->get(
'WBQualityConstraintsRelationId' );
- $constraintParameters = [
- $classId => [
- $snakSerializer->serialize( new
PropertyValueSnak( new PropertyId( $classId ), new EntityIdValue( new ItemId(
'Q100' ) ) ) ),
- $snakSerializer->serialize( new
PropertyValueSnak( new PropertyId( $classId ), new EntityIdValue( new ItemId(
'Q101' ) ) ) )
- ],
- $relationId => [
- $snakSerializer->serialize( new
PropertyValueSnak(
- new PropertyId( $relationId ),
- new EntityIdValue( new ItemId(
$this->getDefaultConfig()->get( 'WBQualityConstraintsInstanceOfRelationId' ) ) )
- ) )
- ]
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertCompliance( $checkResult );
}
public function testTypeConstraintSubclassValid() {
$entity = $this->lookup->getEntity( new ItemId( 'Q4' ) );
- $constraintParameters = [
- 'class' => 'Q100,Q101',
- 'relation' => 'subclass'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertCompliance( $checkResult );
}
public function testTypeConstraintSubclassValidWithIndirection() {
$entity = $this->lookup->getEntity( new ItemId( 'Q5' ) );
- $constraintParameters = [
- 'class' => 'Q100,Q101',
- 'relation' => 'subclass'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertCompliance( $checkResult );
}
public function testTypeConstraintSubclassValidWithMoreIndirection() {
$entity = $this->lookup->getEntity( new ItemId( 'Q6' ) );
- $constraintParameters = [
- 'class' => 'Q100,Q101',
- 'relation' => 'subclass'
- ];
- $checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
- $this->assertCompliance( $checkResult );
- }
-
- public function testTypeConstraintSubclassValidWithStatement() {
- $entity = $this->lookup->getEntity( new ItemId( 'Q4' ) );
- $snakSerializer =
WikibaseRepo::getDefaultInstance()->getBaseDataModelSerializerFactory()->newSnakSerializer();
- $classId = $this->getDefaultConfig()->get(
'WBQualityConstraintsClassId' );
- $relationId = $this->getDefaultConfig()->get(
'WBQualityConstraintsRelationId' );
- $constraintParameters = [
- $classId => [
- $snakSerializer->serialize( new
PropertyValueSnak( new PropertyId( $classId ), new EntityIdValue( new ItemId(
'Q100' ) ) ) ),
- $snakSerializer->serialize( new
PropertyValueSnak( new PropertyId( $classId ), new EntityIdValue( new ItemId(
'Q101' ) ) ) )
- ],
- $relationId => [
- $snakSerializer->serialize( new
PropertyValueSnak(
- new PropertyId( $relationId ),
- new EntityIdValue( new ItemId(
$this->getDefaultConfig()->get( 'WBQualityConstraintsSubclassOfRelationId' ) ) )
- ) )
- ]
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertCompliance( $checkResult );
}
public function testTypeConstraintInstanceInvalid() {
$entity = $this->lookup->getEntity( new ItemId( 'Q1' ) );
- $constraintParameters = [
- 'class' => 'Q200,Q201',
- 'relation' => 'instance'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertViolation( $checkResult,
'wbqc-violation-message-type-instance' );
}
public function testTypeConstraintInstanceInvalidWithIndirection() {
$entity = $this->lookup->getEntity( new ItemId( 'Q2' ) );
- $constraintParameters = [
- 'class' => 'Q200,Q201',
- 'relation' => 'instance'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertViolation( $checkResult,
'wbqc-violation-message-type-instance' );
}
public function testTypeConstraintInstanceInvalidWithMoreIndirection() {
$entity = $this->lookup->getEntity( new ItemId( 'Q3' ) );
- $constraintParameters = [
- 'class' => 'Q200,Q201',
- 'relation' => 'instance'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertViolation( $checkResult,
'wbqc-violation-message-type-instance' );
}
public function testTypeConstraintSubclassInvalid() {
$entity = $this->lookup->getEntity( new ItemId( 'Q4' ) );
- $constraintParameters = [
- 'class' => 'Q200,Q201',
- 'relation' => 'subclass'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertViolation( $checkResult,
'wbqc-violation-message-type-subclass' );
}
public function testTypeConstraintSubclassInvalidWithIndirection() {
$entity = $this->lookup->getEntity( new ItemId( 'Q5' ) );
- $constraintParameters = [
- 'class' => 'Q200,Q201' ,
- 'relation' => 'subclass'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertViolation( $checkResult,
'wbqc-violation-message-type-subclass' );
}
public function testTypeConstraintSubclassInvalidWithMoreIndirection() {
$entity = $this->lookup->getEntity( new ItemId( 'Q6' ) );
- $constraintParameters = [
- 'class' => 'Q200,Q201',
- 'relation' => 'subclass'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertViolation( $checkResult,
'wbqc-violation-message-type-subclass' );
}
public function testTypeConstraintSubclassCycle() {
$entity = $this->lookup->getEntity( new ItemId( 'Q7' ) );
- $constraintParameters = [
- 'class' => 'Q100,Q101',
- 'relation' => 'instance'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint(
$this->typeStatement, $this->getConstraintMock( $constraintParameters ),
$entity );
$this->assertViolation( $checkResult,
'wbqc-violation-message-type-instance' );
}
diff --git a/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
b/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
index 68b4e14..d0436a6 100644
--- a/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
+++ b/tests/phpunit/Checker/TypeChecker/ValueTypeCheckerTest.php
@@ -70,192 +70,150 @@
public function testValueTypeConstraintInstanceValid() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q1' ) ) ) );
- $constraintParameters = [
- 'relation' => 'instance',
- 'class' => 'Q100,Q101'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertCompliance( $checkResult );
}
public function testValueTypeConstraintInstanceValidWithIndirection() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q2' ) ) ) );
- $constraintParameters = [
- 'relation' => 'instance',
- 'class' => 'Q100,Q101'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertCompliance( $checkResult );
}
public function
testValueTypeConstraintInstanceValidWithMoreIndirection() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q3' ) ) ) );
- $constraintParameters = [
- 'relation' => 'instance',
- 'class' => 'Q100,Q101'
- ];
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
- $this->assertCompliance( $checkResult );
- }
-
- public function testTypeConstraintInstanceValidWithStatement() {
- $statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q3' ) ) ) );
- $snakSerializer =
WikibaseRepo::getDefaultInstance()->getBaseDataModelSerializerFactory()->newSnakSerializer();
- $classId = $this->getDefaultConfig()->get(
'WBQualityConstraintsClassId' );
- $relationId = $this->getDefaultConfig()->get(
'WBQualityConstraintsRelationId' );
- $constraintParameters = [
- $classId => [
- $snakSerializer->serialize( new
PropertyValueSnak( new PropertyId( $classId ), new EntityIdValue( new ItemId(
'Q100' ) ) ) ),
- $snakSerializer->serialize( new
PropertyValueSnak( new PropertyId( $classId ), new EntityIdValue( new ItemId(
'Q101' ) ) ) )
- ],
- $relationId => [
- $snakSerializer->serialize( new
PropertyValueSnak(
- new PropertyId( $relationId ),
- new EntityIdValue( new ItemId(
$this->getDefaultConfig()->get( 'WBQualityConstraintsInstanceOfRelationId' ) ) )
- ) )
- ]
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertCompliance( $checkResult );
}
public function testValueTypeConstraintSubclassValid() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q4' ) ) ) );
- $constraintParameters = [
- 'relation' => 'subclass',
- 'class' => 'Q100,Q101'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertCompliance( $checkResult );
}
public function testValueTypeConstraintSubclassValidWithIndirection() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q5' ) ) ) );
- $constraintParameters = [
- 'relation' => 'subclass',
- 'class' => 'Q100,Q101'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertCompliance( $checkResult );
}
public function
testValueTypeConstraintSubclassValidWithMoreIndirection() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q6' ) ) ) );
- $constraintParameters = [
- 'relation' => 'subclass',
- 'class' => 'Q100,Q101'
- ];
- $checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
- $this->assertCompliance( $checkResult );
- }
-
- public function testTypeConstraintSubclassValidWithStatement() {
- $statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q4' ) ) ) );
- $snakSerializer =
WikibaseRepo::getDefaultInstance()->getBaseDataModelSerializerFactory()->newSnakSerializer();
- $classId = $this->getDefaultConfig()->get(
'WBQualityConstraintsClassId' );
- $relationId = $this->getDefaultConfig()->get(
'WBQualityConstraintsRelationId' );
- $constraintParameters = [
- $classId => [
- $snakSerializer->serialize( new
PropertyValueSnak( new PropertyId( $classId ), new EntityIdValue( new ItemId(
'Q100' ) ) ) ),
- $snakSerializer->serialize( new
PropertyValueSnak( new PropertyId( $classId ), new EntityIdValue( new ItemId(
'Q101' ) ) ) )
- ],
- $relationId => [
- $snakSerializer->serialize( new
PropertyValueSnak(
- new PropertyId( $relationId ),
- new EntityIdValue( new ItemId(
$this->getDefaultConfig()->get( 'WBQualityConstraintsSubclassOfRelationId' ) ) )
- ) )
- ]
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertCompliance( $checkResult );
}
public function testValueTypeConstraintInstanceInvalid() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q1' ) ) ) );
- $constraintParameters = [
- 'relation' => 'instance',
- 'class' => 'Q200,Q201'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertViolation( $checkResult,
'wbqc-violation-message-valueType-instance' );
}
public function testValueTypeConstraintInstanceInvalidWithIndirection()
{
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q2' ) ) ) );
- $constraintParameters = [
- 'relation' => 'instance',
- 'class' => 'Q200,Q201'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertViolation( $checkResult,
'wbqc-violation-message-valueType-instance' );
}
public function
testValueTypeConstraintInstanceInvalidWithMoreIndirection() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q3' ) ) ) );
- $constraintParameters = [
- 'relation' => 'instance',
- 'class' => 'Q200,Q201'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertViolation( $checkResult,
'wbqc-violation-message-valueType-instance' );
}
public function testValueTypeConstraintSubclassInvalid() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q4' ) ) ) );
- $constraintParameters = [
- 'relation' => 'subclass',
- 'class' => 'Q200,Q201'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertViolation( $checkResult,
'wbqc-violation-message-valueType-subclass' );
}
public function testValueTypeConstraintSubclassInvalidWithIndirection()
{
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q5' ) ) ) );
- $constraintParameters = [
- 'relation' => 'subclass',
- 'class' => 'Q200,Q201'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertViolation( $checkResult,
'wbqc-violation-message-valueType-subclass' );
}
public function
testValueTypeConstraintSubclassInvalidWithMoreIndirection() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q6' ) ) ) );
- $constraintParameters = [
- 'relation' => 'subclass',
- 'class' => 'Q200,Q201'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'subclass' ),
+ $this->classParameter( [ 'Q200', 'Q201' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertViolation( $checkResult,
'wbqc-violation-message-valueType-subclass' );
}
public function testValueTypeConstraintWrongType() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new StringValue( 'foo bar baz' ) ) );
- $constraintParameters = [
- 'relation' => 'instance',
- 'class' => 'Q100,Q101'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertViolation( $checkResult,
'wbqc-violation-message-value-needed-of-type' );
}
public function testValueTypeConstraintNonExistingValue() {
$statement = new Statement( new PropertyValueSnak(
$this->valueTypePropertyId, new EntityIdValue( new ItemId( 'Q100' ) ) ) );
- $constraintParameters = [
- 'relation' => 'instance',
- 'class' => 'Q100,Q101'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertViolation( $checkResult,
'wbqc-violation-message-value-entity-must-exist' );
}
public function testValueTypeConstraintNoValueSnak() {
$statement = NewStatement::noValueFor( 'P1' )->build();
- $constraintParameters = [
- 'relation' => 'instance',
- 'class' => 'Q100,Q101'
- ];
+ $constraintParameters = array_merge(
+ $this->relationParameter( 'instance' ),
+ $this->classParameter( [ 'Q100', 'Q101' ] )
+ );
$checkResult = $this->checker->checkConstraint( $statement,
$this->getConstraintMock( $constraintParameters ), $this->getEntity() );
$this->assertCompliance( $checkResult );
}
diff --git a/tests/phpunit/ConstraintParameters.php
b/tests/phpunit/ConstraintParameters.php
index c527d10..e7fb376 100644
--- a/tests/phpunit/ConstraintParameters.php
+++ b/tests/phpunit/ConstraintParameters.php
@@ -5,9 +5,11 @@
use DataValues\DataValue;
use DataValues\StringValue;
use DataValues\UnboundedQuantityValue;
+use InvalidArgumentException;
use Serializers\Serializer;
use ValueFormatters\ValueFormatter;
use Wikibase\DataModel\Entity\EntityIdValue;
+use Wikibase\DataModel\Entity\ItemId;
use Wikibase\DataModel\Entity\PropertyId;
use Wikibase\DataModel\Services\EntityId\PlainEntityIdFormatter;
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
@@ -80,6 +82,53 @@
}
/**
+ * @param string[] $classIds item ID serializations
+ * @return array
+ */
+ public function classParameter( array $classIds ) {
+ $classParameterId = $this->getDefaultConfig()->get(
'WBQualityConstraintsClassId' );
+ return [
+ $classParameterId => array_map(
+ function( $classId ) use ( $classParameterId ) {
+ return
$this->getSnakSerializer()->serialize(
+ new PropertyValueSnak(
+ new PropertyId(
$classParameterId ),
+ new EntityIdValue( new
ItemId( $classId ) )
+ )
+ );
+ },
+ $classIds
+ )
+ ];
+ }
+
+ /**
+ * @param string $relation 'instance' or 'subclass'
+ * @return array
+ */
+ public function relationParameter( $relation ) {
+ $relationParameterId = $this->getDefaultConfig()->get(
'WBQualityConstraintsRelationId' );
+ switch ( $relation ) {
+ case 'instance':
+ $configKey =
'WBQualityConstraintsInstanceOfRelationId';
+ break;
+ case 'subclass':
+ $configKey =
'WBQualityConstraintsSubclassOfRelationId';
+ break;
+ default:
+ throw new InvalidArgumentException( '$relation
must be instance or subclass' );
+ }
+ return [
+ $relationParameterId => [
$this->getSnakSerializer()->serialize(
+ new PropertyValueSnak(
+ new PropertyId( $relationParameterId ),
+ new EntityIdValue( new ItemId(
$this->getDefaultConfig()->get( $configKey ) ) )
+ )
+ ) ]
+ ];
+ }
+
+ /**
* @param string $propertyId property ID serialization
* @return array
*/
--
To view, visit https://gerrit.wikimedia.org/r/362395
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I507bbdeda6b638e7ae28cbc59a1ea9fb6cefa72d
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints
Gerrit-Branch: master
Gerrit-Owner: Lucas Werkmeister (WMDE) <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: Lucas Werkmeister (WMDE) <[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