Tamslo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/210023

Change subject: Added column 'source' to violation table
......................................................................

Added column 'source' to violation table

Therefore adapted Violations, ViolationSerializer and Tests.

Change-Id: I1dac5b0024baec5f364490cf161832255eb27ad8
---
M includes/Serializer/ViolationSerializer.php
M includes/Violations/Violation.php
M includes/Violations/ViolationLookup.php
M includes/Violations/ViolationQuery.php
M includes/Violations/ViolationStore.php
M sql/create_wdqa_violations.sql
M tests/phpunit/Api/GetViolationsTest.php
M tests/phpunit/Serializer/ViolationSerializerTest.php
M tests/phpunit/Violations/ViolationLookupTest.php
M tests/phpunit/Violations/ViolationQueryTest.php
M tests/phpunit/Violations/ViolationStoreTest.php
M tests/phpunit/Violations/ViolationTest.php
12 files changed, 126 insertions(+), 36 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikidataQuality 
refs/changes/23/210023/1

diff --git a/includes/Serializer/ViolationSerializer.php 
b/includes/Serializer/ViolationSerializer.php
index 8d368bc..b501bac 100644
--- a/includes/Serializer/ViolationSerializer.php
+++ b/includes/Serializer/ViolationSerializer.php
@@ -47,6 +47,7 @@
                        'claimGuid' => $violation->getClaimGuid(),
                        'constraintId' => $violation->getConstraintId(),
                        // TODO: ->getSerialization (when it really is an 
EntityId and not just a string)
+                       'source' => $violation->getSource(),
                        'constraintTypeEntityId' => 
$violation->getConstraintTypeEntityId(),
                        'additionalInfo' => $violation->getAdditionalInfo(),
                        'updatedAt' => $violation->getUpdatedAt(),
diff --git a/includes/Violations/Violation.php 
b/includes/Violations/Violation.php
index 415299e..223a692 100644
--- a/includes/Violations/Violation.php
+++ b/includes/Violations/Violation.php
@@ -53,6 +53,13 @@
        private $constraintId;
 
        /**
+        * source the violation originates from (e.g. name of extension)
+        *
+        * @var string $source
+        */
+       private $source;
+
+       /**
         * type of the constraint that is violated
         *
         * @var EntityId $constraintTypeEntityId
@@ -90,17 +97,19 @@
         * @param PropertyId $propertyId
         * @param string $claimGuid
         * @param string $constraintId
+        * @param string $source
         * @param EntityId $constraintTypeEntityId
         * @param int $revisionId
         * @param string $status
         * @param string $additionalInfo
         */
        // TODO: Argument 4 --> EntityId as TypeHint
-       public function __construct( EntityId $entityId, PropertyId 
$propertyId, $claimGuid, $constraintId, $constraintTypeEntityId, $revisionId, 
$status, $additionalInfo = null, $updatedAt = null ) {
+       public function __construct( EntityId $entityId, PropertyId 
$propertyId, $claimGuid, $constraintId, $source, $constraintTypeEntityId, 
$revisionId, $status, $additionalInfo = null, $updatedAt = null ) {
                $this->entityId = $entityId;
                $this->propertyId = $propertyId;
                $this->setClaimGuid( $claimGuid );
                $this->setConstraintId( $constraintId );
+               $this->setSource( $source );
                $this->constraintTypeEntityId = $constraintTypeEntityId;
                $this->setRevisionId( $revisionId );
                $this->setStatus( $status );
@@ -130,6 +139,13 @@
                        throw new InvalidArgumentException( '$constraintId must 
be string.' );
                }
                $this->constraintId = $constraintId;
+       }
+
+       private function setSource( $source ) {
+               if ( !is_string( $source ) ) {
+                       throw new InvalidArgumentException( '$source must be 
string.' );
+               }
+               $this->source = $source;
        }
 
        /**
@@ -204,6 +220,13 @@
        }
 
        /**
+        * @return string
+        */
+       public function getSource() {
+               return $this->source;
+       }
+
+       /**
         * @return EntityId
         */
        public function getConstraintTypeEntityId() {
diff --git a/includes/Violations/ViolationLookup.php 
b/includes/Violations/ViolationLookup.php
index 283ce28..5993ce3 100644
--- a/includes/Violations/ViolationLookup.php
+++ b/includes/Violations/ViolationLookup.php
@@ -44,6 +44,7 @@
                                new PropertyId( $result->pid ),
                                $result->claim_guid,
                                $result->constraint_id,
+                               $result->source,
                                new ItemId( $result->constraint_type_entity_id 
),
                                (int)$result->revision_id,
                                $result->status,
diff --git a/includes/Violations/ViolationQuery.php 
b/includes/Violations/ViolationQuery.php
index c180b2c..b69c627 100644
--- a/includes/Violations/ViolationQuery.php
+++ b/includes/Violations/ViolationQuery.php
@@ -35,6 +35,7 @@
                'propertyId' => 'pid',
                'claimGuid' => 'claim_guid',
                'constraintId' => 'constraint_id',
+               'source' => 'source',
                'constraintTypeEntityId' => 'constraint_type_entity_id',
                'additionalInfo' => 'additional_info',
                'updatedAt' => 'updated_at',
@@ -108,6 +109,19 @@
        }
 
        /**
+        * @param $source
+        */
+       public function setSource( $source ) {
+               $this->testParamType( $source, __FUNCTION__ );
+               $key = $this->keys[ 'source' ];
+               $this->conditions[ $key ] = $key . '="' . $source . '"';
+       }
+
+       public function unsetSource() {
+               unset( $this->conditions[ $this->keys[ 'source' ] ] );
+       }
+
+       /**
         * @param $constraintTypeEntityId
         */
        public function setConstraintTypeEntityId( $constraintTypeEntityId ) {
diff --git a/includes/Violations/ViolationStore.php 
b/includes/Violations/ViolationStore.php
index 60d95bc..517e58c 100644
--- a/includes/Violations/ViolationStore.php
+++ b/includes/Violations/ViolationStore.php
@@ -32,6 +32,7 @@
                        'pid' => 
$violation->getPropertyId()->getSerialization(),
                        'claim_guid' => $violation->getClaimGuid(),
                        'constraint_id' => $violation->getConstraintId(),
+                       'source' => $violation->getSource(),
                        'constraint_type_entity_id' => 
$violation->getConstraintTypeEntityId(),
                        //TODO: use this line: ->getSerialization(),
                        'additional_info' => $violation->getAdditionalInfo(),
@@ -68,13 +69,15 @@
 
     /**
      * @param string $claimGuid
-     * @param string $constraintClaimGuid
+     * @param string $constraintId
+        * @param string $source
+        *
      * @return bool|\ResultWrapper
      * @throws \DBUnexpectedError
      */
-       public function removeViolationWith( $claimGuid, $constraintClaimGuid ) 
{
+       public function removeViolationWith( $claimGuid, $constraintId, $source 
) {
 
-               if ( !is_string( $claimGuid ) || !is_string( 
$constraintClaimGuid ) ) {
+               if ( !is_string( $claimGuid ) || !is_string( $constraintId ) || 
!is_string( $source ) ) {
                        throw new InvalidArgumentException( 'Input of 
ViolationStore::removeViolationWith() has to be string' );
                }
 
@@ -82,7 +85,8 @@
 
                $success = $db->delete( VIOLATION_TABLE, array(
                        "claim_guid=\"$claimGuid\"",
-                       "constraint_id=\"$constraintClaimGuid\""
+                       "constraint_id=\"$constraintId\"",
+                       "source=\"$source\""
                ) );
 
                return $success;
@@ -96,12 +100,14 @@
        private function violationExists( Violation $violation ) {
                $db = $this->getDBConnection();
                $claimGuid = $violation->getClaimGuid();
-               $constraintClaimGuid = $violation->getConstraintId();
+               $constraintId = $violation->getConstraintId();
+               $source = $violation->getSource();
                $existing = $db->selectRow( VIOLATION_TABLE,
-                                                                               
  array( 'claim_guid', 'constraint_id' ),
+                                                                               
  array( 'claim_guid', 'constraint_id', 'source' ),
                                                                                
  array(
                                                                                
          "claim_guid=\"$claimGuid\"",
-                                                                               
          "constraint_id=\"$constraintClaimGuid\""
+                                                                               
          "constraint_id=\"$constraintId\"",
+                                                                               
          "source=\"$source\""
                                                                                
  ) );
                $this->reuseDBConnection( $db );
                return $existing ? true : false;
@@ -127,11 +133,12 @@
        private function updateViolation( array $accumulator ) {
                $db = $this->getDBConnection();
                $claimGuid = $accumulator['claim_guid'];
-               $constraintClaimGuid = $accumulator['constraint_id'];
+               $constraintId = $accumulator['constraint_id'];
+               $source = $accumulator['source'];
                $success = $db->update(
                        VIOLATION_TABLE,
                        $accumulator,
-                       array( "claim_guid=\"$claimGuid\"", 
"constraint_id=\"$constraintClaimGuid\"" )
+                       array( "claim_guid=\"$claimGuid\"", 
"constraint_id=\"$constraintId\"", "source=\"$source\"" )
                );
                $this->reuseDBConnection( $db );
                return $success;
diff --git a/sql/create_wdqa_violations.sql b/sql/create_wdqa_violations.sql
index e5c29e7..232865a 100644
--- a/sql/create_wdqa_violations.sql
+++ b/sql/create_wdqa_violations.sql
@@ -3,13 +3,15 @@
   pid                           VARBINARY(15)     NOT NULL,
   claim_guid                    VARBINARY(63)     NOT NULL,
   constraint_id                 VARBINARY(63)     NOT NULL,
+  source                        VARBINARY(63)     NOT NULL,
   constraint_type_entity_id     VARBINARY(15)     NOT NULL,
   additional_info               TEXT              DEFAULT NULL,
   updated_at                    VARBINARY(31)     NOT NULL,
   revision_id                   INT(10) UNSIGNED  NOT NULL,
   status                        VARBINARY(31)     NOT NULL,
-  PRIMARY KEY (claim_guid, constraint_id)
+  PRIMARY KEY (claim_guid, constraint_id, source)
 ) /*$wgDBTableOptions*/;
 
 CREATE INDEX /*i*/claim_guid ON /*_*/wdqa_violations (claim_guid);
-CREATE INDEX /*i*/constraint_id ON /*_*/wdqa_violations (constraint_id);
\ No newline at end of file
+CREATE INDEX /*i*/constraint_id ON /*_*/wdqa_violations (constraint_id);
+CREATE INDEX /*i*/source ON /*_*/wdqa_violations (source);
\ No newline at end of file
diff --git a/tests/phpunit/Api/GetViolationsTest.php 
b/tests/phpunit/Api/GetViolationsTest.php
index 7995048..dc7c75f 100644
--- a/tests/phpunit/Api/GetViolationsTest.php
+++ b/tests/phpunit/Api/GetViolationsTest.php
@@ -110,6 +110,7 @@
                $this->assertEquals( 2, count( $result[0]['results'][ 
$claimGuidP1 ] ) );
                $this->assertEquals( 1, count( $result[0]['results'][ 
$claimGuidP2 ] ) );
 
-               $this->assertEquals( 9, count( $result[0]['results'][ 
$claimGuidP1 ][0] ) );
+               $violationFieldCount = 10;
+               $this->assertEquals( $violationFieldCount, count( 
$result[0]['results'][ $claimGuidP1 ][0] ) );
        }
 }
diff --git a/tests/phpunit/Serializer/ViolationSerializerTest.php 
b/tests/phpunit/Serializer/ViolationSerializerTest.php
index 7e13887..65000a6 100644
--- a/tests/phpunit/Serializer/ViolationSerializerTest.php
+++ b/tests/phpunit/Serializer/ViolationSerializerTest.php
@@ -41,6 +41,7 @@
                        new PropertyId( 'P1' ),
                        'P1$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
                        'Q666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
+                       'foobar',
                        new ItemId( 'Q666' ),
                        1234,
                        'exception',
@@ -54,6 +55,7 @@
                $this->assertEquals( 
$violation->getPropertyId()->getSerialization(), 
$serializedViolation['propertyId'] );
                $this->assertEquals( $violation->getClaimGuid(), 
$serializedViolation['claimGuid'] );
                $this->assertEquals( $violation->getConstraintId(), 
$serializedViolation['constraintId'] );
+               $this->assertEquals( $violation->getSource(), 
$serializedViolation['source'] );
                $this->assertEquals( $violation->getConstraintTypeEntityId(), 
$serializedViolation['constraintTypeEntityId'] );
                $this->assertEquals( $violation->getRevisionId(), 
$serializedViolation['revisionId'] );
                $this->assertEquals( $violation->getStatus(), 
$serializedViolation['status'] );
diff --git a/tests/phpunit/Violations/ViolationLookupTest.php 
b/tests/phpunit/Violations/ViolationLookupTest.php
index 04530e2..c198237 100644
--- a/tests/phpunit/Violations/ViolationLookupTest.php
+++ b/tests/phpunit/Violations/ViolationLookupTest.php
@@ -27,6 +27,7 @@
 
                $violationQuery->setClaimGuid( 
'P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' );
                $violationQuery->setConstraintId( 
'P667$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' );
+               $violationQuery->setSource( 'foobar' );
 
                $queryResult = $violationLookup->getWhere( $violationQuery );
                $this->assertEquals( 1, count( $queryResult ) );
@@ -61,6 +62,7 @@
                                'pid' => 'P13',
                                'claim_guid' => 
'P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
                                'constraint_id' => 
'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
+                               'source' => 'foobar',
                                'constraint_type_entity_id' => 'Q666',
                                'additional_info' => 'first',
                                'updated_at' => '20141015150000',
@@ -72,6 +74,7 @@
                                'pid' => 'P13',
                                'claim_guid' => 
'P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
                                'constraint_id' => 
'P667$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
+                               'source' => 'foobar',
                                'constraint_type_entity_id' => 'Q666',
                                'additional_info' => 'second',
                                'updated_at' => '20141015150000',
@@ -83,6 +86,7 @@
                                'pid' => 'P13',
                                'claim_guid' => 
'P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
                                'constraint_id' => 
'P668$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
+                               'source' => 'foobar',
                                'constraint_type_entity_id' => 'Q666',
                                'additional_info' => 'third',
                                'updated_at' => '20141015150000',
diff --git a/tests/phpunit/Violations/ViolationQueryTest.php 
b/tests/phpunit/Violations/ViolationQueryTest.php
index 790233f..ef6886e 100644
--- a/tests/phpunit/Violations/ViolationQueryTest.php
+++ b/tests/phpunit/Violations/ViolationQueryTest.php
@@ -29,27 +29,31 @@
 
                $queryCondition->setConstraintId( 'value' );
                $conditionArray = $queryCondition->toArray();
-               $this->assertEquals( 'constraint_id="value"', $conditionArray[ 
2 ], "Test ConstraintClaimGuidSetter" );
+               $this->assertEquals( 'constraint_id="value"', $conditionArray[ 
2 ], "Test ConstraintIdSetter" );
+
+               $queryCondition->setSource( 'value' );
+               $conditionArray = $queryCondition->toArray();
+               $this->assertEquals( 'source="value"', $conditionArray[ 3 ], 
"Test SourceSetter" );
 
                $queryCondition->setConstraintTypeEntityId( 'value' );
                $conditionArray = $queryCondition->toArray();
-               $this->assertEquals( 'constraint_type_entity_id="value"', 
$conditionArray[ 3 ], "Test ConstraintTypeEntityIdSetter" );
+               $this->assertEquals( 'constraint_type_entity_id="value"', 
$conditionArray[ 4 ], "Test ConstraintTypeEntityIdSetter" );
 
                $queryCondition->setAdditionalInfo( 'value' );
                $conditionArray = $queryCondition->toArray();
-               $this->assertEquals( 'additional_info="value"', 
$conditionArray[ 4 ], "Test AdditionalInfoSetter" );
+               $this->assertEquals( 'additional_info="value"', 
$conditionArray[ 5 ], "Test AdditionalInfoSetter" );
 
                $queryCondition->setUpdatedAt( 'value' );
                $conditionArray = $queryCondition->toArray();
-               $this->assertEquals( 'updated_at="value"', $conditionArray[ 5 
], "Test UpdatedAtSetter" );
+               $this->assertEquals( 'updated_at="value"', $conditionArray[ 6 
], "Test UpdatedAtSetter" );
 
                $queryCondition->setRevisionId( 'value' );
                $conditionArray = $queryCondition->toArray();
-               $this->assertEquals( 'revision_id="value"', $conditionArray[ 6 
], "Test RevisionIdSetter" );
+               $this->assertEquals( 'revision_id="value"', $conditionArray[ 7 
], "Test RevisionIdSetter" );
 
                $queryCondition->setStatus( 'value' );
                $conditionArray = $queryCondition->toArray();
-               $this->assertEquals( 'status="value"', $conditionArray[ 7 ], 
"Test StatusSetter" );
+               $this->assertEquals( 'status="value"', $conditionArray[ 8 ], 
"Test StatusSetter" );
        }
 
        public function testSettersWithInvalidArguments() {
@@ -64,6 +68,7 @@
                $queryCondition->setEntityId( 'value' );
                $queryCondition->setPropertyId( 'value' );
                $queryCondition->setClaimGuid( 'value' );
+               $queryCondition->setSource( 'value' );
                $queryCondition->setConstraintId( 'value' );
                $queryCondition->setConstraintTypeEntityId( 'value' );
                $queryCondition->setAdditionalInfo( 'value' );
@@ -83,7 +88,10 @@
                $this->assertEquals( --$count, count( 
$queryCondition->toArray() ), "Test ClaimGuidUnsetter" );
 
                $queryCondition->unsetConstraintId();
-               $this->assertEquals( --$count, count( 
$queryCondition->toArray() ), "Test ConstraintClaimGuidUnsetter" );
+               $this->assertEquals( --$count, count( 
$queryCondition->toArray() ), "Test ConstraintIdUnsetter" );
+
+               $queryCondition->unsetSource();
+               $this->assertEquals( --$count, count( 
$queryCondition->toArray() ), "Test SourceUnsetter" );
 
                $queryCondition->unsetConstraintTypeEntityId();
                $this->assertEquals( --$count, count( 
$queryCondition->toArray() ), "Test ConstraintTypeEntityIdUnsetter" );
diff --git a/tests/phpunit/Violations/ViolationStoreTest.php 
b/tests/phpunit/Violations/ViolationStoreTest.php
index 52271c9..ff73a5a 100644
--- a/tests/phpunit/Violations/ViolationStoreTest.php
+++ b/tests/phpunit/Violations/ViolationStoreTest.php
@@ -31,16 +31,17 @@
 
                $actual = $this->db->selectRow( VIOLATION_TABLE, array (
                        'claim_guid',
-                       'constraint_id'
-               ), array ( 
'claim_guid="P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"', 
'constraint_id="P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"' ) );
+                       'constraint_id',
+                       'source'
+               ), array ( 
'claim_guid="P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"', 
'constraint_id="P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"', 'source="foobar"' 
) );
                $this->assertNotNull( $actual );
 
-               $violationStore->removeViolationWith( 
'P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 
'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' );
+               $violationStore->removeViolationWith( 
'P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 
'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 'foobar' );
 
                $actual = $this->db->selectRow( VIOLATION_TABLE, array (
                        'claim_guid',
                        'constraint_id'
-               ), array ( 
'claim_guid="P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"', 
'constraint_id="P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"' ) );
+               ), array ( 
'claim_guid="P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"', 
'constraint_id="P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"', 'source="foobar"' 
) );
                $this->assertFalse( $actual );
        }
 
@@ -48,8 +49,9 @@
                $violationStore = new ViolationStore();
 
                $this->setExpectedException( 'InvalidArgumentException' );
-               $violationStore->removeViolationWith( '1234', 1234 );
-               $violationStore->removeViolationWith( 1234, '1234' );
+               $violationStore->removeViolationWith( '1234', '1234', 1234 );
+               $violationStore->removeViolationWith( '1234', 1234, '1234' );
+               $violationStore->removeViolationWith( 1234, '1234', '1234' );
        }
 
        public function testInsertNewViolation() {
@@ -57,9 +59,9 @@
 
                $pid = new PropertyId( 'P13' );
                $claimGuid = 'P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
-               $violation = new Violation( new ItemId( 'Q42' ), $pid, 
$claimGuid, 'P667$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', new ItemId( 'Q666' ), 
1234, 'verified' );
+               $violation = new Violation( new ItemId( 'Q42' ), $pid, 
$claimGuid, 'P667$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 'foobar' , new ItemId( 
'Q666' ), 1234, 'verified' );
 
-               $anotherViolation = new Violation( new ItemId( 'Q42' ), $pid, 
$claimGuid, 'P668$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', new ItemId( 'Q666' ), 
1234, 'verified', '{additional:information}' );
+               $anotherViolation = new Violation( new ItemId( 'Q42' ), $pid, 
$claimGuid, 'P668$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 'foobar', new ItemId( 
'Q666' ), 1234, 'verified', '{additional:information}' );
 
                $count = $this->db->select( VIOLATION_TABLE, array (
                        'claim_guid',
@@ -78,13 +80,14 @@
 
                $pid = new PropertyId( 'P13' );
                $claimGuid = 'P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
-               $violation = new Violation( new ItemId( 'Q42' ), $pid, 
$claimGuid, 'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', new ItemId( 'Q666' ), 
1234, 'unverified' );
+               $violation = new Violation( new ItemId( 'Q42' ), $pid, 
$claimGuid, 'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 'foobar', new ItemId( 
'Q666' ), 1234, 'unverified' );
 
                $violationStore->saveViolation( $violation );
 
                $updated = $this->db->selectRow( VIOLATION_TABLE, array ( 
'status', 'updated_at' ), array (
                        'claim_guid="P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"',
-                       
'constraint_id="P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"'
+                       
'constraint_id="P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"',
+                       'source="foobar"'
                ) );
                $this->assertEquals( 'unverified', $updated->status );
                $this->assertNotEquals( '20141015150000', $updated->updated_at 
);
@@ -95,7 +98,7 @@
 
                $pid = new PropertyId( 'P13' );
                $claimGuid = 'P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
-               $violation = new Violation( new ItemId( 'Q42' ),  $pid, 
$claimGuid, 'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', new ItemId( 'Q666' ), 
1234, 'unverified' );
+               $violation = new Violation( new ItemId( 'Q42' ),  $pid, 
$claimGuid, 'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 'foobar', new ItemId( 
'Q666' ), 1234, 'unverified' );
 
                $this->setExpectedException( 'InvalidArgumentException' );
                $violationStore->insertViolations( $violation );
