From 9a9c04512e5dcb77c7fe5d850e3f2a0250cc160e Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 18 Jan 2017 20:07:16 +0100 Subject: * Motor Sport Magazine feed provider --- .../test/Tests/QueryPath/EntitiesTest.php | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lib/querypath/test/Tests/QueryPath/EntitiesTest.php (limited to 'lib/querypath/test/Tests/QueryPath/EntitiesTest.php') 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 @@ + + * @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 = '&©&& nothing.'; + $expect = '&©&& nothing.'; + $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 = '&©&& nothing.'; + /*$expect = '&©&& nothing.';*/ + // We get this because the DOM serializer re-converts entities. + $expect = ' +&©&& nothing.'; + + $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())); + } +} -- cgit v1.2.3