-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathCharacterTest.php
159 lines (137 loc) · 5.02 KB
/
CharacterTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/*
* This file is part of the PHPCR API Tests package
*
* Copyright (c) 2015 Liip and others
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPCR\Tests\Query;
use PHPCR\Query\QueryInterface;
use PHPCR\Query\QueryManagerInterface;
class CharacterTest extends \PHPCR\Test\BaseCase
{
public static function setupBeforeClass($fixtures = '06_Query/characters')
{
parent::setupBeforeClass($fixtures);
self::$staticSharedFixture['qm'] = self::$staticSharedFixture['session']->getWorkspace()->getQueryManager();
}
/**
* Using /tests_general_base/propertyCharacterComparison/jcr:content.
*/
public function testPropertyWithBackslash()
{
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery('
SELECT data.class
FROM [nt:unstructured] AS data
WHERE data.class = "PHPCR\Query\QueryInterface"',
QueryInterface::JCR_SQL2
);
$result = $query->execute();
$rows = $result->getRows();
$this->assertCount(1, $rows);
$this->assertEquals('PHPCR\Query\QueryInterface', $rows->current()->getValue('class'));
}
/**
* Using /tests_general_base/propertyCharacterComparison/jcr:content.
*/
public function testPropertyWithDoubleBackslash()
{
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery('
SELECT data.doublebackslash
FROM [nt:unstructured] AS data
WHERE data.doublebackslash = "PHPCR\\\\Query\\\\QueryInterface"',
QueryInterface::JCR_SQL2
);
$result = $query->execute();
$rows = $result->getRows();
$this->assertCount(1, $rows);
$this->assertEquals('PHPCR\\\\Query\\\\QueryInterface', $rows->current()->getValue('doublebackslash'));
}
/**
* Using /tests_general_base/propertyCharacterComparison/jcr:content.
*/
public function testPropertyWithQuotes()
{
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery(sprintf('
SELECT data.quotes
FROM [nt:unstructured] AS data
WHERE data.quotes = "%s"
', "\\\"'"),
QueryInterface::JCR_SQL2
);
$result = $query->execute();
$rows = $result->getRows();
$this->assertCount(1, $rows);
$this->assertEquals('"\'', $rows->current()->getValue('quotes'));
}
/**
* Using /tests_general_base/propertyCharacterComparison/jcr:content.
*/
public function testPropertyWithQuotesAndBackslash()
{
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery(sprintf('
SELECT data.quoteandbackslash
FROM [nt:unstructured] AS data
WHERE data.quoteandbackslash = "%s"
', "'a\'\'b\'\'c'"),
QueryInterface::JCR_SQL2
);
$result = $query->execute();
$rows = $result->getRows();
$this->assertCount(1, $rows);
$this->assertEquals("'a\'\'b\'\'c'", $rows->current()->getValue('quoteandbackslash'));
}
public function testQueryWithColon()
{
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery('
SELECT data.property
FROM [nt:unstructured] AS data
WHERE data.property = "foo:bar"
',
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'));
}
public function testNodeNameWithMinus()
{
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery('
SELECT node.[jcr:uuid] AS uuid
FROM [nt:unstructured] AS node
WHERE ISCHILDNODE(node, [/tests_query_encoding/test-2e])',
QueryInterface::JCR_SQL2
);
$result = $query->execute();
$rows = $result->getRows();
$this->assertCount(1, $rows);
$this->assertEquals('PHPCR\Query\QueryInterface', $rows->current()->getValue('class'));
}
}