summaryrefslogtreecommitdiff
path: root/lib/querypath/test/Tests/QueryPath/EntitiesTest.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-01-18 20:07:16 +0100
committeremkael <emkael@tlen.pl>2017-01-18 20:07:16 +0100
commit9a9c04512e5dcb77c7fe5d850e3f2a0250cc160e (patch)
treefed46b5f4c2ed3a050bb1a7ad7c6d0a3ea844d55 /lib/querypath/test/Tests/QueryPath/EntitiesTest.php
parentc5bcf8f74fb80b7e163663845b0d6e35cabface3 (diff)
* Motor Sport Magazine feed provider
Diffstat (limited to 'lib/querypath/test/Tests/QueryPath/EntitiesTest.php')
-rw-r--r--lib/querypath/test/Tests/QueryPath/EntitiesTest.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/querypath/test/Tests/QueryPath/EntitiesTest.php b/lib/querypath/test/Tests/QueryPath/EntitiesTest.php
new file mode 100644
index 0000000..62a3426
--- /dev/null
+++ b/lib/querypath/test/Tests/QueryPath/EntitiesTest.php
@@ -0,0 +1,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>&amp;&copy;&#38;& nothing.</root>';
+ $expect = '<?xml version="1.0"?><root>&#38;&#169;&#38;&#38; nothing.</root>';
+ $this->assertEquals($expect, \QueryPath\Entities::replaceAllEntities($test));
+
+ $test = '&&& ';
+ $expect = '&#38;&#38;&#38; ';
+ $this->assertEquals($expect, \QueryPath\Entities::replaceAllEntities($test));
+
+ $test = "&eacute;\n";
+ $expect = "&#233;\n";
+ $this->assertEquals($expect, \QueryPath\Entities::replaceAllEntities($test));
+ }
+
+ public function testReplaceHexEntities() {
+ $test = '&#xA9;';
+ $expect = '&#xA9;';
+ $this->assertEquals($expect, \QueryPath\Entities::replaceAllEntities($test));
+ }
+
+ public function testQPEntityReplacement() {
+ $test = '<?xml version="1.0"?><root>&amp;&copy;&#38;& nothing.</root>';
+ /*$expect = '<?xml version="1.0"?><root>&#38;&#169;&#38;&#38; nothing.</root>';*/
+ // We get this because the DOM serializer re-converts entities.
+ $expect = '<?xml version="1.0"?>
+<root>&amp;&#xA9;&amp;&amp; nothing.</root>';
+
+ $qp = qp($test, NULL, array('replace_entities' => TRUE));
+ // Interestingly, the XML serializer converts decimal to hex and ampersands
+ // to &amp;.
+ $this->assertEquals($expect, trim($qp->xml()));
+ }
+}