-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathQueryResultsTest.php
More file actions
246 lines (200 loc) · 7.68 KB
/
Copy pathQueryResultsTest.php
File metadata and controls
246 lines (200 loc) · 7.68 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?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\QueryResultInterface;
/**
* $ 6.11 QueryResult - Test the query result object.
*/
class QueryResultsTest extends QueryBaseCase
{
/** @var QueryResultInterface */
protected $qr;
public static $expect = array('jcr:createdBy','jcr:created','jcr:primaryType','jcr:path','jcr:score');
public function setUp()
{
parent::setUp();
$this->qr = $this->query->execute();
//sanity check
$this->assertInstanceOf('PHPCR\Query\QueryResultInterface', $this->qr);
}
public function testBindValue()
{
$this->markTestSkipped(); //TODO: test with a SQL2 query
}
public function testGetBindVariableNames()
{
$this->markTestSkipped(); //TODO: test with a SQL2 query
}
public function testGetBindVariableNamesEmpty()
{
$this->markTestSkipped(); //TODO: test with a SQL2 query
}
public function testGetColumnNames()
{
$columnNames = $this->qr->getColumnNames();
sort($columnNames); //order is not determined
$columnNamesExpected = array('nt:folder.jcr:created', 'nt:folder.jcr:createdBy', 'nt:folder.jcr:primaryType');
$this->assertEquals($columnNamesExpected, $columnNames);
}
public function testGetAliasColumnNames()
{
$query = $this->sharedFixture['qm']->createQuery('
SELECT [jcr:mimeType] AS bar, stringToCompare as foo, [nt:unstructured].longNumberToCompare, ding
FROM [nt:unstructured]
WHERE stringToCompare IS NOT NULL
',
\PHPCR\Query\QueryInterface::JCR_SQL2
);
$qr = $query->execute();
$columnNames = $qr->getColumnNames();
sort($columnNames); //order is not determined
$columnNamesExpected = array('bar', 'ding', 'foo', 'nt:unstructured.longNumberToCompare');
$this->assertEquals($columnNamesExpected, $columnNames);
foreach ($qr->getRows() as $row) {
$this->assertNotNull($row->getValue('bar'));
$this->assertNotNull($row->getValue('foo'));
$this->assertNotNull($row->getValue('longNumberToCompare'));
$this->assertEquals('', $row->getValue('ding'));
}
}
public function testGetNodes()
{
$nodes = $this->qr->getNodes();
$count = 0;
foreach ($nodes as $node) {
$this->assertInstanceOf('PHPCR\NodeInterface', $node);
$count++;
}
$this->assertEquals(5, $count);
}
public function testGetNodesAtOnce()
{
// This test gets the nodes in one burst (parallel) instead serial like testGetNodes()
$nodeIterator = $this->qr->getNodes();
$keys = array();
$this->markTestSkipped('TODO: this is not part of the api, update test when we decided what should happen');
$nodes = $nodeIterator->getNodes();
foreach ($nodes as $path => $node) {
$this->assertInstanceOf('PHPCR\NodeInterface', $node);
$this->assertEquals($path, $node->getPath());
$keys[] = $path;
}
$this->assertCount(8, $keys);
$this->assertContains('/tests_general_base/idExample/jcr:content/Test escaping_x0020bla <>\'" node', $keys);
}
public function testGetSelectorNames()
{
$selectorNames = $this->qr->getSelectorNames();
$selectorNamesExpected = array('nt:folder');
$this->assertEquals($selectorNamesExpected, $selectorNames);
}
public function testIterateOverQueryResult()
{
$count = 0;
foreach ($this->qr as $key => $row) {
$this->assertInstanceOf('PHPCR\Query\RowInterface', $row); // Test if the return element is an instance of row
foreach ($row as $columnName => $value) { // Test if we can iterate over the columns inside a row
$count++;
}
}
$this->assertEquals(15, $count);
}
public function testReadPropertyContentFromResults()
{
$seekName = '/tests_general_base/multiValueProperty';
$this->assertTrue(count($this->qr->getNodes()) > 0);
foreach ($this->qr->getNodes() as $path => $node) {
if ($seekName == $path) {
break;
}
}
$this->assertInstanceOf('PHPCR\NodeInterface', $node);
$prop = $node->getProperty('jcr:uuid');
$this->assertInstanceOf('PHPCR\PropertyInterface', $prop);
$this->assertEquals('jcr:uuid', $prop->getName());
$this->assertEquals('14e18ef3-be20-4985-bee9-7bb4763b31de', $prop->getString());
}
public function testCompareNumberFields()
{
$query = $this->sharedFixture['qm']->createQuery('
SELECT data.longNumberToCompare
FROM [nt:unstructured] AS data
WHERE data.longNumberToCompare > 2
AND ISDESCENDANTNODE([/tests_general_base])
',
\PHPCR\Query\QueryInterface::JCR_SQL2
);
$result = $query->execute();
$rows = array();
foreach ($result->getRows() as $row) {
$rows[] = $row;
}
$this->assertCount(1, $rows);
$this->assertEquals(10, $rows[0]->getValue('data.longNumberToCompare'));
}
public function testCompareNumberFieldsMulti()
{
$query = $this->sharedFixture['qm']->createQuery('
SELECT data.longNumberToCompareMulti
FROM [nt:unstructured] AS data
WHERE data.longNumberToCompareMulti = 2
AND ISDESCENDANTNODE([/tests_general_base])
',
\PHPCR\Query\QueryInterface::JCR_SQL2
);
$result = $query->execute();
$rows = array();
foreach ($result->getRows() as $row) {
$rows[] = $row;
}
$this->assertCount(1, $rows);
// returning a string value is, perhaps suprisingly, the correct behavior.
$this->assertEquals('4 2 8', $rows[0]->getValue('data.longNumberToCompareMulti'));
}
public function testCompareStringFields()
{
$query = $this->sharedFixture['qm']->createQuery(
'SELECT data.stringToCompare FROM [nt:unstructured] AS data WHERE data.stringToCompare > "10"',
\PHPCR\Query\QueryInterface::JCR_SQL2
);
$result = $query->execute();
$rows = array();
foreach ($result->getRows() as $row) {
$rows[] = $row;
}
$this->assertCount(1, $rows);
$this->assertEquals(2, $rows[0]->getValue('data.stringToCompare'));
}
public function testBooleanField()
{
$query = $this->sharedFixture['qm']->createQuery(
'SELECT data.thisIsNo FROM [nt:unstructured] as data WHERE data.thisIsNo = false',
\PHPCR\Query\QueryInterface::JCR_SQL2
);
$result = $query->execute();
$rows = array();
foreach ($result->getRows() as $row) {
$rows[] = $row;
}
$this->assertCount(1, $rows);
$this->assertEquals(false, $rows[0]->getValue('data.thisIsNo'));
$query = $this->sharedFixture['qm']->createQuery(
'SELECT data.thisIsYes FROM [nt:unstructured] as data WHERE data.thisIsYes = true',
\PHPCR\Query\QueryInterface::JCR_SQL2
);
$result = $query->execute();
$rows = array();
foreach ($result->getRows() as $row) {
$rows[] = $row;
}
$this->assertCount(1, $rows);
$this->assertEquals(true, $rows[0]->getValue('data.thisIsYes'));
}
}