/** * @param Diff $changes * @param Snak $oldestMainSnak The old main snak, if present; otherwise, the new main snak * @param Snak $newestMainSnak The new main snak, if present; otherwise, the old main snak * * @return string HTML */ private function visualizeQualifierChanges(Diff $changes, Snak $oldestMainSnak, Snak $newestMainSnak) { $html = ''; $msg = wfMessage('wikibase-diffview-qualifier')->inLanguage($this->languageCode); $header = $msg->parse(); $oldClaimHeader = $this->snakVisualizer->getPropertyAndValueHeader($oldestMainSnak) . ' / ' . $header; $newClaimHeader = $this->snakVisualizer->getPropertyAndValueHeader($newestMainSnak) . ' / ' . $header; foreach ($changes as $change) { $oldValue = null; $newValue = null; if ($change instanceof DiffOpAdd) { $newValue = $change->getNewValue(); } elseif ($change instanceof DiffOpChange) { $oldValue = $change->getOldValue(); $newValue = $change->getNewValue(); } elseif ($change instanceof DiffOpRemove) { $oldValue = $change->getOldValue(); } $oldValueHtml = $oldValue !== null ? $this->snakVisualizer->getPropertyAndDetailedValue($oldValue) : null; $newValueHtml = $newValue !== null ? $this->snakVisualizer->getPropertyAndDetailedValue($newValue) : null; $valueFormatter = new DiffOpValueFormatter($oldClaimHeader, $newClaimHeader, $oldValueHtml, $newValueHtml); $html .= $valueFormatter->generateHtml(); } return $html; }
/** * @dataProvider provideGenerateHtml */ public function testGenerateHtml($name, $oldValues, $newValues, $pattern) { $formatter = new DiffOpValueFormatter($name, $name, $oldValues, $newValues); $html = $formatter->generateHtml(); $this->assertRegExp($pattern, $html); }