/** * Generates and returns an HTML visualization of the provided EntityContentDiff. * * @since 0.5 * * @param EntityContentDiff $diff * * @return string */ public function visualizeEntityContentDiff(EntityContentDiff $diff) { $html = ''; $html .= $this->visualizeRedirectDiff($diff->getRedirectDiff()); $html .= $this->visualizeEntityDiff($diff->getEntityDiff()); return $html; }
/** * @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()))); }
/** * @dataProvider diffProvider * * @param EntityContent $a * @param EntityContent $b * @param EntityContentDiff $expected */ public function testGetDiff(EntityContent $a, EntityContent $b, EntityContentDiff $expected) { $actual = $a->getDiff($b); $this->assertInstanceOf('Wikibase\\Repo\\Content\\EntityContentDiff', $actual); $expectedEntityOps = $expected->getEntityDiff()->getOperations(); $actualEntityOps = $actual->getEntityDiff()->getOperations(); // HACK: ItemDiff always sets this, even if it's empty. Ignore. if (isset($actualEntityOps['claim']) && $actualEntityOps['claim']->isEmpty()) { unset($actualEntityOps['claim']); } $this->assertArrayEquals($expectedEntityOps, $actualEntityOps, false, true); $expectedRedirectOps = $expected->getRedirectDiff()->getOperations(); $actualRedirectOps = $actual->getRedirectDiff()->getOperations(); $this->assertArrayEquals($expectedRedirectOps, $actualRedirectOps, false, true); }
/** * Returns a patched copy of this Content object. * * @param EntityContentDiff $patch * * @throws PatcherException * @return EntityContent */ public function getPatchedCopy(EntityContentDiff $patch) { /* @var EntityHandler $handler */ $handler = $this->getContentHandler(); if ($this->isRedirect()) { $entityAfterPatch = $this->makeEmptyEntity(); } else { $entityAfterPatch = unserialize(serialize($this->getEntity())); } // FIXME: this should either be done in the derivatives, or the patcher // should be injected, so the application can add support for additional entity types. $patcher = new EntityPatcher(); $patcher->patchEntity($entityAfterPatch, $patch->getEntityDiff()); $redirAfterPatch = $this->getPatchedRedirect($patch->getRedirectDiff()); if ($redirAfterPatch !== null && !$entityAfterPatch->isEmpty()) { throw new PatcherException('EntityContent must not contain Entity data as well as' . ' a redirect after applying the patch!'); } elseif ($redirAfterPatch) { $patched = $handler->makeEntityRedirectContent($redirAfterPatch); if (!$patched) { throw new PatcherException('Cannot create a redirect using content model ' . $this->getModel() . '!'); } } else { $patched = $handler->makeEntityContent(new EntityInstanceHolder($entityAfterPatch)); } return $patched; }