blob: 62a34262ae16b9125a1c833e26670d2df17b465f (
plain)
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
|
<?php
/** @file
* Tests for the QueryPath library.
* @author M Butcher <matt@aleph-null.tv>
* @license The GNU Lesser GPL (LGPL) or an MIT-like license.
*/
namespace QueryPath\Tests;
require_once __DIR__ . '/TestCase.php';
/**
* @ingroup querypath_tests
*/
class EntitiesTest extends TestCase {
public function testReplaceEntity() {
$entity = 'amp';
$this->assertEquals('38', \QueryPath\Entities::replaceEntity($entity));
$entity = 'lceil';
$this->assertEquals('8968', \QueryPath\Entities::replaceEntity($entity));
}
public function testReplaceAllEntities() {
$test = '<?xml version="1.0"?><root>&©&& nothing.</root>';
$expect = '<?xml version="1.0"?><root>&©&& nothing.</root>';
$this->assertEquals($expect, \QueryPath\Entities::replaceAllEntities($test));
$test = '&&& ';
$expect = '&&& ';
$this->assertEquals($expect, \QueryPath\Entities::replaceAllEntities($test));
$test = "é\n";
$expect = "é\n";
$this->assertEquals($expect, \QueryPath\Entities::replaceAllEntities($test));
}
public function testReplaceHexEntities() {
$test = '©';
$expect = '©';
$this->assertEquals($expect, \QueryPath\Entities::replaceAllEntities($test));
}
public function testQPEntityReplacement() {
$test = '<?xml version="1.0"?><root>&©&& nothing.</root>';
/*$expect = '<?xml version="1.0"?><root>&©&& nothing.</root>';*/
// We get this because the DOM serializer re-converts entities.
$expect = '<?xml version="1.0"?>
<root>&©&& nothing.</root>';
$qp = qp($test, NULL, array('replace_entities' => TRUE));
// Interestingly, the XML serializer converts decimal to hex and ampersands
// to &.
$this->assertEquals($expect, trim($qp->xml()));
}
}
|