/**
  * @dataProvider provideConstruction
  *
  * @param EntityDiff $entityDiff
  * @param Diff $redirectDiff
  */
 public function testConstruction(EntityDiff $entityDiff, Diff $redirectDiff)
 {
     $diff = new EntityContentDiff($entityDiff, $redirectDiff);
     $this->assertArrayEquals($entityDiff->getOperations(), $diff->getEntityDiff()->getOperations());
     $this->assertEmpty(array_diff(array_keys($entityDiff->getOperations()), array_keys($diff->getEntityDiff()->getOperations())));
     $this->assertArrayEquals($redirectDiff->getOperations(), $diff->getRedirectDiff()->getOperations());
     $this->assertEmpty(array_diff(array_keys($redirectDiff->getOperations()), array_keys($diff->getRedirectDiff()->getOperations())));
 }
Esempio n. 2
0
 /**
  * @param Fingerprint $fingerprint
  * @param EntityDiff $patch
  *
  * @throws InvalidArgumentException
  */
 public function patchFingerprint(Fingerprint $fingerprint, EntityDiff $patch)
 {
     $labels = $this->patcher->patch($fingerprint->getLabels()->toTextArray(), $patch->getLabelsDiff());
     $fingerprint->setLabels($this->newTermListFromArray($labels));
     $descriptions = $this->patcher->patch($fingerprint->getDescriptions()->toTextArray(), $patch->getDescriptionsDiff());
     $fingerprint->setDescriptions($this->newTermListFromArray($descriptions));
     $this->patchAliases($fingerprint, $patch->getAliasesDiff());
 }
 /**
  * @param EntityDiff $entityDiff
  * @param Diff $redirectDiff
  */
 public function __construct(EntityDiff $entityDiff, Diff $redirectDiff)
 {
     $operations = array();
     $this->entityDiff = $entityDiff;
     $this->redirectDiff = $redirectDiff;
     $operations = array_merge($operations, $this->entityDiff->getOperations());
     $operations = array_merge($operations, $this->redirectDiff->getOperations());
     parent::__construct($operations, true);
 }
 /**
  * @param array $diffOp
  *
  * @return DiffOp
  * @throws InvalidArgumentException
  */
 public function newFromArray(array $diffOp)
 {
     $this->assertHasKey('type', $diffOp);
     // see EntityDiff::getType() and ItemDiff::getType()
     if (preg_match('!^diff/(.*)$!', $diffOp['type'], $matches)) {
         $itemType = $matches[1];
         $this->assertHasKey('operations', $diffOp);
         $operations = $this->createOperations($diffOp['operations']);
         $diff = EntityDiff::newForType($itemType, $operations);
         return $diff;
     }
     return parent::newFromArray($diffOp);
 }
 /**
  * Generates and returns an HTML visualization of the provided EntityDiff.
  *
  * @since 0.4
  *
  * @param EntityDiff $diff
  *
  * @return string
  */
 protected function visualizeEntityDiff(EntityDiff $diff)
 {
     if ($diff->isEmpty()) {
         return '';
     }
     $html = '';
     $termDiffVisualizer = new DiffView(array(), new Diff(array($this->context->getLanguage()->getMessage('wikibase-diffview-label') => $diff->getLabelsDiff(), $this->context->getLanguage()->getMessage('wikibase-diffview-alias') => $diff->getAliasesDiff(), $this->context->getLanguage()->getMessage('wikibase-diffview-description') => $diff->getDescriptionsDiff()), true), $this->siteStore, $this->entityIdFormatter, $this->context);
     $html .= $termDiffVisualizer->getHtml();
     foreach ($diff->getClaimsDiff() as $claimDiffOp) {
         $html .= $this->getClaimDiffHtml($claimDiffOp);
     }
     // FIXME: this does not belong here as it is specific to items
     if ($diff instanceof ItemDiff) {
         $linkDiffVisualizer = new DiffView(array(), new Diff(array($this->context->getLanguage()->getMessage('wikibase-diffview-link') => $diff->getSiteLinkDiff()), true), $this->siteStore, $this->entityIdFormatter, $this->context);
         $html .= $linkDiffVisualizer->getHtml();
     }
     return $html;
 }
Esempio n. 6
0
 /**
  * @see EntityDiff::isEmpty
  *
  * @return bool
  */
 public function isEmpty()
 {
     return parent::isEmpty() && $this->getSiteLinkDiff()->isEmpty();
 }
Esempio n. 7
0
 /**
  * @dataProvider diffProvider
  */
 public function testGetAliasesDiff(EntityDiff $entityDiff)
 {
     $diff = $entityDiff->getAliasesDiff();
     $this->assertInstanceOf('Diff\\Diff', $diff);
     $this->assertTrue($diff->isAssociative());
 }