function test_format() { $diff = new Diff(DIFF_SPACE); $one = 'a b c d e f g'; $two = 'a c d e t t f'; $res = $diff->compare($one, $two); $out = $diff->format($res); $expected = array(array('', 'a'), array('-', 'b'), array('', 'c'), array('', 'd'), array('', 'e'), array('+', 't'), array('+', 't'), array('', 'f'), array('-', 'g')); $this->assertEquals($out, $expected); }
/** * Returns a comparison of the two specified versions of the specified item * in the form of an associative array. * * @param string name of collection * @param string name of unique id column * @param mixed unique id of item * @param integer unique revision id of newer version * @param integer unique revision id of older version * @return array hash * */ function compare($collection, $key, $id, $rid1, $rid2, $diff_type = DIFF_HTML) { // returns diff as associative array $rev1 = $this->getRevision($collection, $key, $id, $rid1, true); if (!is_object($rev1)) { $this->error = 'Revision #' . $rid1 . ' does not exist.'; return false; } $rev2 = $this->getRevision($collection, $key, $id, $rid2, true); if (!is_object($rev2)) { $this->error = 'Revision #' . $rid2 . ' does not exists.'; return false; } $diff = new Diff(DIFF_HTML); $out = array(); foreach (array_keys(get_object_vars($rev1)) as $key) { $out[$key] = $diff->format($diff->compare($rev1->{$key}, $rev2->{$key})); } return $out; }