diff options
author | Brett Profitt <brett.profitt@gmail.com> | 2012-12-10 15:50:25 -0500 |
---|---|---|
committer | Brett Profitt <brett.profitt@gmail.com> | 2012-12-10 15:50:25 -0500 |
commit | 43a395ae735777bfb5474c4f6a37dc1cd0818a37 (patch) | |
tree | 6c156136680474a61cf162d8ef3aceef12cfc7dd /engine/tests/api | |
parent | 4c517db146cb1c59c8a54d9e87b9e5a4ae17987e (diff) | |
download | elgg-43a395ae735777bfb5474c4f6a37dc1cd0818a37.tar.gz elgg-43a395ae735777bfb5474c4f6a37dc1cd0818a37.tar.bz2 |
Fixes #1479. Added ElggAutoP. Removing [\n\r] from test strings before compare to deal with differing whitespace between tags among PHP versions.
Diffstat (limited to 'engine/tests/api')
-rw-r--r-- | engine/tests/api/output.php | 138 |
1 files changed, 74 insertions, 64 deletions
diff --git a/engine/tests/api/output.php b/engine/tests/api/output.php index eb1a66b29..c3d5aa8c6 100644 --- a/engine/tests/api/output.php +++ b/engine/tests/api/output.php @@ -1,64 +1,74 @@ -<?php
-/**
- * Test case for ElggAutop functionality.
- * @author Steve Clay <steve@mrclay.org>
- */
-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("<html><meta http-equiv='content-type' content='text/html; charset=utf-8'><body>"
- . $in . '</body></html>');
- $serialized = $doc->saveHTML();
- list(,$out) = explode('<body>', $serialized, 2);
- list($out) = explode('</body>', $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;
- }
-}
+<?php +/** + * Test case for ElggAutoP functionality. + */ +class ElggCoreOutputAutoPTest extends ElggCoreUnitTest { + + /** + * @var ElggAutoP + */ + protected $_autop; + + public function setUp() { + $this->_autop = new ElggAutoP(); + } + + public function testDomRoundtrip() { + $d = dir(dirname(dirname(__FILE__)) . '/test_files/output/autop'); + $in = file_get_contents($d->path . "/domdoc_in.html"); + $exp = file_get_contents($d->path . "/domdoc_exp.html"); + $exp = $this->flattenString($exp); + + $doc = new DOMDocument(); + libxml_use_internal_errors(true); + $doc->loadHTML("<html><meta http-equiv='content-type' content='text/html; charset=utf-8'><body>" + . $in . '</body></html>'); + $serialized = $doc->saveHTML(); + list(,$out) = explode('<body>', $serialized, 2); + list($out) = explode('</body>', $out, 2); + $out = $this->flattenString($out); + + $this->assertEqual($exp, $out, "DOMDocument's parsing/serialization roundtrip"); + } + + public function testProcess() { + $data = $this->provider(); + foreach ($data as $row) { + list($test, $in, $exp) = $row; + $exp = $this->flattenString($exp); + $out = $this->_autop->process($in); + $out = $this->flattenString($out); + + $this->assertEqual($exp, $out, "Equality case {$test}"); + } + } + + public function provider() { + $d = dir(dirname(dirname(__FILE__)) . '/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; + } + + /** + * Different versions of PHP return different whitespace between tags. + * Removing all line breaks normalizes that. + */ + public function flattenString($string) { + $r = preg_replace('/[\n\r]+/', '', $string); + return $r; + } +}
\ No newline at end of file |