Permalink
Browse files

fix(html): autop no longer ltrims next to a leading inline element

Migrates test to PHPUnit

Fixes #9790
  • Loading branch information...
mrclay committed May 4, 2016
1 parent 7d64da4 commit 6785ee88278859c87a5569428656d6870f69fa3d
@@ -226,6 +226,10 @@ protected function addParagraphs(DOMElement $el) {
$isElement = ($node->nodeType === XML_ELEMENT_NODE);
if ($isElement) {
$isBlock = in_array($node->nodeName, $this->_blocks);
if (!$isBlock) {
// if we start with an inline element we don't need to do this
$ltrimFirstTextNode = false;
}
} else {
$isBlock = false;
}
@@ -241,7 +245,9 @@ protected function addParagraphs(DOMElement $el) {
if ($isText) {
$nodeText = $node->nodeValue;
if ($ltrimFirstTextNode) {
// we're at the beginning of a sequence of text/inline elements
$nodeText = ltrim($nodeText);
$ltrimFirstTextNode = false;
}
@@ -250,6 +256,7 @@ protected function addParagraphs(DOMElement $el) {
$nodeText = substr($nodeText, strlen($m[0]));
}
if ($isLastInline) {
// we're at the end of a sequence of text/inline elements
$nodeText = rtrim($nodeText);
}
$nodeText = str_replace("\n", $this->_unique . 'NL', $nodeText);
View
@@ -567,33 +567,6 @@ function _elgg_get_display_query($string) {
return htmlspecialchars($display_query, ENT_QUOTES, 'UTF-8', false);
}
/**
* Unit tests for Output
*
* @param string $hook unit_test
* @param string $type system
* @param mixed $value Array of tests
* @param mixed $params Params
*
* @return array
* @access private
*/
function _elgg_output_unit_test($hook, $type, $value, $params) {
global $CONFIG;
$value[] = "{$CONFIG->path}engine/tests/ElggCoreOutputAutoPTest.php";
return $value;
}
/**
* Initialize the output subsystem.
*
* @return void
* @access private
*/
function _elgg_output_init() {
elgg_register_plugin_hook_handler('unit_test', 'system', '_elgg_output_unit_test');
}
return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
$events->registerHandler('init', 'system', '_elgg_output_init');
};
@@ -1,8 +1,6 @@
<?php
/**
* Test case for \ElggAutoP functionality.
*/
class ElggCoreOutputAutoPTest extends \ElggCoreUnitTest {
class ElggAutoPTest extends \PHPUnit_Framework_TestCase {
/**
* @var \ElggAutoP
@@ -14,7 +12,7 @@ public function setUp() {
}
public function testDomRoundtrip() {
$d = dir(dirname(__FILE__) . '/test_files/output/autop');
$d = dir(__DIR__ . '/test_files/autop');
$in = file_get_contents($d->path . "/domdoc_in.html");
$exp = file_get_contents($d->path . "/domdoc_exp.html");
$exp = $this->flattenString($exp);
@@ -28,23 +26,22 @@ public function testDomRoundtrip() {
list($out) = explode('</body>', $out, 2);
$out = $this->flattenString($out);
$this->assertEqual($exp, $out, "DOMDocument's parsing/serialization roundtrip");
$this->assertEquals($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}");
}
/**
* @dataProvider provider
*/
public function testProcess($test, $in, $exp) {
$exp = $this->flattenString($exp);
$out = $this->_autop->process($in);
$out = $this->flattenString($out);
$this->assertEquals($exp, $out, "Equality case {$test}");
}
public function provider() {
$d = dir(dirname(__FILE__) . '/test_files/output/autop');
$d = dir(__DIR__ . '/test_files/autop');
$tests = array();
while (false !== ($entry = $d->read())) {
if (preg_match('/^([a-z\\-]+)\.in\.html$/i', $entry, $m)) {
@@ -0,0 +1,3 @@
<p><b></b> test</p>
<p><b> test</b></p>
@@ -0,0 +1,3 @@
<b></b> test
<b> test</b>

0 comments on commit 6785ee8

Please sign in to comment.