/usr/share/php/tests/Horde_Util/Horde/Util/DomhtmlTest.php is in php-horde-util 2.3.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | <?php
/**
* @author Michael Slusarz <slusarz@horde.org>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @category Horde
* @package Util
* @subpackage UnitTests
*/
class Horde_Util_DomhtmlTest extends PHPUnit_Framework_TestCase
{
public function testBug9567()
{
$text = <<<EOT
<html>
<head>
<meta http-equiv=3DContent-Type content=3D"text/html; charset=3Diso-8859-1">
</head>
<body>
pr=E9parer =E0 vendre d’ao=FBt ;
</body>
</html>
EOT;
$expected = "préparer à vendre d’août ;";
$dom = new Horde_Domhtml(quoted_printable_decode($text), 'iso-8859-1');
$this->assertEquals(
Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-1'),
trim($dom->returnBody())
);
$this->assertEquals(
'iso-8859-1',
$dom->getCharset()
);
/* Test auto-detect. */
$dom = new Horde_Domhtml(quoted_printable_decode($text));
$this->assertEquals(
Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-1'),
trim($dom->returnBody())
);
$this->assertEquals(
'iso-8859-1',
$dom->getCharset()
);
}
public function testBug9714()
{
$text = "<html><body>J'ai r=E9ussi J ai r=E9ussi</body></html>";
$expected = "J'ai réussi J ai réussi";
$dom = new Horde_Domhtml(quoted_printable_decode($text), 'iso-8859-15');
$this->assertEquals(
Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-15'),
trim($dom->returnBody())
);
/* iso-8859-15 is not recognized, so UTF-8 is used internally. */
$this->assertEquals(
'UTF-8',
$dom->getCharset()
);
/* Test auto-detect. */
$dom = new Horde_Domhtml(quoted_printable_decode($text));
$this->assertEquals(
Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-15'),
trim($dom->returnBody())
);
/* iso-8859-1 is used for auto-detection. */
$this->assertEquals(
'iso-8859-1',
$dom->getCharset()
);
}
public function testBug9992()
{
$text = base64_decode('dGVzdDogtbno6bvtu+nt/eHpu7797Txicj4K');
$expected = '<p>test: ľščéťíťéíýáéťžýí<br/></p>';
$dom = new Horde_Domhtml($text, 'iso-8859-2');
$this->assertEquals(
Horde_String::convertCharset($expected, 'UTF-8', 'iso-8859-2'),
trim($dom->returnBody())
);
$this->assertEquals(
'UTF-8',
$dom->getCharset()
);
}
public function testIterator()
{
$text = file_get_contents(__DIR__ . '/fixtures/domhtml_test.html');
$dom = new Horde_Domhtml($text);
$tags = array(
'html',
'body',
'div',
'head',
'title'
);
foreach ($dom as $node) {
if ($node instanceof DOMElement) {
if ($node->tagName != reset($tags)) {
$this->fail('Wrong tag name.');
}
array_shift($tags);
}
}
}
public function testHrefSpaces()
{
$text = <<<EOT
<html>
<body>
<a href=" http://foo.example.com/">Foo</a>
</body>
</html>
EOT;
$dom = new Horde_Domhtml($text, 'UTF-8');
foreach ($dom as $val) {
if (($val instanceof DOMElement) &&
($val->tagName == 'a')) {
$this->assertEquals(
' http://foo.example.com/',
$val->getAttribute('href')
);
}
}
$this->assertEquals(
'UTF-8',
$dom->getCharset()
);
}
public function testHeadGeneration()
{
$dom = new Horde_Domhtml('<div>foo</div>');
$head = $dom->getHead();
$this->assertNull($head->previousSibling);
$this->assertEquals(
'iso-8859-1',
$dom->getCharset()
);
}
public function testBodyGeneration()
{
$dom = new Horde_Domhtml('<div>foo</div>');
$body = $dom->getBody();
$this->assertEquals(
1,
$body->childNodes->length
);
$this->assertEquals(
'div',
$body->childNodes->item(0)->tagName
);
}
public function testReturnHtmlCharset()
{
$dom = new Horde_DomHtml('<html><body><div>préparer à vendre d’août</div></body></html>', 'UTF-8');
$this->assertEquals(
$dom->returnHtml(),
$dom->returnHtml(array('charset' => 'iso-8859-1'))
);
}
public function testReturnHtmlMetaCharset()
{
$dom = new Horde_Domhtml('<html><body><div>foo</div></body></html>', 'UTF-8');
$this->assertRegExp(
'/"text\/html; charset=utf-8"/',
$dom->returnHtml(array('metacharset' => true))
);
}
}
|