Skip to content

Commit 7726fec

Browse files
committed
Merge pull request #119 from phpcr/add-encoding-tests
add some tests about content encoding when writing, reading and querying
2 parents 3095c00 + aaef389 commit 7726fec

File tree

3 files changed

+49
-5
lines changed

3 files changed

+49
-5
lines changed

fixtures/06_Query/characters.xml

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
<sv:property sv:name="quoteandbackslash" sv:type="String">
5959
<sv:value>'a\'\'b\'\'c'</sv:value>
6060
</sv:property>
61+
62+
<sv:property sv:name="ampersand" sv:type="String">
63+
<sv:value>foo &amp; bar&amp;baz</sv:value>
64+
</sv:property>
6165
</sv:node>
6266
</sv:node>
6367
</sv:node>

tests/06_Query/CharacterTest.php

+24-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPCR\Tests\Query;
44

55
use PHPCR\Query\QueryInterface;
6+
use PHPCR\Query\QueryManagerInterface;
67

78
require_once(__DIR__ . '/../../inc/BaseCase.php');
89

@@ -19,7 +20,7 @@ public static function setupBeforeClass($fixtures = '06_Query/characters')
1920
*/
2021
public function testPropertyWithBackslash()
2122
{
22-
/** @var QueryManager $queryManager */
23+
/** @var QueryManagerInterface $queryManager */
2324
$queryManager = $this->sharedFixture['qm'];
2425
$query = $queryManager->createQuery('
2526
SELECT data.class
@@ -40,7 +41,7 @@ public function testPropertyWithBackslash()
4041
*/
4142
public function testPropertyWithDoubleBackslash()
4243
{
43-
/** @var QueryManager $queryManager */
44+
/** @var QueryManagerInterface $queryManager */
4445
$queryManager = $this->sharedFixture['qm'];
4546
$query = $queryManager->createQuery('
4647
SELECT data.doublebackslash
@@ -61,7 +62,7 @@ public function testPropertyWithDoubleBackslash()
6162
*/
6263
public function testPropertyWithQuotes()
6364
{
64-
/** @var QueryManager $queryManager */
65+
/** @var QueryManagerInterface $queryManager */
6566
$queryManager = $this->sharedFixture['qm'];
6667
$query = $queryManager->createQuery(sprintf('
6768
SELECT data.quotes
@@ -83,7 +84,7 @@ public function testPropertyWithQuotes()
8384
*/
8485
public function testPropertyWithQuotesAndBackslash()
8586
{
86-
/** @var QueryManager $queryManager */
87+
/** @var QueryManagerInterface $queryManager */
8788
$queryManager = $this->sharedFixture['qm'];
8889
$query = $queryManager->createQuery(sprintf('
8990
SELECT data.quoteandbackslash
@@ -102,7 +103,7 @@ public function testPropertyWithQuotesAndBackslash()
102103

103104
public function testQueryWithColon()
104105
{
105-
/** @var QueryManager $queryManager */
106+
/** @var QueryManagerInterface $queryManager */
106107
$queryManager = $this->sharedFixture['qm'];
107108
$query = $queryManager->createQuery('
108109
SELECT data.property
@@ -112,4 +113,22 @@ public function testQueryWithColon()
112113
QueryInterface::JCR_SQL2
113114
)->execute();
114115
}
116+
117+
public function testQueryWithAmpersand()
118+
{
119+
/** @var QueryManagerInterface $queryManager */
120+
$queryManager = $this->sharedFixture['qm'];
121+
$query = $queryManager->createQuery('
122+
SELECT data.ampersand
123+
FROM [nt:unstructured] AS data
124+
WHERE data.ampersand = "foo & bar&baz"
125+
',
126+
QueryInterface::JCR_SQL2
127+
);
128+
129+
$result = $query->execute();
130+
$rows = $result->getRows();
131+
$this->assertCount(1, $rows);
132+
$this->assertEquals('foo & bar&baz', $rows->current()->getValue('ampersand'));
133+
}
115134
}

tests/10_Writing/EncodingTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,25 @@ public static function getNodeNames()
5050
array("node-&-x"),
5151
);
5252
}
53+
54+
/**
55+
* @dataProvider getPropertyValues
56+
*/
57+
public function testEncodingPropertyValues($value, $type)
58+
{
59+
$this->node->setProperty($type, $value);
60+
$session = $this->saveAndRenewSession();
61+
$this->assertEquals($value, $session->getRootNode()->getNode('tests_write_encoding')->getNode('testEncoding')->getPropertyValue($type));
62+
}
63+
64+
public static function getPropertyValues()
65+
{
66+
return array(
67+
array('PHPCR\Query\QueryInterface', 'backslash'),
68+
array('PHPCR\\\\Query\\\\QueryInterface', 'doublebackslash'),
69+
array('"\'', 'quotes'),
70+
array('a\\\'\\\'b\\\'\\\'c', 'quotesandbackslash'),
71+
array('foo & bar&baz', 'ampersand'),
72+
);
73+
}
5374
}

0 commit comments

Comments
 (0)