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