Jonaskeutel has submitted this change and it was merged. Change subject: Fixed tests ......................................................................
Fixed tests Change-Id: I27ad24f098608d5a877f9902f2f96ecb3c664476 --- M includes/Constraint.php M includes/ConstraintCheck/Helper/ConstraintReportHelper.php M includes/ConstraintRepository.php M maintenance/UpdateTable.php M tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php M tests/phpunit/ConstraintRepositoryTest.php M tests/phpunit/ConstraintTest.php M tests/phpunit/Helper/ConstraintReportHelperTest.php 8 files changed, 41 insertions(+), 33 deletions(-) Approvals: Jonaskeutel: Verified; Looks good to me, approved diff --git a/includes/Constraint.php b/includes/Constraint.php index d85f910..699296d 100644 --- a/includes/Constraint.php +++ b/includes/Constraint.php @@ -2,6 +2,9 @@ namespace WikibaseQuality\ConstraintReport; +use Wikibase\DataModel\Entity\PropertyId; + + /** * Class Constraint * @@ -38,11 +41,11 @@ /** * @param string $constraintClaimGuid - * @param string $propertyId + * @param PropertyId $propertyId * @param string $constraintTypeQid * @param array $constraintParameters */ - public function __construct( $constraintClaimGuid, $propertyId, $constraintTypeQid, $constraintParameters) { + public function __construct( $constraintClaimGuid, PropertyId $propertyId, $constraintTypeQid, $constraintParameters) { $this->constraintClaimGuid = $constraintClaimGuid; $this->constraintTypeQid = $constraintTypeQid; $this->propertyId = $propertyId; diff --git a/includes/ConstraintCheck/Helper/ConstraintReportHelper.php b/includes/ConstraintCheck/Helper/ConstraintReportHelper.php index bd5a9bd..4f10d75 100755 --- a/includes/ConstraintCheck/Helper/ConstraintReportHelper.php +++ b/includes/ConstraintCheck/Helper/ConstraintReportHelper.php @@ -87,7 +87,7 @@ */ public function parseParameterArray( $parameterArray, $asString = false ) { if ( $parameterArray[ 0 ] === '' ) { // parameter not given - return array ( 'null' ); + return array ( 'none' ); } else { $array = array (); foreach ( $parameterArray as $parameter ) { @@ -104,7 +104,7 @@ * @return null|string */ public function getParameterFromJson( $json, $parameter ) { - isset( $json->$parameter ) ? $json->$parameter : null; + return isset( $json->$parameter ) ? $json->$parameter : null; } } \ No newline at end of file diff --git a/includes/ConstraintRepository.php b/includes/ConstraintRepository.php index 42586c2..487c24e 100644 --- a/includes/ConstraintRepository.php +++ b/includes/ConstraintRepository.php @@ -42,7 +42,7 @@ function ( Constraint $constraint ) { return array( 'constraint_guid' => $constraint->getConstraintClaimGuid(), - 'pid' => $constraint->getPropertyId(), + 'pid' => $constraint->getPropertyId()->getNumericId(), 'constraint_type_qid' => $constraint->getConstraintTypeQid(), 'constraint_parameters' => json_encode( $constraint->getConstraintParameters() ) ); @@ -84,7 +84,8 @@ foreach( $results as $result ) { $constraintTypeQid = $result->constraint_type_qid; $constraintParameters = (array) json_decode( $result->constraint_parameters ); - $constraints[] = new Constraint( $result->constraint_guid, new PropertyId( $result->pid ), $constraintTypeQid, $constraintParameters ); + $serializedPid = 'P' . $result->pid; + $constraints[] = new Constraint( $result->constraint_guid, new PropertyId( $serializedPid ), $constraintTypeQid, $constraintParameters ); } return $constraints; } diff --git a/maintenance/UpdateTable.php b/maintenance/UpdateTable.php index 9e94d9b..9b822d2 100644 --- a/maintenance/UpdateTable.php +++ b/maintenance/UpdateTable.php @@ -3,6 +3,7 @@ namespace WikibaseQuality\ConstraintReport\Maintenance; // @codeCoverageIgnoreStart +use Wikibase\DataModel\Entity\PropertyId; use WikibaseQuality\ConstraintReport\Constraint; use WikibaseQuality\ConstraintReport\ConstraintReportFactory; @@ -63,7 +64,8 @@ } $constraintParameters = (array) json_decode( $data[3] ); - $accumulator[] = new Constraint( $data[0], $data[1], $data[2], $constraintParameters ); + $propertyId = new PropertyId( 'P' . $data[1] ); + $accumulator[] = new Constraint( $data[0], $propertyId, $data[2], $constraintParameters ); } } diff --git a/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php b/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php index 9ffddf8..226c23b 100755 --- a/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php +++ b/tests/phpunit/Checker/FormatChecker/FormatCheckerTest.php @@ -66,16 +66,16 @@ $statement9 = new Statement( new PropertyValueSnak( new PropertyId( 'P345' ), $value9 ) ); $statement10 = new Statement( new PropertyValueSnak( new PropertyId( 'P345' ), $value10 ) ); - $this->assertEquals( 'compliance', $this->formatChecker->checkConstraint( $statement1, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); - $this->assertEquals( 'compliance', $this->formatChecker->checkConstraint( $statement2, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); - $this->assertEquals( 'compliance', $this->formatChecker->checkConstraint( $statement3, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); - $this->assertEquals( 'compliance', $this->formatChecker->checkConstraint( $statement4, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement5, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement6, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement7, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement8, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement9, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement10, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement1, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement2, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement3, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement4, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement5, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement6, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement7, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement8, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement9, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement10, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); } public function testFormatConstraintTaxonName() { @@ -103,23 +103,23 @@ $statement9 = new Statement( new PropertyValueSnak( new PropertyId( 'P345' ), $value9 ) ); $statement10 = new Statement( new PropertyValueSnak( new PropertyId( 'P345' ), $value10 ) ); - $this->assertEquals( 'compliance', $this->formatChecker->checkConstraint( $statement1, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); - $this->assertEquals( 'compliance', $this->formatChecker->checkConstraint( $statement2, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); - $this->assertEquals( 'compliance', $this->formatChecker->checkConstraint( $statement3, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); - $this->assertEquals( 'compliance', $this->formatChecker->checkConstraint( $statement4, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement5, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement6, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement7, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement8, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement9, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement10, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement1, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement2, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement3, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement4, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement5, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement6, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement7, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement8, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement9, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement10, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); } public function testFormatConstraintEmptyPattern() { $pattern = null; $value = new StringValue( 'Populus × canescens' ); $statement = new Statement( new PropertyValueSnak( new PropertyId( 'P345' ), $value ) ); - $this->assertEquals( 'violation', $this->formatChecker->checkConstraint( $statement, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); + $this->assertEquals( 'todo', $this->formatChecker->checkConstraint( $statement, $this->getConstraintMock( array( 'pattern' => $pattern ) ) )->getStatus(), 'check should not comply' ); } public function testFormatConstraintNoStringValue() { diff --git a/tests/phpunit/ConstraintRepositoryTest.php b/tests/phpunit/ConstraintRepositoryTest.php index 046f9a8..276aaae 100755 --- a/tests/phpunit/ConstraintRepositoryTest.php +++ b/tests/phpunit/ConstraintRepositoryTest.php @@ -2,6 +2,7 @@ namespace WikibaseQuality\ConstraintReport\Tests; +use Wikibase\DataModel\Entity\PropertyId; use WikibaseQuality\ConstraintReport\Constraint; use WikibaseQuality\ConstraintReport\ConstraintRepository; @@ -43,8 +44,8 @@ $this->insertTestData(); $constraints = array( - new Constraint( 'foo', 42, 'TestConstraint', array( 'foo' => 'bar' ) ), - new Constraint( 'bar', 42, 'TestConstraint', array( 'bar' => 'baz' ) ) + new Constraint( 'foo', new PropertyId('P42'), 'TestConstraint', array( 'foo' => 'bar' ) ), + new Constraint( 'bar', new PropertyId('P42'), 'TestConstraint', array( 'bar' => 'baz' ) ) ); $repo = new ConstraintRepository(); $repo->insertBatch( $constraints ); diff --git a/tests/phpunit/ConstraintTest.php b/tests/phpunit/ConstraintTest.php index 09d1897..1e80dd6 100755 --- a/tests/phpunit/ConstraintTest.php +++ b/tests/phpunit/ConstraintTest.php @@ -2,6 +2,7 @@ namespace WikibaseQuality\ConstraintReport\Tests; +use Wikibase\DataModel\Entity\PropertyId; use WikibaseQuality\ConstraintReport\ConstraintRepository; @@ -22,7 +23,7 @@ $constraints = $repo->queryConstraintsForProperty( 1 ); $this->assertEquals( 'Item', $constraints[0]->getConstraintTypeQid() ); - $this->assertEquals( 1, $constraints[0]->getPropertyId() ); + $this->assertEquals( new PropertyId('P1'), $constraints[0]->getPropertyId() ); $this->assertEquals( '1', $constraints[0]->getConstraintClaimGuid() ); $constraintParameters = $constraints[0]->getConstraintParameters(); $this->assertEquals( 2, count( $constraintParameters ) ); diff --git a/tests/phpunit/Helper/ConstraintReportHelperTest.php b/tests/phpunit/Helper/ConstraintReportHelperTest.php index d5f7575..51d1726 100755 --- a/tests/phpunit/Helper/ConstraintReportHelperTest.php +++ b/tests/phpunit/Helper/ConstraintReportHelperTest.php @@ -59,12 +59,12 @@ public function testParseNullParameter() { $parameter = null; - $this->assertEquals( array ( 'null' ), $this->helper->parseSingleParameter( $parameter ) ); + $this->assertEquals( array ( 'none' ), $this->helper->parseSingleParameter( $parameter ) ); } public function testParseNullParameterArray() { $parameter = array ( '' ); - $this->assertEquals( array ( 'null' ), $this->helper->parseParameterArray( $parameter ) ); + $this->assertEquals( array ( 'none' ), $this->helper->parseParameterArray( $parameter ) ); } public function testParseParameterArray() { -- To view, visit https://gerrit.wikimedia.org/r/219164 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I27ad24f098608d5a877f9902f2f96ecb3c664476 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikidataQualityConstraints Gerrit-Branch: v1 Gerrit-Owner: Tamslo <tamaraslosa...@gmail.com> Gerrit-Reviewer: Jonaskeutel <jonas.keu...@student.hpi.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits