/**
  * @dataProvider diffClaimsProvider
  */
 public function testDiffClaims(Statement $oldStatement = null, Statement $newStatement = null, ClaimDifference $expected)
 {
     $differ = new ClaimDiffer(new OrderedListDiffer(new ComparableComparer()));
     $actual = $differ->diffClaims($oldStatement, $newStatement);
     $this->assertTrue($expected->equals($actual));
     // Additional fail-safe checks to guard against an ArrayObject bug in PHP 5.3, that returned
     // true when using == to compare two ArrayObject instances with differing content.
     $this->assertEquals($expected->getQualifierChanges()->getArrayCopy(), $actual->getQualifierChanges()->getArrayCopy());
     $this->assertEquals($expected->getReferenceChanges()->getArrayCopy(), $actual->getReferenceChanges()->getArrayCopy());
 }
 /**
  * Returns the HTML for a single claim DiffOp.
  *
  * @since 0.4
  *
  * @param DiffOp $claimDiffOp
  *
  * @return string
  * @throws MWException
  */
 protected function getClaimDiffHtml(DiffOp $claimDiffOp)
 {
     if ($claimDiffOp instanceof DiffOpChange) {
         $claimDifference = $this->claimDiffer->diffClaims($claimDiffOp->getOldValue(), $claimDiffOp->getNewValue());
         return $this->claimDiffVisualizer->visualizeClaimChange($claimDifference, $claimDiffOp->getNewValue());
     }
     if ($claimDiffOp instanceof DiffOpAdd) {
         return $this->claimDiffVisualizer->visualizeNewClaim($claimDiffOp->getNewValue());
     } elseif ($claimDiffOp instanceof DiffOpRemove) {
         return $this->claimDiffVisualizer->visualizeRemovedClaim($claimDiffOp->getOldValue());
     } else {
         throw new MWException('Encountered an unexpected diff operation type for a claim');
     }
 }
 /**
  * Checks what has actually changed inside a statement by looking at a ClaimDifference,
  * constructs an edit-summary based upon that information and returns
  * a Summary object holding this edit-summary
  *
  * @param Statement|null $oldStatement
  * @param Statement $newStatement
  *
  * @return Summary
  */
 public function buildClaimSummary(Statement $oldStatement = null, Statement $newStatement)
 {
     $guid = $newStatement->getGuid();
     $summary = new Summary($this->apiModuleName);
     // Only one statement touched, so we're always having singular here.
     $summary->addAutoCommentArgs(1);
     $summaryArgs = $this->buildSummaryArgs($newStatement, $guid);
     $summary->addAutoSummaryArgs($summaryArgs);
     if ($oldStatement !== null) {
         //claim is changed
         $claimDifference = $this->claimDiffer->diffClaims($oldStatement, $newStatement);
         if ($claimDifference->isAtomic()) {
             if ($claimDifference->getMainSnakChange() !== null) {
                 $summary->setAction('update');
             } elseif ($claimDifference->getQualifierChanges()->isEmpty() === false) {
                 $summary->addAutoCommentArgs($claimDifference->getQualifierChanges()->count());
                 $summary->setAction('update-qualifiers');
             } elseif ($claimDifference->getReferenceChanges()->isEmpty() === false) {
                 $summary->addAutoCommentArgs($claimDifference->getReferenceChanges()->count());
                 $summary->setAction('update-references');
             } elseif ($claimDifference->getRankChange() !== null) {
                 $summary->setAction('update-rank');
             } else {
                 // something "else" has changed inside the claim, so falling back to plain update message
                 $summary->setAction('update');
             }
         } else {
             // TODO: decide what to do if changes affect multiple part of the claim
             // e.g. concat several autocomments into one?
             $summary->setAction('update');
         }
     } else {
         //new claim is added
         $summary->setAction('create');
     }
     return $summary;
 }
 /**
  * Get diff html for a removed claim
  *
  * @since 0.4
  *
  * @param Statement $statement
  *
  * @return string HTML
  */
 public function visualizeRemovedClaim(Statement $statement)
 {
     $claimDiffer = new ClaimDiffer(new ListDiffer());
     $claimDifference = $claimDiffer->diffClaims($statement, null);
     return $this->visualizeClaimChange($claimDifference, $statement);
 }