1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?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;
}
}
|