From aaef389e10b3e36b5a87e361ac11f36d719e1968 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Mon, 7 Oct 2013 18:15:12 +0200 Subject: [PATCH] add some tests about content encoding when writing, reading and querying --- fixtures/06_Query/characters.xml | 4 ++++ tests/06_Query/CharacterTest.php | 29 ++++++++++++++++++++++++----- tests/10_Writing/EncodingTest.php | 21 +++++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/fixtures/06_Query/characters.xml b/fixtures/06_Query/characters.xml index ea5e0d05..cf15301d 100644 --- a/fixtures/06_Query/characters.xml +++ b/fixtures/06_Query/characters.xml @@ -58,6 +58,10 @@ 'a\'\'b\'\'c' + + + foo & bar&baz + diff --git a/tests/06_Query/CharacterTest.php b/tests/06_Query/CharacterTest.php index 3215c912..a1f6bdb5 100644 --- a/tests/06_Query/CharacterTest.php +++ b/tests/06_Query/CharacterTest.php @@ -3,6 +3,7 @@ namespace PHPCR\Tests\Query; use PHPCR\Query\QueryInterface; +use PHPCR\Query\QueryManagerInterface; require_once(__DIR__ . '/../../inc/BaseCase.php'); @@ -19,7 +20,7 @@ public static function setupBeforeClass($fixtures = '06_Query/characters') */ public function testPropertyWithBackslash() { - /** @var QueryManager $queryManager */ + /** @var QueryManagerInterface $queryManager */ $queryManager = $this->sharedFixture['qm']; $query = $queryManager->createQuery(' SELECT data.class @@ -40,7 +41,7 @@ public function testPropertyWithBackslash() */ public function testPropertyWithDoubleBackslash() { - /** @var QueryManager $queryManager */ + /** @var QueryManagerInterface $queryManager */ $queryManager = $this->sharedFixture['qm']; $query = $queryManager->createQuery(' SELECT data.doublebackslash @@ -61,7 +62,7 @@ public function testPropertyWithDoubleBackslash() */ public function testPropertyWithQuotes() { - /** @var QueryManager $queryManager */ + /** @var QueryManagerInterface $queryManager */ $queryManager = $this->sharedFixture['qm']; $query = $queryManager->createQuery(sprintf(' SELECT data.quotes @@ -83,7 +84,7 @@ public function testPropertyWithQuotes() */ public function testPropertyWithQuotesAndBackslash() { - /** @var QueryManager $queryManager */ + /** @var QueryManagerInterface $queryManager */ $queryManager = $this->sharedFixture['qm']; $query = $queryManager->createQuery(sprintf(' SELECT data.quoteandbackslash @@ -102,7 +103,7 @@ public function testPropertyWithQuotesAndBackslash() public function testQueryWithColon() { - /** @var QueryManager $queryManager */ + /** @var QueryManagerInterface $queryManager */ $queryManager = $this->sharedFixture['qm']; $query = $queryManager->createQuery(' SELECT data.property @@ -112,4 +113,22 @@ public function testQueryWithColon() QueryInterface::JCR_SQL2 )->execute(); } + + public function testQueryWithAmpersand() + { + /** @var QueryManagerInterface $queryManager */ + $queryManager = $this->sharedFixture['qm']; + $query = $queryManager->createQuery(' + SELECT data.ampersand + FROM [nt:unstructured] AS data + WHERE data.ampersand = "foo & bar&baz" + ', + QueryInterface::JCR_SQL2 + ); + + $result = $query->execute(); + $rows = $result->getRows(); + $this->assertCount(1, $rows); + $this->assertEquals('foo & bar&baz', $rows->current()->getValue('ampersand')); + } } diff --git a/tests/10_Writing/EncodingTest.php b/tests/10_Writing/EncodingTest.php index 055d6636..f96a3d58 100644 --- a/tests/10_Writing/EncodingTest.php +++ b/tests/10_Writing/EncodingTest.php @@ -50,4 +50,25 @@ public static function getNodeNames() array("node-&-x"), ); } + + /** + * @dataProvider getPropertyValues + */ + public function testEncodingPropertyValues($value, $type) + { + $this->node->setProperty($type, $value); + $session = $this->saveAndRenewSession(); + $this->assertEquals($value, $session->getRootNode()->getNode('tests_write_encoding')->getNode('testEncoding')->getPropertyValue($type)); + } + + public static function getPropertyValues() + { + return array( + array('PHPCR\Query\QueryInterface', 'backslash'), + array('PHPCR\\\\Query\\\\QueryInterface', 'doublebackslash'), + array('"\'', 'quotes'), + array('a\\\'\\\'b\\\'\\\'c', 'quotesandbackslash'), + array('foo & bar&baz', 'ampersand'), + ); + } }