@@ -106,7 +109,7 @@
 
                $pid = new PropertyId( 'P13' );
                $claimGuid = 'P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
-               $violation = new Violation( new ItemId( 'Q42' ),  $pid, 
$claimGuid, 'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', new ItemId( 'Q666' ), 
1234, 'unverified' );
+               $violation = new Violation( new ItemId( 'Q42' ),  $pid, 
$claimGuid, 'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee', 'foobar', new ItemId( 
'Q666' ), 1234, 'unverified' );
 
                $this->setExpectedException( 'InvalidArgumentException' );
                $violationStore->insertViolations( array ( $violation, 'abcd' ) 
);
@@ -120,6 +123,7 @@
                                                           'pid' => 'P13',
                                                           'claim_guid' => 
'P13$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
                                                           'constraint_id' => 
'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
+                                                          'source' => 'foobar',
                                                           
'constraint_type_entity_id' => 'Q666',
                                                           'additional_info' => 
null,
                                                           'updated_at' => 
wfTimestamp( TS_MW, '2014-10-15T15:00:00Z' ),
diff --git a/tests/phpunit/Violations/ViolationTest.php 
b/tests/phpunit/Violations/ViolationTest.php
index 88b6d04..2330936 100644
--- a/tests/phpunit/Violations/ViolationTest.php
+++ b/tests/phpunit/Violations/ViolationTest.php
@@ -24,13 +24,14 @@
        /**
         * @dataProvider validArgumentsProvider
         */
