jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/403967 )
Change subject: Add status parameter to CheckConstraints ...................................................................... Add status parameter to CheckConstraints This new parameter of the wbcheckconstraints API corresponds to the $statuses parameter of ResultsBuilder and filters the returned check results. For now, the default value is '*' (all statuses) to preserve compatibility, but we plan to change it to just the three statuses for which results are also cached in the future. Bug: T183927 Change-Id: I69885a05734956722f939e8a71d1490afc8182ab --- M i18n/en.json M i18n/qqq.json M src/Api/CheckConstraints.php M src/ConstraintCheck/Result/CheckResult.php M tests/phpunit/Api/CheckConstraintsTest.php 5 files changed, 83 insertions(+), 17 deletions(-) Approvals: Lucas Werkmeister (WMDE): Looks good to me, approved jenkins-bot: Verified diff --git a/i18n/en.json b/i18n/en.json index 2271b21..7bb971a 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -54,6 +54,15 @@ "apihelp-wbcheckconstraints-param-id": "ID list of the entities to get the data from. Separate values with '|' or alternative.", "apihelp-wbcheckconstraints-param-claimid": "GUID list identifying a claim to check a constraint report. Separate values with '|'.", "apihelp-wbcheckconstraints-param-constraintid": "Optional filter to return only the constraints that have the specified constraint ID.", + "apihelp-wbcheckconstraints-param-status": "Optional filter to return only check results with the selected statuses.\n\nNote that only results for the 'violation', 'warning' and 'bad-parameters' statuses are cached, so any request that is not limited to only those statuses (or a subset of them) does not benefit from caching.", + "apihelp-wbcheckconstraints-paramvalue-status-compliance": "The statement satisfies the constraint.", + "apihelp-wbcheckconstraints-paramvalue-status-violation": "The statement violates the constraint.", + "apihelp-wbcheckconstraints-paramvalue-status-exception": "The subject entity of the statement is a known exception to the constraint.", + "apihelp-wbcheckconstraints-paramvalue-status-todo": "The constraint is not implemented.", + "apihelp-wbcheckconstraints-paramvalue-status-bad-parameters": "The constraint parameters are broken.", + "apihelp-wbcheckconstraints-paramvalue-status-deprecated": "The constraint has not been checked because the statement is deprecated.", + "apihelp-wbcheckconstraints-paramvalue-status-warning": "The statement violates the constraint, but the constraint is not mandatory.", + "apihelp-wbcheckconstraints-paramvalue-status-not-in-scope": "The constraint is not checked on this kind of snak (main snak, qualifier or reference), so the constraint check is skipped.", "apihelp-wbcheckconstraintparameters-summary": "Checks the constraint parameters of constraint statements.", "apihelp-wbcheckconstraintparameters-extended-description": "Either or both of the <var>property</var> and <var>constraintid</var> parameters may be specified; all constraints selected by either parameter will be checked.", "apihelp-wbcheckconstraintparameters-param-propertyid": "List of property IDs to check. All constraint statements of these properties will be checked.\n\nIf this parameter is specified, it must be nonempty.", diff --git a/i18n/qqq.json b/i18n/qqq.json index 00a7406..fa6b9f2 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -56,6 +56,15 @@ "apihelp-wbcheckconstraints-param-id": "{{doc-apihelp-param|wbcheckconstraints|id}}", "apihelp-wbcheckconstraints-param-claimid": "{{doc-apihelp-param|wbcheckconstraints|claimid}}", "apihelp-wbcheckconstraints-param-constraintid": "Sorry, the below documentation appears to be outdated, since no such patterns exist in the original text under translation:\n\n\n{{doc-apihelp-param|wbcheckconstraints|constraintid}}", + "apihelp-wbcheckconstraints-param-status": "{{doc-apihelp-param|wbcheckconstraints|status}}", + "apihelp-wbcheckconstraints-paramvalue-status-compliance": "{{doc-apihelp-paramvalue|wbcheckconstraints|status|compliance}}", + "apihelp-wbcheckconstraints-paramvalue-status-violation": "{{doc-apihelp-paramvalue|wbcheckconstraints|status|violation}}", + "apihelp-wbcheckconstraints-paramvalue-status-exception": "{{doc-apihelp-paramvalue|wbcheckconstraints|status|exception}}", + "apihelp-wbcheckconstraints-paramvalue-status-todo": "{{doc-apihelp-paramvalue|wbcheckconstraints|status|todo}}", + "apihelp-wbcheckconstraints-paramvalue-status-bad-parameters": "{{doc-apihelp-paramvalue|wbcheckconstraints|status|bad-parameters}}", + "apihelp-wbcheckconstraints-paramvalue-status-deprecated": "{{doc-apihelp-paramvalue|wbcheckconstraints|status|deprecated}}", + "apihelp-wbcheckconstraints-paramvalue-status-warning": "{{doc-apihelp-paramvalue|wbcheckconstraints|status|warning}}", + "apihelp-wbcheckconstraints-paramvalue-status-not-in-scope": "{{doc-apihelp-paramvalue|wbcheckconstraints|status|not-in-scope}}", "apihelp-wbcheckconstraintparameters-summary": "{{doc-apihelp-summary|wbcheckconstraintparameters}}", "apihelp-wbcheckconstraintparameters-extended-description": "{{doc-apihelp-extended-description|wbcheckconstraintparameters}}", "apihelp-wbcheckconstraintparameters-param-propertyid": "{{doc-apihelp-param|wbcheckconstraintparameters|propertyid}}", diff --git a/src/Api/CheckConstraints.php b/src/Api/CheckConstraints.php index 9d8801a..46b5303 100644 --- a/src/Api/CheckConstraints.php +++ b/src/Api/CheckConstraints.php @@ -35,6 +35,7 @@ const PARAM_ID = 'id'; const PARAM_CLAIM_ID = 'claimid'; const PARAM_CONSTRAINT_ID = 'constraintid'; + const PARAM_STATUS = 'status'; /** * @var EntityIdParser @@ -201,6 +202,7 @@ $entityIds = $this->parseEntityIds( $params ); $claimIds = $this->parseClaimIds( $params ); $constraintIDs = $params[self::PARAM_CONSTRAINT_ID]; + $statuses = $params[self::PARAM_STATUS]; $this->getResult()->addValue( null, @@ -209,16 +211,7 @@ $entityIds, $claimIds, $constraintIDs, - [ - CheckResult::STATUS_COMPLIANCE, - CheckResult::STATUS_VIOLATION, - CheckResult::STATUS_WARNING, - CheckResult::STATUS_EXCEPTION, - CheckResult::STATUS_NOT_IN_SCOPE, - CheckResult::STATUS_DEPRECATED, - CheckResult::STATUS_BAD_PARAMETERS, - CheckResult::STATUS_TODO, - ] + $statuses )->getArray() ); // ensure that result contains the given entity IDs even if they have no statements @@ -317,6 +310,26 @@ ApiBase::PARAM_TYPE => 'string', ApiBase::PARAM_ISMULTI => true, ], + self::PARAM_STATUS => [ + ApiBase::PARAM_TYPE => [ + CheckResult::STATUS_COMPLIANCE, + CheckResult::STATUS_VIOLATION, + CheckResult::STATUS_WARNING, + CheckResult::STATUS_EXCEPTION, + CheckResult::STATUS_NOT_IN_SCOPE, + CheckResult::STATUS_DEPRECATED, + CheckResult::STATUS_BAD_PARAMETERS, + CheckResult::STATUS_TODO, + ], + ApiBase::PARAM_ISMULTI => true, + ApiBase::PARAM_ALL => true, + ApiBase::PARAM_DFLT => /* implode( '|', [ + CheckResult::STATUS_VIOLATION, + CheckResult::STATUS_WARNING, + CheckResult::STATUS_BAD_PARAMETERS, + ] )*/ '*', + ApiBase::PARAM_HELP_MSG_PER_VALUE => [], + ], ]; } diff --git a/src/ConstraintCheck/Result/CheckResult.php b/src/ConstraintCheck/Result/CheckResult.php index 62679a3..7aab614 100644 --- a/src/ConstraintCheck/Result/CheckResult.php +++ b/src/ConstraintCheck/Result/CheckResult.php @@ -58,9 +58,12 @@ const STATUS_NOT_IN_SCOPE = 'not-in-scope'; /* * When adding another status, don’t forget to also do the following: - * * define a message for it in i18n/ + * * define messages for it in i18n/: + * * wbqc-constraintreport-status- + * * apihelp-wbcheckconstraints-paramvalue-status- * * declare a color for it in modules/SpecialConstraintReportPage.less * * update $order in DelegatingConstraintChecker::sortResult + * * update PARAM_STATUS type in CheckConstraints::getAllowedParams */ /** diff --git a/tests/phpunit/Api/CheckConstraintsTest.php b/tests/phpunit/Api/CheckConstraintsTest.php index 6570d6f..4ae94a2 100644 --- a/tests/phpunit/Api/CheckConstraintsTest.php +++ b/tests/phpunit/Api/CheckConstraintsTest.php @@ -18,6 +18,8 @@ use Wikibase\DataModel\Statement\Statement; use Wikibase\DataModel\Statement\StatementList; use Wikibase\Repo\EntityIdLabelFormatterFactory; +use Wikibase\Repo\Tests\NewItem; +use Wikibase\Repo\Tests\NewStatement; use Wikibase\Repo\WikibaseRepo; use WikibaseQuality\ConstraintReport\Api\CheckConstraints; use WikibaseQuality\ConstraintReport\Constraint; @@ -200,7 +202,7 @@ new PropertyId( 'P1' ), '46fc8ec9-4903-4592-9a0e-afdd1fa03183' ); - $this->givenPropertyHasViolation( new PropertyId( 'P1' ) ); + $this->givenPropertyHasStatus( new PropertyId( 'P1' ), CheckResult::STATUS_VIOLATION ); $result = $this->doRequest( [ CheckConstraints::PARAM_ID => 'Q1' ] ); @@ -219,7 +221,7 @@ new PropertyId( 'P1' ), '46fc8ec9-4903-4592-9a0e-afdd1fa03183' ); - $this->givenPropertyHasViolation( new PropertyId( 'P1' ) ); + $this->givenPropertyHasStatus( new PropertyId( 'P1' ), CheckResult::STATUS_VIOLATION ); $result = $this->doRequest( [ CheckConstraints::PARAM_CLAIM_ID => 'Q1$46fc8ec9-4903-4592-9a0e-afdd1fa03183' ] ); @@ -241,7 +243,7 @@ $statement->setGuid( $guid ); $item->getStatements()->addStatement( $statement ); self::$entityLookup->addEntity( $item ); - $this->givenPropertyHasViolation( new PropertyId( $propertyId ) ); + $this->givenPropertyHasStatus( new PropertyId( $propertyId ), CheckResult::STATUS_VIOLATION ); $result = $this->doRequest( [ CheckConstraints::PARAM_CLAIM_ID => $guid ] ); @@ -254,6 +256,34 @@ $this->assertEquals( $propertyId, $resultsForItem[0]['property'] ); } + public function testStatusParameterFiltersResults() { + $item = NewItem::withId( 'Q1' ) + ->andStatement( NewStatement::noValueFor( 'P1' ) ) + ->andStatement( NewStatement::noValueFor( 'P2' ) ) + ->build(); + self::$entityLookup->addEntity( $item ); + $this->givenPropertyHasStatus( new PropertyId( 'P1' ), CheckResult::STATUS_VIOLATION ); + $this->givenPropertyHasStatus( new PropertyId( 'P2' ), CheckResult::STATUS_COMPLIANCE ); + + $result = $this->doRequest( [ + CheckConstraints::PARAM_ID => 'Q1', + CheckConstraints::PARAM_STATUS => CheckResult::STATUS_VIOLATION . '|' . CheckResult::STATUS_WARNING, + ] ); + + $this->assertCount( 1, $result['wbcheckconstraints'] ); + $this->assertCount( 2, $result['wbcheckconstraints']['Q1']['claims'] ); + + $violatingStatement = $result['wbcheckconstraints']['Q1']['claims']['P1'][0]; + $violatingStatementResults = $violatingStatement['mainsnak']['results']; + $this->assertCount( 1, $violatingStatementResults ); + $this->assertEquals( CheckResult::STATUS_WARNING, $violatingStatementResults[0]['status'] ); + $this->assertEquals( 'P1', $violatingStatementResults[0]['property'] ); + + $compliantStatement = $result['wbcheckconstraints']['Q1']['claims']['P2'][0]; + $compliantStatementResults = $compliantStatement['mainsnak']['results']; + $this->assertCount( 0, $compliantStatementResults ); + } + /** * @param array $params * @return array Array of violations @@ -263,12 +293,14 @@ return $this->doApiRequest( $params, [], false, null )[0]; } - private function givenPropertyHasViolation( PropertyId $propertyId ) { - self::$checkerMap['Q1234'] = new FakeChecker( CheckResult::STATUS_VIOLATION ); + private function givenPropertyHasStatus( PropertyId $propertyId, $status ) { + static $itemIdNumber = 1234; + $itemId = 'Q' . $itemIdNumber++; + self::$checkerMap[$itemId] = new FakeChecker( $status ); self::$constraintLookupContents[] = new Constraint( 'P1234$6a4d1930-922b-4c2e-b6e1-9a06bf04c2f8', $propertyId, - 'Q1234', + $itemId, [] ); } -- To view, visit https://gerrit.wikimedia.org/r/403967 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I69885a05734956722f939e8a71d1490afc8182ab Gerrit-PatchSet: 4 Gerrit-Project: mediawiki/extensions/WikibaseQualityConstraints Gerrit-Branch: master Gerrit-Owner: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de> Gerrit-Reviewer: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de> Gerrit-Reviewer: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits