Tamslo has uploaded a new change for review.
https://gerrit.wikimedia.org/r/206761
Change subject: Removed Violations and ResultToViolationTranslator
......................................................................
Removed Violations and ResultToViolationTranslator
In order to publish the first version we remove everything that writes
into the violations table.
Change-Id: Ic10451fe8ac9959e0ba77e3ea16a8e2e13b0b2d0
---
D includes/Result/ResultToViolationTranslator.php
D includes/Violations/Violation.php
D includes/Violations/ViolationLookup.php
D includes/Violations/ViolationQuery.php
D includes/Violations/ViolationStore.php
D tests/phpunit/Violations/ViolationLookupTest.php
D tests/phpunit/Violations/ViolationQueryTest.php
D tests/phpunit/Violations/ViolationStoreTest.php
D tests/phpunit/Violations/ViolationTest.php
9 files changed, 0 insertions(+), 1,154 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataQuality
refs/changes/61/206761/1
diff --git a/includes/Result/ResultToViolationTranslator.php
b/includes/Result/ResultToViolationTranslator.php
deleted file mode 100644
index 0307aa3..0000000
--- a/includes/Result/ResultToViolationTranslator.php
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-
-namespace WikidataQuality\Result;
-
-use Wikibase\DataModel\Entity\EntityId;
-use Wikibase\Repo\WikibaseRepo;
-
-
-class ResultToViolationTranslator {
-
- private $revisionLookup;
-
- public function __construct() {
- $this->revisionLookup =
WikibaseRepo::getDefaultInstance()->getEntityRevisionLookup();
- }
-
- /**
- * @param EntityId $entityId
- *
- * @return int|false
- */
-
- protected function getRevisionIdForEntity( EntityId $entityId ) {
- return $this->revisionLookup->getLatestRevisionId( $entityId );
- }
-
-}
\ No newline at end of file
diff --git a/includes/Violations/Violation.php
b/includes/Violations/Violation.php
deleted file mode 100644
index 871f37a..0000000
--- a/includes/Violations/Violation.php
+++ /dev/null
@@ -1,218 +0,0 @@
-<?php
-
-namespace WikidataQuality\Violations;
-
-use Wikibase\DataModel\Entity\EntityId;
-use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\DataModel\Statement\Statement;
-use InvalidArgumentException;
-
-
-/**
- * Class Violation
- *
- * Holds data that will be inserted into the violation table
- *
- * @package WikidataQuality\Violation
- * @author BP2014N1
- * @license GNU GPL v2+
- */
-class Violation {
-
- const STATUS_VIOLATION = 'violation';
- const STATUS_EXCEPTION = 'exception';
- const STATUS_UNVERIFIED = 'unverified';
-
- /**
- * entity that contains the violation
- *
- * @var EntityId $entityId
- */
- private $entityId;
-
- /**
- * property of the claim that contains the violation
- *
- * @var PropertyId $pid
- */
- private $pid;
-
- /**
- * claim that contains the violation
- *
- * @var string $claimGuid
- */
- private $claimGuid;
-
- /**
- * constraint that is violated
- *
- * @var string $constraintClaimGuid
- */
- private $constraintClaimGuid;
-
- /**
- * type of the constraint that is violated
- *
- * @var EntityId $constraintTypeEntityId
- */
- private $constraintTypeEntityId;
-
- /**
- * additional information that is used when the violation is displayed
in the UI
- *
- * @var string $additionalInfo
- */
- private $additionalInfo;
-
- /**
- * wfTimestamp of last update in table
- *
- * @var string $updatedAt
- */
- private $updatedAt;
-
- /**
- * @var int $revisionId
- */
- private $revisionId;
-
- /**
- * status of the violation
- *
- * @var string $status
- */
- private $status;
-
- /**
- * @param EntityId $entityId
- * @param Statement|array $statement
- * @param string $constraintClaimGuid
- * @param EntityId $constraintTypeEntityId
- * @param $revisionId
- * @param string $status
- * @param string $additionalInfo
- */
- // TODO: Argument 4 --> EntityId as TypeHint
- public function __construct( EntityId $entityId, $statement,
$constraintClaimGuid, $constraintTypeEntityId, $revisionId, $status,
$additionalInfo = null, $updatedAt = null ) {
- $this->entityId = $entityId;
- if ( $statement instanceof Statement ) {
- $this->pid = $statement->getPropertyId();
- $this->claimGuid = $statement->getGuid();
- } else if ( is_array( $statement ) ) {
- if ( !( $statement[ 'pid' ] instanceof PropertyId ) ) {
- throw new InvalidArgumentException( 'pid must
be of type PropertyId' );
- }
- if ( !is_string( $statement[ 'claimGuid' ] ) ) {
- throw new InvalidArgumentException( 'claimGuid
must be of type string' );
- }
- $this->pid = $statement[ 'pid' ];
- $this->claimGuid = $statement[ 'claimGuid' ];
- } else {
- throw new InvalidArgumentException( 'Provide either a
statement or an array with keys "pid" and "claimGuid" as parameter for
$statement' );
- }
- if ( is_string( $constraintClaimGuid ) ) {
- $this->constraintClaimGuid = $constraintClaimGuid;
- } else {
- throw new InvalidArgumentException(
'$constraintClaimGuid must be of type string' );
- }
- $this->constraintTypeEntityId = $constraintTypeEntityId;
- if ( is_int( $revisionId ) ) {
- $this->revisionId = $revisionId;
- } else {
- throw new InvalidArgumentException( '$revisionId must
be of type int' );
- }
-
- if ( is_string( $status ) ) {
- $this->status = $status;
- } else {
- throw new InvalidArgumentException( '$status must be of
type string' );
- }
- if ( is_string( $additionalInfo ) ) {
- $this->additionalInfo = $additionalInfo;
- } else if ( is_null( $additionalInfo ) ) {
- $this->additionalInfo = $additionalInfo;
- } else {
- throw new InvalidArgumentException( '$additionalInfo
must be of type string' );
- }
- if ( $updatedAt ) {
- $this->setUpdatedAt( $updatedAt );
- }
- }
-
- /**
- * @param string $updatedAt
- */
- public function setUpdatedAt( $updatedAt ) {
- $timestamp = wfTimestamp( TS_MW, $updatedAt );
- if ( $timestamp ) {
- $this->updatedAt = $timestamp;
- } else {
- throw new InvalidArgumentException( 'Please provide a
proper timestamp format for wfTimestamp()' );
- }
-
- }
-
- /**
- * @return EntityId
- */
- public function getEntityId() {
- return $this->entityId;
- }
-
- /**
- * @return PropertyId
- */
- public function getPropertyId() {
- return $this->pid;
- }
-
- /**
- * @return string
- */
- public function getClaimGuid() {
- return $this->claimGuid;
- }
-
- /**
- * @return string
- */
- public function getConstraintClaimGuid() {
- return $this->constraintClaimGuid;
- }
-
- /**
- * @return EntityId
- */
- public function getConstraintTypeEntityId() {
- return $this->constraintTypeEntityId;
- }
-
- /**
- * @return string
- */
- public function getAdditionalInfo() {
- return $this->additionalInfo;
- }
-
- /**
- * @return string
- */
- public function getUpdatedAt() {
- return $this->updatedAt;
- }
-
- /**
- * @return int
- */
- public function getRevisionId() {
- return $this->revisionId;
- }
-
- /**
- * @return string
- */
- public function getStatus() {
- return $this->status;
- }
-}
\ No newline at end of file
diff --git a/includes/Violations/ViolationLookup.php
b/includes/Violations/ViolationLookup.php
deleted file mode 100644
index 72ff228..0000000
--- a/includes/Violations/ViolationLookup.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-
-namespace WikidataQuality\Violations;
-
-use Doctrine\Instantiator\Exception\InvalidArgumentException;
-use Wikibase\DataModel\Entity\ItemId;
-use Wikibase\DataModel\Entity\PropertyId;
-
-
-/**
- * Class ViolationLookup
- *
- * Receives an object of ViolationQuery, performs the query and returns an
object of type Violation
- *
- * @package WikidataQuality\ViolationLookup
- * @author BP2014N1
- * @license GNU GPL v2+
- */
-class ViolationLookup {
-
- private $db;
-
- /**
- * @param array $conditions
- *
- * @return array of Violations|null
- */
- public function getWhere( ViolationQuery $violationQuery ) {
- $this->getDBConnection();
- $queryResult = $this->db->select( VIOLATION_TABLE, '*',
$violationQuery->toArray() );
- return $this->queryResultToViolationObjects( $queryResult );
- }
-
- private function queryResultToViolationObjects( $queryResult ) {
-
- if ( $queryResult->numRows() === 0 ) {
- return null;
- }
-
- $violations = array ();
- foreach ( $queryResult as $result ) {
- $violation = new Violation(
- new ItemId( $result->entity_id ),
- array ( 'pid' => new PropertyId( $result->pid
), 'claimGuid' => $result->claim_guid ),
- $result->constraint_id,
- new ItemId( $result->constraint_type_entity_id
),
- (int) $result->revision_id,
- $result->status,
- $result->additional_info,
- $result->updated_at
- );
- $violations[ ] = $violation;
- }
-
- return $violations;
- }
-
- private function getDBConnection() {
- wfWaitForSlaves();
- $loadBalancer = wfGetLB();
- $this->db = $loadBalancer->getConnection( DB_MASTER );
- }
-}
\ No newline at end of file
diff --git a/includes/Violations/ViolationQuery.php
b/includes/Violations/ViolationQuery.php
deleted file mode 100644
index b0cb442..0000000
--- a/includes/Violations/ViolationQuery.php
+++ /dev/null
@@ -1,180 +0,0 @@
-<?php
-
-namespace WikidataQuality\Violations;
-
-use Doctrine\Instantiator\Exception\InvalidArgumentException;
-
-
-/**
- * Class ViolationQuery
- *
- * Receives values of queries as strings and converts them to
- * an array that can be used as $conds in methods like
- * DataBase::select( $table, $a, $conds )
- *
- * @package WikidataQuality\ViolationQuery
- * @author BP2014N1
- * @license GNU GPL v2+
- */
-class ViolationQuery {
-
- /**
- * Holds all conditions that were set
- *
- * @var array
- */
- private $conditions = array ();
-
- /**
- * Holds column names in VIOLATION_TABLE
- *
- * @var array
- */
- private $keys = array (
- 'entityId' => 'entity_id',
- 'propertyId' => 'pid',
- 'claimGuid' => 'claim_guid',
- 'constraintId' => 'constraint_id',
- 'constraintTypeEntityId' => 'constraint_type_entity_id',
- 'additionalInfo' => 'additional_info',
- 'updatedAt' => 'updated_at',
- 'revisionId' => 'revision_id',
- 'status' => 'status'
- );
-
- /**
- * Returns array that works with DataBase::select and similar methods
- *
- * @return array
- */
- public function toArray() {
- $conditionArray = array ();
- foreach ( $this->conditions as $condition ) {
- $conditionArray[ ] = $condition;
- }
- return $conditionArray;
- }
-
- /**
- * @param $entityId
- */
- public function setEntityId( $entityId ) {
- $this->testParamType( $entityId, __FUNCTION__ );
- $key = $this->keys[ 'entityId' ];
- $this->conditions[ $key ] = $key . '="' . $entityId . '"';
- }
-
- public function unsetEntityId() {
- unset( $this->conditions[ $this->keys[ 'entityId' ] ] );
- }
-
- /**
- * @param $propertyId
- */
- public function setPropertyId( $propertyId ) {
- $this->testParamType( $propertyId, __FUNCTION__ );
- $key = $this->keys[ 'propertyId' ];
- $this->conditions[ $key ] = $key . '="' . $propertyId . '"';
- }
-
- public function unsetPropertyId() {
- unset( $this->conditions[ $this->keys[ 'propertyId' ] ] );
- }
-
- /**
- * @param $claimGuid
- */
- public function setClaimGuid( $claimGuid ) {
- $this->testParamType( $claimGuid, __FUNCTION__ );
- $key = $this->keys[ 'claimGuid' ];
- $this->conditions[ $key ] = $key . '="' . $claimGuid . '"';
- }
-
- public function unsetClaimGuid() {
- unset( $this->conditions[ $this->keys[ 'claimGuid' ] ] );
- }
-
- /**
- * @param $constraintId
- */
- public function setConstraintClaimGuid( $constraintId ) {
- $this->testParamType( $constraintId, __FUNCTION__ );
- $key = $this->keys[ 'constraintId' ];
- $this->conditions[ $key ] = $key . '="' . $constraintId . '"';
- }
-
- public function unsetConstraintClaimGuid() {
- unset( $this->conditions[ $this->keys[ 'constraintId' ] ] );
- }
-
- /**
- * @param $constraintTypeEntityId
- */
- public function setConstraintTypeEntityId( $constraintTypeEntityId ) {
- $this->testParamType( $constraintTypeEntityId, __FUNCTION__ );
- $key = $this->keys[ 'constraintTypeEntityId' ];
- $this->conditions[ $key ] = $key . '="' .
$constraintTypeEntityId . '"';
- }
-
- public function unsetConstraintTypeEntityId() {
- unset( $this->conditions[ $this->keys[ 'constraintTypeEntityId'
] ] );
- }
-
- /**
- * @param $additionalInfo
- */
- public function setAdditionalInfo( $additionalInfo ) {
- $this->testParamType( $additionalInfo, __FUNCTION__ );
- $key = $this->keys[ 'additionalInfo' ];
- $this->conditions[ $key ] = $key . '="' . $additionalInfo . '"';
- }
-
- public function unsetAdditionalInfo() {
- unset( $this->conditions[ $this->keys[ 'additionalInfo' ] ] );
- }
-
- /**
- * @param $updatedAt
- */
- public function setUpdatedAt( $updatedAt ) {
- $this->testParamType( $updatedAt, __FUNCTION__ );
- $key = $this->keys[ 'updatedAt' ];
- $this->conditions[ $key ] = $key . '="' . $updatedAt . '"';
- }
-
- public function unsetUpdatedAt() {
- unset( $this->conditions[ $this->keys[ 'updatedAt' ] ] );
- }
-
- /**
- * @param $revisionId
- */
- public function setRevisionId( $revisionId ) {
- $this->testParamType( $revisionId, __FUNCTION__ );
- $key = $this->keys[ 'revisionId' ];
- $this->conditions[ $key ] = $key . '="' . $revisionId . '"';
- }
-
- public function unsetRevisionId() {
- unset( $this->conditions[ $this->keys[ 'revisionId' ] ] );
- }
-
- /**
- * @param $status
- */
- public function setStatus( $status ) {
- $this->testParamType( $status, __FUNCTION__ );
- $key = $this->keys[ 'status' ];
- $this->conditions[ $key ] = $key . '="' . $status . '"';
- }
-
- public function unsetStatus() {
- unset( $this->conditions[ $this->keys[ 'status' ] ] );
- }
-
- private function testParamType( $param, $function ) {
- if ( !is_string( $param ) ) {
- throw new InvalidArgumentException( "Input of $function
has to be of type string" );
- }
- }
-}
\ No newline at end of file
diff --git a/includes/Violations/ViolationStore.php
b/includes/Violations/ViolationStore.php
deleted file mode 100644
index a84d6c9..0000000
--- a/includes/Violations/ViolationStore.php
+++ /dev/null
@@ -1,139 +0,0 @@
-<?php
-
-namespace WikidataQuality\Violations;
-
-use Doctrine\Instantiator\Exception\InvalidArgumentException;
-use WikidataQuality\Violations\Violation;
-
-
-/**
- * Class ViolationStore
- *
- * Inserts, updates and deletes entries in the violation table
- *
- * @package WikidataQuality\ViolationStore
- * @author BP2014N1
- * @license GNU GPL v2+
- */
-class ViolationStore {
-
- private $db;
-
- /**
- * @param array|Violation $violations
- *
- * @throws \DBError
- */
- public function insertViolations( $violations ) {
- if ( $violations instanceof Violation ) {
- $violations = array ( $violations );
- }
- if ( !is_array( $violations ) ) {
- throw new InvalidArgumentException( '$violationa must
be instance of WikidataQuality\Violations\Violation or an array of those.' );
- }
- foreach ( $violations as $violation ) {
- if ( !( $violation instanceof Violation ) ) {
- throw new InvalidArgumentException( 'Objects in
$violations must be instance of WikidataQuality\Violations\Violation' );
- }
- }
-
- $this->getDBConnection();
-
- foreach ( $violations as $violation ) {
- $updatedAt = wfTimestamp( TS_MW );
- $accumulator = array (
- 'entity_id' =>
$violation->getEntityId()->getSerialization(),
- 'pid' =>
$violation->getPropertyId()->getSerialization(),
- 'claim_guid' => $violation->getClaimGuid(),
- 'constraint_id' =>
$violation->getConstraintClaimGuid(),
- 'constraint_type_entity_id' =>
$violation->getConstraintTypeEntityId(),
- //TODO: use this line: ->getSerialization(),
- 'additional_info' =>
$violation->getAdditionalInfo(),
- 'updated_at' => $updatedAt,
- 'revision_id' => $violation->getRevisionId(),
- 'status' => $violation->getStatus()
- );
-
- if ( !$this->violationExists( $violation ) ) {
- $this->insertNewViolation( $accumulator );
- } else {
- $this->updateViolation( $accumulator );
- }
- }
- }
-
- /**
- * @param \WikidataQuality\Violations\Violation $violation
- *
- * @return mixed
- * @throws \DBError
- */
- public function removeViolationWith( $claimGuid, $constraintClaimGuid )
{
-
- if ( !is_string( $claimGuid ) || !is_string(
$constraintClaimGuid ) ) {
- throw new InvalidArgumentException( 'Input of
ViolationStore::removeViolationWith() has to be string' );
- }
-
- $this->getDBConnection();
-
- $success = $this->db->delete( VIOLATION_TABLE, array (
- "claim_guid=\"$claimGuid\"",
- "constraint_id=\"$constraintClaimGuid\""
- ) );
-
- return $success;
- }
-
- /**
- * @throws \DBError
- * @throws \MWException
- */
- private function getDBConnection() {
- wfWaitForSlaves();
- $loadBalancer = wfGetLB();
- $this->db = $loadBalancer->getConnection( DB_MASTER );
- }
-
- /**
- * @param \WikidataQuality\Violations\Violation $violation
- *
- * @return bool
- */
- private function violationExists( Violation $violation ) {
- $claimGuid = $violation->getClaimGuid();
- $constraintClaimGuid = $violation->getConstraintClaimGuid();
- $existing = $this->db->selectRow( VIOLATION_TABLE,
-
array ( 'claim_guid', 'constraint_id' ),
-
array (
-
"claim_guid=\"$claimGuid\"",
-
"constraint_id=\"$constraintClaimGuid\""
-
) );
- return $existing ? true : false;
- }
-
- /**
- * @param array $accumulator
- *
- * @return mixed
- */
- private function insertNewViolation( array $accumulator ) {
- $success = $this->db->insert( VIOLATION_TABLE, $accumulator );
- return $success;
- }
-
- /**
- * @param array $accumulator
- *
- * @return mixed
- */
- private function updateViolation( array $accumulator ) {
- $claimGuid = $accumulator[ 'claim_guid' ];
- $constraintClaimGuid = $accumulator[ 'constraint_id' ];
- $success = $this->db->update(
- VIOLATION_TABLE,
- $accumulator,
- array ( "claim_guid=\"$claimGuid\"",
"constraint_id=\"$constraintClaimGuid\"" )
- );
- return $success;
- }
-}
\ No newline at end of file
diff --git a/tests/phpunit/Violations/ViolationLookupTest.php
b/tests/phpunit/Violations/ViolationLookupTest.php
deleted file mode 100644
index 8ac41da..0000000
--- a/tests/phpunit/Violations/ViolationLookupTest.php
+++ /dev/null
@@ -1,93 +0,0 @@
-<?php
-
-namespace WikidataQuality\Tests\Violation;
-
-use WikidataQuality\Violations\ViolationLookup;
-use WikidataQuality\Violations\ViolationQuery;
-
-
-/**
- * @covers WikidataQuality\Violations\ViolationLookup
- *
- * @uses WikidataQuality\Violations\Violation
- * @uses WikidataQuality\Violations\ViolationQuery
- *
- * @group database
- * @group medium
- *
- * @author BP2014N1
- * @license GNU GPL v2+
- */
-class ViolationLookupTest extends \MediaWikiTestCase {
-
- public function testGetOne() {
- $violationLookup = new ViolationLookup();
- $violationQuery = new ViolationQuery();
-
- $violationQuery->setClaimGuid( 'P13$1-2-3-4' );
- $violationQuery->setConstraintClaimGuid( 'P667$1-2-3-4' );
-
- $queryResult = $violationLookup->getWhere( $violationQuery );
- $this->assertEquals( 1, count( $queryResult ) );
- $this->assertEquals( 'second', $queryResult[ 0
]->getAdditionalInfo() );
- }
-
- public function testGetMultiple() {
- $violationLookup = new ViolationLookup();
- $violationQuery = new ViolationQuery();
-
- $violationQuery->setEntityId( 'Q42' );
-
- $queryResult = $violationLookup->getWhere( $violationQuery );
- $this->assertEquals( 3, count( $queryResult ) );
- }
-
- public function testGetNull() {
- $violationLookup = new ViolationLookup();
- $violationQuery = new ViolationQuery();
-
- $violationQuery->setStatus( 'exception' );
-
- $queryResult = $violationLookup->getWhere( $violationQuery );
- $this->assertNull( $queryResult );
- }
-
- public function addDBData() {
- $this->db->delete( VIOLATION_TABLE, '*' );
- $this->db->insert( VIOLATION_TABLE, array (
- array (
- 'entity_id' => 'Q42',
- 'pid' => 'P13',
- 'claim_guid' => 'P13$1-2-3-4',
- 'constraint_id' => 'P666$1-2-3-4',
- 'constraint_type_entity_id' => 'Q666',
- 'additional_info' => 'first',
- 'updated_at' => '20141015150000',
- 'revision_id' => 1234,
- 'status' => 'verified'
- ),
- array (
- 'entity_id' => 'Q42',
- 'pid' => 'P13',
- 'claim_guid' => 'P13$1-2-3-4',
- 'constraint_id' => 'P667$1-2-3-4',
- 'constraint_type_entity_id' => 'Q666',
- 'additional_info' => 'second',
- 'updated_at' => '20141015150000',
- 'revision_id' => 1234,
- 'status' => 'verified'
- ),
- array (
- 'entity_id' => 'Q42',
- 'pid' => 'P13',
- 'claim_guid' => 'P13$1-2-3-4',
- 'constraint_id' => 'P668$1-2-3-4',
- 'constraint_type_entity_id' => 'Q666',
- 'additional_info' => 'third',
- 'updated_at' => '20141015150000',
- 'revision_id' => 1234,
- 'status' => 'verified'
- )
- ) );
- }
-}
diff --git a/tests/phpunit/Violations/ViolationQueryTest.php
b/tests/phpunit/Violations/ViolationQueryTest.php
deleted file mode 100644
index 5e067cc..0000000
--- a/tests/phpunit/Violations/ViolationQueryTest.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-
-
-namespace WikidataQuality\Tests\Violation;
-
-use WikidataQuality\Violations\ViolationQuery;
-
-
-/**
- * @covers WikidataQuality\Violations\ViolationQuery
- *
- * @author BP2014N1
- * @license GNU GPL v2+
- */
-class ViolationQueryTest extends \MediaWikiTestCase {
-
- public function testSetters() {
- $queryCondition = new ViolationQuery();
-
- $queryCondition->setEntityId( 'value' );
- $conditionArray = $queryCondition->toArray();
- $this->assertEquals( 'entity_id="value"', $conditionArray[ 0 ],
"Test EntityIdSetter" );
-
- $queryCondition->setPropertyId( 'value' );
- $conditionArray = $queryCondition->toArray();
- $this->assertEquals( 'pid="value"', $conditionArray[ 1 ], "Test
PropertyIdSetter" );
-
- $queryCondition->setConstraintClaimGuid( 'value' );
- $conditionArray = $queryCondition->toArray();
- $this->assertEquals( 'constraint_id="value"', $conditionArray[
2 ], "Test ConstraintClaimGuidSetter" );
-
- $queryCondition->setConstraintTypeEntityId( 'value' );
- $conditionArray = $queryCondition->toArray();
- $this->assertEquals( 'constraint_type_entity_id="value"',
$conditionArray[ 3 ], "Test ConstraintTypeEntityIdSetter" );
-
- $queryCondition->setAdditionalInfo( 'value' );
- $conditionArray = $queryCondition->toArray();
- $this->assertEquals( 'additional_info="value"',
$conditionArray[ 4 ], "Test AdditionalInfoSetter" );
-
- $queryCondition->setUpdatedAt( 'value' );
- $conditionArray = $queryCondition->toArray();
- $this->assertEquals( 'updated_at="value"', $conditionArray[ 5
], "Test UpdatedAtSetter" );
-
- $queryCondition->setRevisionId( 'value' );
- $conditionArray = $queryCondition->toArray();
- $this->assertEquals( 'revision_id="value"', $conditionArray[ 6
], "Test RevisionIdSetter" );
-
- $queryCondition->setStatus( 'value' );
- $conditionArray = $queryCondition->toArray();
- $this->assertEquals( 'status="value"', $conditionArray[ 7 ],
"Test StatusSetter" );
- }
-
- public function testSettersWithInvalidArguments() {
- $queryCondition = new ViolationQuery();
-
- $this->setExpectedException( 'InvalidArgumentException' );
- $queryCondition->setEntityId( 1234 );
- }
-
- public function testUnsetters() {
- $queryCondition = new ViolationQuery();
- $queryCondition->setEntityId( 'value' );
- $queryCondition->setPropertyId( 'value' );
- $queryCondition->setClaimGuid( 'value' );
- $queryCondition->setConstraintClaimGuid( 'value' );
- $queryCondition->setConstraintTypeEntityId( 'value' );
- $queryCondition->setAdditionalInfo( 'value' );
- $queryCondition->setUpdatedAt( 'value' );
- $queryCondition->setRevisionId( 'value' );
- $queryCondition->setStatus( 'value' );
-
- $count = count( $queryCondition->toArray() );
-
- $queryCondition->unsetEntityId();
- $this->assertEquals( --$count, count(
$queryCondition->toArray() ), "Test EntityIdUnsetter" );
-
- $queryCondition->unsetPropertyId();
- $this->assertEquals( --$count, count(
$queryCondition->toArray() ), "Test PropertyIdUnsetter" );
-
- $queryCondition->unsetClaimGuid();
- $this->assertEquals( --$count, count(
$queryCondition->toArray() ), "Test ClaimGuidUnsetter" );
-
- $queryCondition->unsetConstraintClaimGuid();
- $this->assertEquals( --$count, count(
$queryCondition->toArray() ), "Test ConstraintClaimGuidUnsetter" );
-
- $queryCondition->unsetConstraintTypeEntityId();
- $this->assertEquals( --$count, count(
$queryCondition->toArray() ), "Test ConstraintTypeEntityIdUnsetter" );
-
- $queryCondition->unsetAdditionalInfo();
- $this->assertEquals( --$count, count(
$queryCondition->toArray() ), "Test AdditionalInfoUnsetter" );
-
- $queryCondition->unsetUpdatedAt();
- $this->assertEquals( --$count, count(
$queryCondition->toArray() ), "Test UpdatedAtUnsetter" );
-
- $queryCondition->unsetRevisionId();
- $this->assertEquals( --$count, count(
$queryCondition->toArray() ), "Test RevisionIdUnsetter" );
-
- $queryCondition->unsetStatus();
- $this->assertEquals( --$count, count(
$queryCondition->toArray() ), "Test StatusUnsetter" );
-
- $this->assertEquals( 0, $count );
- }
-}
diff --git a/tests/phpunit/Violations/ViolationStoreTest.php
b/tests/phpunit/Violations/ViolationStoreTest.php
deleted file mode 100644
index 8a5185c..0000000
--- a/tests/phpunit/Violations/ViolationStoreTest.php
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-
-namespace WikidataQuality\Tests\Violation;
-
-use DataValues\StringValue;
-use Wikibase\DataModel\Claim\Claim;
-use Wikibase\DataModel\Entity\ItemId;
-use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\DataModel\Snak\PropertyValueSnak;
-use Wikibase\DataModel\Statement\Statement;
-use WikidataQuality\Violations\Violation;
-use WikidataQuality\Violations\ViolationStore;
-
-
-/**
- * @covers WikidataQuality\Violations\ViolationStore
- *
- * @uses WikidataQuality\Violations\Violation
- *
- * @group database
- * @group medium
- *
- * @author BP2014N1
- * @license GNU GPL v2+
- */
-class ViolationStoreTest extends \MediaWikiTestCase {
-
- public function testRemoveViolation() {
- $violationStore = new ViolationStore();
-
- $actual = $this->db->selectRow( VIOLATION_TABLE, array (
- 'claim_guid',
- 'constraint_id'
- ), array ( 'claim_guid="P13$1-2-3-4"',
'constraint_id="P666$1-2-3-4"' ) );
- $this->assertNotNull( $actual );
-
- $violationStore->removeViolationWith( 'P13$1-2-3-4',
'P666$1-2-3-4' );
-
- $actual = $this->db->selectRow( VIOLATION_TABLE, array (
- 'claim_guid',
- 'constraint_id'
- ), array ( 'claim_guid="P13$1-2-3-4"',
'constraint_id="P666$1-2-3-4"' ) );
- $this->assertFalse( $actual );
- }
-
- public function testRemoveViolationWithInvalidArguments() {
- $violationStore = new ViolationStore();
-
- $this->setExpectedException( 'InvalidArgumentException' );
- $violationStore->removeViolationWith( '1234', 1234 );
- $violationStore->removeViolationWith( 1234, '1234' );
- }
-
- public function testInsertNewViolation() {
- $violationStore = new ViolationStore();
-
- $pid = new PropertyId( 'P13' );
- $claimGuid = 'P13$1-2-3-4';
- $snak = new PropertyValueSnak( $pid, new StringValue( 'abcd' )
);
- $claim = new Claim( $snak );
- $statement = new Statement( $claim );
- $statement->setGuid( $claimGuid );
- $violation = new Violation( new ItemId( 'Q42' ), $statement,
'P667$1-2-3-4', new ItemId( 'Q666' ), 1234, 'verified' );
-
- $anotherViolation = new Violation( new ItemId( 'Q42' ),
$statement, 'P668$1-2-3-4', new ItemId( 'Q666' ), 1234, 'verified',
'{additional:information}' );
-
- $count = $this->db->select( VIOLATION_TABLE, array (
- 'claim_guid',
- 'constraint_id'
- ), array ( 'claim_guid="P13$1-2-3-4"' ) )->numRows();
- $violationStore->insertViolations( array ( $violation,
$anotherViolation ) );
- $newCount = $this->db->select( VIOLATION_TABLE, array (
- 'claim_guid',
- 'constraint_id'
- ), array ( 'claim_guid="P13$1-2-3-4"' ) )->numRows();
- $this->assertEquals( $count + 2, $newCount );
- }
-
- public function testUpdateViolation() {
- $violationStore = new ViolationStore();
-
- $pid = new PropertyId( 'P13' );
- $claimGuid = 'P13$1-2-3-4';
- $snak = new PropertyValueSnak( $pid, new StringValue( 'abcd' )
);
- $claim = new Claim( $snak );
- $statement = new Statement( $claim );
- $statement->setGuid( $claimGuid );
- $violation = new Violation( new ItemId( 'Q42' ), $statement,
'P666$1-2-3-4', new ItemId( 'Q666' ), 1234, 'unverified' );
-
- $violationStore->insertViolations( $violation );
-
- $updated = $this->db->selectRow( VIOLATION_TABLE, array (
'status', 'updated_at' ), array (
- 'claim_guid="P13$1-2-3-4"',
- 'constraint_id="P666$1-2-3-4"'
- ) );
- $this->assertEquals( 'unverified', $updated->status );
- $this->assertNotEquals( '20141015150000', $updated->updated_at
);
- }
-
- public function testInsertViolationWithInvalidArguments() {
- $violationStore = new ViolationStore();
-
- $pid = new PropertyId( 'P13' );
- $claimGuid = 'P13$1-2-3-4';
- $snak = new PropertyValueSnak( $pid, new StringValue( 'abcd' )
);
- $claim = new Claim( $snak );
- $statement = new Statement( $claim );
- $statement->setGuid( $claimGuid );
- $violation = new Violation( new ItemId( 'Q42' ), $statement,
'P666$1-2-3-4', new ItemId( 'Q666' ), 1234, 'unverified' );
-
- $this->setExpectedException( 'InvalidArgumentException' );
- $violationStore->insertViolations( array ( $violation, 'abcd' )
);
- }
-
- public function addDBData() {
- $this->db->delete( VIOLATION_TABLE, '*' );
- $this->db->insert( VIOLATION_TABLE,
- array (
- 'entity_id' => 'Q42',
- 'pid' => 'P13',
- 'claim_guid' =>
'P13$1-2-3-4',
- 'constraint_id' =>
'P666$1-2-3-4',
-
'constraint_type_entity_id' => 'Q666',
- 'additional_info' =>
null,
- 'updated_at' =>
wfTimestamp( TS_MW, '2014-10-15T15:00:00Z' ),
- 'revision_id' =>
1234,
- 'status' => 'valid'
- )
- );
- }
-}
diff --git a/tests/phpunit/Violations/ViolationTest.php
b/tests/phpunit/Violations/ViolationTest.php
deleted file mode 100644
index 5660d9a..0000000
--- a/tests/phpunit/Violations/ViolationTest.php
+++ /dev/null
@@ -1,200 +0,0 @@
-<?php
-
-namespace WikidataQuality\Tests\Violation;
-
-use DataValues\StringValue;
-use Wikibase\DataModel\Claim\Claim;
-use Wikibase\DataModel\Entity\ItemId;
-use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\DataModel\Snak\PropertyValueSnak;
-use Wikibase\DataModel\Statement\Statement;
-use WikidataQuality\Violations\Violation;
-
-
-/**
- * @covers WikidataQuality\Violations\Violation
- *
- * @author BP2014N1
- * @license GNU GPL v2+
- */
-class ViolationTest extends \MediaWikiTestCase {
-
- /**
- * @dataProvider validArgumentsProvider
- */
- public function testConstructWithValidArguments( $entityId, $statement,
$constraintClaimGuid, $constraintTypeEntityId, $revisionId, $status,
$additionalInfo, $updatedAt ) {
- $violation = new Violation( $entityId, $statement,
$constraintClaimGuid, $constraintTypeEntityId, $revisionId, $status,
$additionalInfo, $updatedAt );
-
- $this->assertEquals( $entityId, $violation->getEntityId() );
- if ( $statement instanceof Statement ) {
- $this->assertEquals(
$statement->getPropertyId()->getSerialization(), $violation->getPropertyId() );
- $this->assertEquals( $statement->getGuid(),
$violation->getClaimGuid() );
- } else if ( is_array( $statement ) ) {
- $this->assertEquals( $statement[ 'pid' ],
$violation->getPropertyId() );
- $this->assertEquals( $statement[ 'claimGuid' ],
$violation->getClaimGuid() );
- }
- $this->assertEquals( $constraintClaimGuid,
$violation->getConstraintClaimGuid() );
- $this->assertEquals( $constraintTypeEntityId,
$violation->getConstraintTypeEntityId() );
- $this->assertEquals( $revisionId, $violation->getRevisionId() );
- $this->assertEquals( $status, $violation->getStatus() );
- $this->assertEquals( $additionalInfo,
$violation->getAdditionalInfo() );
- if ( $updatedAt ) {
- $this->assertEquals( wfTimestamp( TS_MW, $updatedAt ),
$violation->getUpdatedAt() );
- } else {
- $this->assertEquals( null, $violation->getUpdatedAt() );
- }
- }
-
- public function validArgumentsProvider() {
- $entityId = new ItemId( 'Q42' );
- $pid = new PropertyId( 'P1' );
- $claimGuid = 'P1$1-2-3-4';
- $snak = new PropertyValueSnak( $pid, new StringValue( 'abcd' )
);
- $claim = new Claim( $snak );
- $statement = new Statement( $claim );
- $statement->setGuid( $claimGuid );
- $constraintClaimGuid = 'P666$1-2-3-4';
- $constraintTypeEntityId = new ItemId( 'Q666' );
- $revisionId = 1234;
- $status = 'verified';
-
- return array (
- array (
- $entityId,
- $statement,
- $constraintClaimGuid,
- $constraintTypeEntityId,
- $revisionId,
- $status,
- '{"type":"JSON", "mandatory":false}',
- '2014-10-15T15:00:00Z'
- ),
- array (
- $entityId,
- $statement,
- $constraintClaimGuid,
- $constraintTypeEntityId,
- $revisionId,
- $status,
- null,
- null
- ),
- array (
- $entityId,
- array ( 'pid' => new PropertyId( 'P1' ),
'claimGuid' => $claimGuid ),
- $constraintClaimGuid,
- $constraintTypeEntityId,
- $revisionId,
- $status,
- null,
- null
- )
- );
- }
-
- /**
- * @dataProvider invalidArgumentsProvider
- */
- public function testConstructWithInvalidArguments( $entityId,
$statement, $constraintClaimGuid, $constraintTypeEntityId, $revisionId,
$status, $additionalInfo, $updatedAt ) {
- $this->setExpectedException( 'InvalidArgumentException' );
-
- new Violation( $entityId, $statement, $constraintClaimGuid,
$constraintTypeEntityId, $revisionId, $status, $additionalInfo, $updatedAt );
- }
-
- public function invalidArgumentsProvider() {
- $entityId = new ItemId( 'Q42' );
- $pid = new PropertyId( 'P1' );
- $claimGuid = 'P1$1-2-3-4';
- $snak = new PropertyValueSnak( $pid, new StringValue( 'abcd' )
);
- $claim = new Claim( $snak );
- $statement = new Statement( $claim );
- $statement->setGuid( $claimGuid );
- $constraintClaimGuid = 'P666$1-2-3-4';
- $constraintTypeEntityId = new ItemId( 'Q666' );
- $revisionId = 1234;
- $status = 'verified';
-
- return array (
- array (
- $entityId,
- 1234,
- $constraintClaimGuid,
- $constraintTypeEntityId,
- $revisionId,
- $status,
- null,
- null
- ),
- array (
- $entityId,
- array ( 'pid' => '1234', 'claimGuid' => '1234'
),
- $constraintClaimGuid,
- $constraintTypeEntityId,
- $revisionId,
- $status,
- null,
- null
- ),
- array (
- $entityId,
- array ( 'pid' => new PropertyId( 'P1234' ),
'claimGuid' => 1234 ),
- $constraintClaimGuid,
- $constraintTypeEntityId,
- $revisionId,
- $status,
- null,
- null
- ),
- array (
- $entityId,
- $statement,
- 1234,
- $constraintTypeEntityId,
- $revisionId,
- $status,
- null,
- null
- ),
- array (
- $entityId,
- $statement,
- $constraintClaimGuid,
- $constraintTypeEntityId,
- '1234',
- $status,
- null,
- null
- ),
- array (
- $entityId,
- $statement,
- $constraintClaimGuid,
- $constraintTypeEntityId,
- $revisionId,
- 1234,
- null,
- null
- ),
- array (
- $entityId,
- $statement,
- $constraintClaimGuid,
- $constraintTypeEntityId,
- $revisionId,
- $status,
- 1234,
- null
- ),
- array (
- $entityId,
- $statement,
- $constraintClaimGuid,
- $constraintTypeEntityId,
- $revisionId,
- $status,
- null,
- '2014-10-15'
- )
- );
- }
-}
--
To view, visit https://gerrit.wikimedia.org/r/206761
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic10451fe8ac9959e0ba77e3ea16a8e2e13b0b2d0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataQuality
Gerrit-Branch: v1
Gerrit-Owner: Tamslo <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits