/**
  * @group performance
  */
 public function testParagraphPerformance()
 {
     $fixturesPath = __DIR__ . '/../../../../fixtures/Performance/';
     $expected = file_get_contents($fixturesPath . 'paragraphs_expected.html');
     $diff = new HtmlDiff(file_get_contents($fixturesPath . 'paragraphs.html'), file_get_contents($fixturesPath . 'paragraphs_changed.html'), 'UTF-8', array());
     $output = $diff->build();
     $this->assertSame($this->stripExtraWhitespaceAndNewLines($output), $this->stripExtraWhitespaceAndNewLines($expected));
 }
 public function testHtmlDiffConfigTraditional()
 {
     $oldText = '<b>text</b>';
     $newText = '<b>t3xt</b>';
     $diff = new HtmlDiff(trim($oldText), trim($newText), 'UTF-8', array());
     $diff->getConfig()->setPurifierCacheLocation('/tmp');
     $diff->setHTMLPurifierConfig($this->config);
     $diff->build();
 }
Exemple #3
0
 public static function diff($old, $new)
 {
     $htmlDiff = new HtmlDiff($old, $new);
     return $htmlDiff->build();
 }
 /**
  * @dataProvider diffContentProvider
  *
  * @param $oldText
  * @param $newText
  * @param $expected
  */
 public function testHtmlDiff($oldText, $newText, $expected)
 {
     $diff = new HtmlDiff(trim($oldText), trim($newText), 'UTF-8', array());
     $output = $diff->build();
     static::assertEquals($this->stripExtraWhitespaceAndNewLines($expected), $this->stripExtraWhitespaceAndNewLines($output));
 }
Exemple #5
0
    if (!is_string($value)) {
        $value = var_export($value, true);
    }
    if (!array_key_exists($key, $debugOutput)) {
        $debugOutput[$key] = array();
    }
    $debugOutput[$key][] = $value;
}
$input = file_get_contents('php://input');
if ($input) {
    header('Content-Type: application/json');
    $data = json_decode($input, true);
    $oldText = $data['oldText'];
    $newText = $data['newText'];
    $useTableDiffing = isset($data['tableDiffing']) ? $data['tableDiffing'] : true;
    $diff = new HtmlDiff($oldText, $newText, 'UTF-8', array());
    if (array_key_exists('matchThreshold', $data)) {
        $diff->setMatchThreshold($data['matchThreshold']);
    }
    $diff->setUseTableDiffing($useTableDiffing);
    $diffOutput = $diff->build();
    $diffOutput = iconv('UTF-8', 'UTF-8//IGNORE', $diffOutput);
    $jsonOutput = json_encode(array('diff' => $diffOutput, 'debug' => $debugOutput));
    if (false === $jsonOutput) {
        throw new \Exception('Failed to encode JSON: ' . json_last_error_msg());
    }
    echo $jsonOutput;
} else {
    header('Content-Type: text/html');
    echo file_get_contents('demo.html');
}
Exemple #6
0
<?php

use Caxy\HtmlDiff\HtmlDiff;
require __DIR__ . '/../lib/Caxy/HtmlDiff/HtmlDiff.php';
require __DIR__ . '/../lib/Caxy/HtmlDiff/Match.php';
require __DIR__ . '/../lib/Caxy/HtmlDiff/Operation.php';
$input = file_get_contents('php://input');
if ($input) {
    $data = json_decode($input, true);
    $diff = new HtmlDiff($data['oldText'], $data['newText']);
    $diff->build();
    header('Content-Type: application/json');
    echo json_encode(array('diff' => $diff->getDifference()));
} else {
    header('Content-Type: text/html');
    echo file_get_contents('demo.html');
}