Skip to content

Commit affab2a

Browse files
committed
Merge pull request #112 from wjzijderveld/character-query-tests
Added some tests to validate literals with backslashes and quotes
2 parents c411348 + 2043e70 commit affab2a

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

fixtures/06_Query/characters.xml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<sv:node
3+
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
4+
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
5+
xmlns:jcr="http://www.jcp.org/jcr/1.0"
6+
xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
7+
8+
sv:name="tests_query_characters">
9+
10+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
11+
<sv:value>nt:unstructured</sv:value>
12+
</sv:property>
13+
14+
<sv:node sv:name="testCharacters">
15+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
16+
<sv:value>nt:unstructured</sv:value>
17+
</sv:property>
18+
19+
<sv:node sv:name="propertyCharacterComparison">
20+
21+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
22+
<sv:value>nt:file</sv:value>
23+
</sv:property>
24+
25+
<sv:property sv:name="jcr:created" sv:type="Date">
26+
<sv:value>2011-03-21T14:34:20.452+01:00</sv:value>
27+
</sv:property>
28+
29+
<sv:property sv:name="jcr:createdBy" sv:type="String">
30+
<sv:value>admin</sv:value>
31+
</sv:property>
32+
33+
<sv:node sv:name="jcr:content">
34+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
35+
<sv:value>nt:unstructured</sv:value>
36+
</sv:property>
37+
38+
<sv:property sv:name="jcr:lastModified" sv:type="Date">
39+
<sv:value>2009-04-27T13:01:07.472+02:00</sv:value>
40+
</sv:property>
41+
42+
<sv:property sv:name="jcr:mimeType" sv:type="String">
43+
<sv:value>text/plain</sv:value>
44+
</sv:property>
45+
46+
<sv:property sv:name="class" sv:type="String">
47+
<sv:value>PHPCR\Query\QueryInterface</sv:value>
48+
</sv:property>
49+
50+
<sv:property sv:name="doublebackslash" sv:type="String">
51+
<sv:value>PHPCR\\Query\\QueryInterface</sv:value>
52+
</sv:property>
53+
54+
<sv:property sv:name="quotes" sv:type="String">
55+
<sv:value>"'</sv:value>
56+
</sv:property>
57+
58+
<sv:property sv:name="quoteandbackslash" sv:type="String">
59+
<sv:value>'a\'\'b\'\'c'</sv:value>
60+
</sv:property>
61+
</sv:node>
62+
</sv:node>
63+
</sv:node>
64+
</sv:node>

tests/06_Query/CharacterTest.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
3+
namespace PHPCR\Tests\Query;
4+
5+
use PHPCR\Query\QueryInterface;
6+
7+
require_once(__DIR__ . '/../../inc/BaseCase.php');
8+
9+
10+
class CharacterTest extends \PHPCR\Test\BaseCase
11+
{
12+
public static function setupBeforeClass($fixtures = '06_Query/characters')
13+
{
14+
parent::setupBeforeClass($fixtures);
15+
self::$staticSharedFixture['qm'] = self::$staticSharedFixture['session']->getWorkspace()->getQueryManager();
16+
}
17+
18+
/**
19+
* Using /tests_general_base/propertyCharacterComparison/jcr:content
20+
*/
21+
public function testPropertyWithBackslash()
22+
{
23+
/** @var QueryManager $queryManager */
24+
$queryManager = $this->sharedFixture['qm'];
25+
$query = $queryManager->createQuery('
26+
SELECT data.class
27+
FROM [nt:unstructured] AS data
28+
WHERE data.class = "PHPCR\Query\QueryInterface"',
29+
QueryInterface::JCR_SQL2
30+
);
31+
32+
$result = $query->execute();
33+
34+
$rows = $result->getRows();
35+
$this->assertCount(1, $rows);
36+
$this->assertEquals('PHPCR\Query\QueryInterface', $rows->current()->getValue('class'));
37+
}
38+
39+
/**
40+
* Using /tests_general_base/propertyCharacterComparison/jcr:content
41+
*/
42+
public function testPropertyWithDoubleBackslash()
43+
{
44+
/** @var QueryManager $queryManager */
45+
$queryManager = $this->sharedFixture['qm'];
46+
$query = $queryManager->createQuery('
47+
SELECT data.doublebackslash
48+
FROM [nt:unstructured] AS data
49+
WHERE data.doublebackslash = "PHPCR\\\\Query\\\\QueryInterface"',
50+
QueryInterface::JCR_SQL2
51+
);
52+
53+
$result = $query->execute();
54+
55+
$rows = $result->getRows();
56+
$this->assertCount(1, $rows);
57+
$this->assertEquals('PHPCR\\\\Query\\\\QueryInterface', $rows->current()->getValue('doublebackslash'));
58+
}
59+
60+
/**
61+
* Using /tests_general_base/propertyCharacterComparison/jcr:content
62+
*/
63+
public function testPropertyWithQuotes()
64+
{
65+
/** @var QueryManager $queryManager */
66+
$queryManager = $this->sharedFixture['qm'];
67+
$query = $queryManager->createQuery(sprintf('
68+
SELECT data.quotes
69+
FROM [nt:unstructured] AS data
70+
WHERE data.quotes = "%s"
71+
', "\\\"'"),
72+
QueryInterface::JCR_SQL2
73+
);
74+
75+
$result = $query->execute();
76+
77+
$rows = $result->getRows();
78+
$this->assertCount(1, $rows);
79+
$this->assertEquals('"\'', $rows->current()->getValue('quotes'));
80+
}
81+
82+
/**
83+
* Using /tests_general_base/propertyCharacterComparison/jcr:content
84+
*/
85+
public function testPropertyWithQuotesAndBackslash()
86+
{
87+
/** @var QueryManager $queryManager */
88+
$queryManager = $this->sharedFixture['qm'];
89+
$query = $queryManager->createQuery(sprintf('
90+
SELECT data.quoteandbackslash
91+
FROM [nt:unstructured] AS data
92+
WHERE data.quoteandbackslash = "%s"
93+
', "'a\'\'b\'\'c'"),
94+
QueryInterface::JCR_SQL2
95+
);
96+
97+
$result = $query->execute();
98+
99+
$rows = $result->getRows();
100+
$this->assertCount(1, $rows);
101+
$this->assertEquals("'a\'\'b\'\'c'", $rows->current()->getValue('quoteandbackslash'));
102+
}
103+
104+
public function testQueryWithColon()
105+
{
106+
/** @var QueryManager $queryManager */
107+
$queryManager = $this->sharedFixture['qm'];
108+
$query = $queryManager->createQuery('
109+
SELECT data.property
110+
FROM [nt:unstructured] AS data
111+
WHERE data.property = "foo:bar"
112+
',
113+
QueryInterface::JCR_SQL2
114+
)->execute();
115+
}
116+
}

0 commit comments

Comments
 (0)