-       public function testConstructWithValidArguments( $entityId, $pid, 
$claimGuid, $constraintId, $constraintTypeEntityId, $revisionId, $status, 
$additionalInfo, $updatedAt ) {
-               $violation = new Violation( $entityId, $pid, $claimGuid, 
$constraintId, $constraintTypeEntityId, $revisionId, $status, $additionalInfo, 
$updatedAt );
+       public function testConstructWithValidArguments( $entityId, $pid, 
$claimGuid, $constraintId, $source, $constraintTypeEntityId, $revisionId, 
$status, $additionalInfo, $updatedAt ) {
+               $violation = new Violation( $entityId, $pid, $claimGuid, 
$constraintId, $source, $constraintTypeEntityId, $revisionId, $status, 
$additionalInfo, $updatedAt );
 
                $this->assertEquals( $entityId, $violation->getEntityId() );
                $this->assertEquals( $pid, $violation->getPropertyId() );
                $this->assertEquals( $claimGuid, $violation->getClaimGuid() );
                $this->assertEquals( $constraintId, 
$violation->getConstraintId() );
+               $this->assertEquals( $source, $violation->getSource() );
                $this->assertEquals( $constraintTypeEntityId, 
$violation->getConstraintTypeEntityId() );
                $this->assertEquals( $revisionId, $violation->getRevisionId() );
                $this->assertEquals( $status, $violation->getStatus() );
@@ -47,6 +48,7 @@
                $pid = new PropertyId( 'P1' );
                $claimGuid = 'P1$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
                $constraintId = 'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
+               $source = 'Constraints';
                $constraintTypeEntityId = new ItemId( 'Q666' );
                $revisionId = 1234;
                $status = 'verified';
@@ -57,6 +59,7 @@
                                $pid,
                                $claimGuid,
                                $constraintId,
+                               $source,
                                $constraintTypeEntityId,
                                $revisionId,
                                $status,
@@ -68,6 +71,7 @@
                                $pid,
                                $claimGuid,
                                $constraintId,
+                               $source,
                                $constraintTypeEntityId,
                                $revisionId,
                                $status,
@@ -80,10 +84,10 @@
        /**
         * @dataProvider invalidArgumentsProvider
         */
-       public function testConstructWithInvalidArguments( $entityId, $pid, 
$claimGuid, $constraintId, $constraintTypeEntityId, $revisionId, $status, 
$additionalInfo, $updatedAt ) {
+       public function testConstructWithInvalidArguments( $entityId, $pid, 
$claimGuid, $constraintId, $source, $constraintTypeEntityId, $revisionId, 
$status, $additionalInfo, $updatedAt ) {
                $this->setExpectedException( 'InvalidArgumentException' );
 
-               new Violation( $entityId, $pid, $claimGuid, $constraintId, 
$constraintTypeEntityId, $revisionId, $status, $additionalInfo, $updatedAt );
+               new Violation( $entityId, $pid, $claimGuid, $constraintId, 
$source, $constraintTypeEntityId, $revisionId, $status, $additionalInfo, 
$updatedAt );
        }
 
        public function invalidArgumentsProvider() {
@@ -91,6 +95,7 @@
                $pid = new PropertyId( 'P1' );
                $claimGuid = 'P1$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
                $constraintId = 'P666$aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
+               $source = 'External Validation';
                $constraintTypeEntityId = new ItemId( 'Q666' );
                $revisionId = 1234;
                $status = 'verified';
@@ -101,6 +106,7 @@
                                $pid,
                                1234,
                                $constraintId,
+                               $source,
                                $constraintTypeEntityId,
                                $revisionId,
                                $status,
@@ -111,6 +117,19 @@
                                $entityId,
                                $pid,
                                $claimGuid,
+                               1234,
+                               $source,
+                               $constraintTypeEntityId,
+                               $revisionId,
+                               $status,
+                               null,
+                               null
+                       ),
+                       array (
+                               $entityId,
+                               $pid,
+                               $claimGuid,
+                               $constraintId,
                                1234,
                                $constraintTypeEntityId,
                                $revisionId,
@@ -123,6 +142,7 @@
                                $pid,
                                $claimGuid,
                                $constraintId,
+                               $source,
                                $constraintTypeEntityId,
                                '1234',
                                $status,
@@ -134,6 +154,7 @@
                                $pid,
                                $claimGuid,
                                $constraintId,
+                               $source,
                                $constraintTypeEntityId,
                                $revisionId,
                                1234,
@@ -145,6 +166,7 @@
                                $pid,
                                $claimGuid,
                                $constraintId,
+                               $source,
                                $constraintTypeEntityId,
                                $revisionId,
                                $status,
@@ -156,6 +178,7 @@
                                $pid,
                                $claimGuid,
                                $constraintId,
+                               $source,
                                $constraintTypeEntityId,
                                $revisionId,
                                $status,

-- 
To view, visit https://gerrit.wikimedia.org/r/210023
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1dac5b0024baec5f364490cf161832255eb27ad8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikidataQuality
Gerrit-Branch: master
Gerrit-Owner: Tamslo <tamaraslosa...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to