From 3bf72994688ad9292bf37444d80ab5ab1a002748 Mon Sep 17 00:00:00 2001 From: Paweł Sroka Date: Sun, 4 Nov 2012 08:25:28 +0100 Subject: Fixes #1479 - Replaces WP autop with implementation from Steve Clay. --- engine/tests/api/output.php | 64 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 engine/tests/api/output.php (limited to 'engine/tests/api') diff --git a/engine/tests/api/output.php b/engine/tests/api/output.php new file mode 100644 index 000000000..eb1a66b29 --- /dev/null +++ b/engine/tests/api/output.php @@ -0,0 +1,64 @@ + + */ +class ElggCoreOutputAutoPTest extends ElggCoreUnitTest { + + /** + * @var ElggAutop + */ + protected $_autop; + + public function setUp() { + $this->_autop = new ElggAutop(); + } + + public function testDomRoundtrip() + { + $d = dir(dirname(__DIR__) . '/test_files/output/autop'); + $in = file_get_contents($d->path . "/domdoc_in.html"); + $exp = file_get_contents($d->path . "/domdoc_exp.html"); + + $doc = new DOMDocument(); + libxml_use_internal_errors(true); + $doc->loadHTML("" + . $in . ''); + $serialized = $doc->saveHTML(); + list(,$out) = explode('', $serialized, 2); + list($out) = explode('', $out, 2); + + $this->assertEqual($exp, $out, "DOMDocument's parsing/serialization roundtrip"); + } + + public function testProcess() + { + $data = $this->provider(); + foreach ($data as $row) { + list($test, $in, $exp) = $row; + $out = $this->_autop->process($in); + $this->assertEqual($exp, $out, "Equality case {$test}"); + } + } + + public function provider() + { + $d = dir(dirname(__DIR__) . '/test_files/output/autop'); + $tests = array(); + while (false !== ($entry = $d->read())) { + if (preg_match('/^([a-z\\-]+)\.in\.html$/i', $entry, $m)) { + $tests[] = $m[1]; + } + } + + $data = array(); + foreach ($tests as $test) { + $data[] = array( + $test, + file_get_contents($d->path . '/' . "{$test}.in.html"), + file_get_contents($d->path . '/' . "{$test}.exp.html"), + ); + } + return $data; + } +} -- cgit v1.2.3