예제 #1
0
 public function assign(DiffOp $diff)
 {
     $data = $diff->toArray();
     $this->oldValue = @$data['oldvalue'];
     $this->newValue = @$data['newvalue'];
     return $this;
 }
예제 #2
0
 /**
  * @dataProvider diffOpProvider
  *
  * @param DiffOp $diffOp
  */
 public function testNewFromArrayWithConversion(DiffOp $diffOp)
 {
     $unserializationFunction = function ($array) {
         if (is_array($array) && isset($array['type']) && $array['type'] === 'Change') {
             return new DiffOpChange($array['teh_old'], $array['teh_new']);
         }
         return $array;
     };
     $factory = new DiffOpFactory($unserializationFunction);
     $serializationFunction = function ($obj) {
         if ($obj instanceof DiffOpChange) {
             return array('type' => 'Change', 'teh_old' => $obj->getOldValue(), 'teh_new' => $obj->getNewValue());
         }
         return $obj;
     };
     // try with conversion callback
     $array = $diffOp->toArray($serializationFunction);
     $newInstance = $factory->newFromArray($array);
     // If an equality method is implemented in DiffOp, it should be used here
     $this->assertEquals($diffOp, $newInstance);
     $this->assertEquals($diffOp->getType(), $newInstance->getType());
 }
 /**
  * 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');
     }
 }
예제 #4
0
 /**
  * Does the actual work.
  *
  * @param string[] $path
  * @param DiffOp $op
  *
  * @return string
  * @throws MWException
  */
 private function generateOpHtml(array $path, DiffOp $op)
 {
     if ($op->isAtomic()) {
         $html = $this->generateDiffHeaderHtml(implode(' / ', $path));
         //TODO: no path, but localized section title
         //FIXME: complex objects as values?
         if ($op->getType() === 'add') {
             /** @var DiffOpAdd $op */
             $html .= $this->generateChangeOpHtml(null, $op->getNewValue(), $path);
         } elseif ($op->getType() === 'remove') {
             /** @var DiffOpRemove $op */
             $html .= $this->generateChangeOpHtml($op->getOldValue(), null, $path);
         } elseif ($op->getType() === 'change') {
             /** @var DiffOpChange $op */
             $html .= $this->generateChangeOpHtml($op->getOldValue(), $op->getNewValue(), $path);
         } else {
             throw new MWException('Invalid diffOp type');
         }
     } else {
         $html = '';
         foreach ($op as $key => $subOp) {
             $html .= $this->generateOpHtml(array_merge($path, array($key)), $subOp);
         }
     }
     return $html;
 }
 /**
  * @param DiffOp $diffOp
  * @param string $action e.g. 'remove', see the constants in EntityChange
  * @param string $siteId
  * @param Title|null $title The page we create an edit summary for
  *
  * @return array|null
  */
 private function getSiteLinkAddRemoveParams(DiffOp $diffOp, $action, $siteId, Title $title = null)
 {
     $params = array();
     if (in_array($action, array('remove', 'restore'))) {
         // Messages: wikibase-comment-remove, wikibase-comment-restore
         $params['message'] = 'wikibase-comment-' . $action;
     } elseif ($diffOp instanceof DiffOpAdd) {
         $params['message'] = 'wikibase-comment-linked';
     } elseif ($diffOp instanceof DiffOpRemove) {
         $params['message'] = 'wikibase-comment-unlink';
     } elseif ($diffOp instanceof DiffOpChange) {
         if ($title && $title->getPrefixedText() === $diffOp->getOldValue()) {
             $params['message'] = 'wikibase-comment-unlink';
         } elseif ($title && $title->getPrefixedText() === $diffOp->getNewValue()) {
             $params['message'] = 'wikibase-comment-linked';
         } else {
             $params['message'] = 'wikibase-comment-sitelink-change';
             $params['sitelink'] = array('oldlink' => array('site' => $siteId, 'page' => $diffOp->getOldValue()), 'newlink' => array('site' => $siteId, 'page' => $diffOp->getNewValue()));
         }
     } else {
         // whatever
         $params = null;
     }
     return $params;
 }
예제 #6
0
 /**
  * @dataProvider instanceProvider
  */
 public function testToArrayWithConversion(DiffOp $diffOp)
 {
     $array = $diffOp->toArray(function ($diffOp) {
         return array('Nyan!');
     });
     $this->assertInternalType('array', $array);
 }
예제 #7
0
 /**
  * Gets called before a new element is added to the ArrayObject.
  *
  * At this point the index is always set (ie not null) and the
  * value is always of the type returned by @see getObjectType.
  *
  * Should return a boolean. When false is returned the element
  * does not get added to the ArrayObject.
  *
  * @param int|string $index
  * @param DiffOp $value
  *
  * @return bool
  * @throws InvalidArgumentException
  */
 private function preSetElement($index, DiffOp $value)
 {
     if ($this->isAssociative === false && ($value->getType() !== 'add' && $value->getType() !== 'remove')) {
         throw new InvalidArgumentException('Diff operation with invalid type "' . $value->getType() . '" provided.');
     }
     if (array_key_exists($value->getType(), $this->typePointers)) {
         $this->typePointers[$value->getType()][] = $index;
     } else {
         throw new InvalidArgumentException('Diff operation with invalid type "' . $value->getType() . '" provided.');
     }
     return true;
 }