Skip to content

Commit a9191d7

Browse files
committed
test operator precedence of the SQL2ToQOM-parser
1 parent c411348 commit a9191d7

File tree

2 files changed

+174
-0
lines changed

2 files changed

+174
-0
lines changed

tests/06_Query/QOM/QomTestQueries.php

+139
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,145 @@ public static function getQueries(\PHPCR\Query\QOM\QueryObjectModelFactoryInterf
135135
array(),
136136
array());
137137

138+
/**
139+
* 6.7.12. Constraint (operator precedence)
140+
*/
141+
$queries['6.7.12.Constraint.Precedence.1'] = $factory->createQuery(
142+
$factory->selector('nt:file'),
143+
$factory->orConstraint(
144+
$factory->comparison(
145+
$factory->propertyValue('prop1', 'sel1'),
146+
Constants::JCR_OPERATOR_EQUAL_TO,
147+
$factory->literal('1')
148+
),
149+
$factory->andConstraint(
150+
$factory->comparison(
151+
$factory->propertyValue('prop2', 'sel1'),
152+
Constants::JCR_OPERATOR_EQUAL_TO,
153+
$factory->literal('2')
154+
),
155+
$factory->comparison(
156+
$factory->propertyValue('prop3', 'sel1'),
157+
Constants::JCR_OPERATOR_EQUAL_TO,
158+
$factory->literal('3')
159+
)
160+
)
161+
),
162+
array(),
163+
array()
164+
);
165+
166+
$queries['6.7.12.Constraint.Precedence.2'] = $factory->createQuery(
167+
$factory->selector('nt:file'),
168+
$factory->orConstraint(
169+
$factory->andConstraint(
170+
$factory->comparison(
171+
$factory->propertyValue('prop1', 'sel1'),
172+
Constants::JCR_OPERATOR_EQUAL_TO,
173+
$factory->literal('1')
174+
),
175+
$factory->comparison(
176+
$factory->propertyValue('prop2', 'sel1'),
177+
Constants::JCR_OPERATOR_EQUAL_TO,
178+
$factory->literal('2')
179+
)
180+
),
181+
$factory->comparison(
182+
$factory->propertyValue('prop3', 'sel1'),
183+
Constants::JCR_OPERATOR_EQUAL_TO,
184+
$factory->literal('3')
185+
)
186+
),
187+
array(),
188+
array()
189+
);
190+
191+
$queries['6.7.12.Constraint.Precedence.3'] = $factory->createQuery(
192+
$factory->selector('nt:file'),
193+
$factory->orConstraint(
194+
$factory->notConstraint(
195+
$factory->comparison(
196+
$factory->propertyValue('prop1', 'sel1'),
197+
Constants::JCR_OPERATOR_EQUAL_TO,
198+
$factory->literal('1')
199+
)
200+
),
201+
$factory->andConstraint(
202+
$factory->comparison(
203+
$factory->propertyValue('prop2', 'sel1'),
204+
Constants::JCR_OPERATOR_EQUAL_TO,
205+
$factory->literal('2')
206+
),
207+
$factory->notConstraint(
208+
$factory->comparison(
209+
$factory->propertyValue('prop3', 'sel1'),
210+
Constants::JCR_OPERATOR_EQUAL_TO,
211+
$factory->literal('3')
212+
)
213+
)
214+
)
215+
),
216+
array(),
217+
array()
218+
);
219+
220+
$queries['6.7.12.Constraint.Precedence.4'] = $factory->createQuery(
221+
$factory->selector('nt:file'),
222+
$factory->orConstraint(
223+
$factory->andConstraint(
224+
$factory->andConstraint(
225+
$factory->propertyExistence('prop1', 'sel1'),
226+
$factory->propertyExistence('prop2', 'sel1')
227+
),
228+
$factory->propertyExistence('prop3', 'sel1')
229+
),
230+
$factory->andConstraint(
231+
$factory->andConstraint(
232+
$factory->andConstraint(
233+
$factory->propertyExistence('prop4', 'sel1'),
234+
$factory->propertyExistence('prop5', 'sel1')
235+
),
236+
$factory->propertyExistence('prop6', 'sel1')
237+
),
238+
$factory->propertyExistence('prop7', 'sel1')
239+
)
240+
),
241+
array(),
242+
array()
243+
);
244+
245+
$queries['6.7.12.Constraint.Precedence.5'] = $factory->createQuery(
246+
$factory->selector('nt:file'),
247+
$factory->orConstraint(
248+
$factory->andConstraint(
249+
$factory->notConstraint(
250+
$factory->propertyExistence('prop1', 'sel1')
251+
),
252+
$factory->notConstraint(
253+
$factory->notConstraint(
254+
$factory->propertyExistence('prop2', 'sel1')
255+
)
256+
)
257+
),
258+
$factory->andConstraint(
259+
$factory->notConstraint(
260+
$factory->comparison(
261+
$factory->propertyValue('prop3', 'sel1'),
262+
Constants::JCR_OPERATOR_EQUAL_TO,
263+
$factory->literal('hello')
264+
)
265+
),
266+
$factory->comparison(
267+
$factory->propertyValue('prop4', 'sel1'),
268+
Constants::JCR_OPERATOR_NOT_EQUAL_TO,
269+
$factory->literal('hello')
270+
)
271+
)
272+
),
273+
array(),
274+
array()
275+
);
276+
138277
/**
139278
* 6.7.13. AndConstraint
140279
*/

tests/06_Query/QOM/Sql2TestQueries.php

+35
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,41 @@ public static function getQueries() {
4646
*/
4747
$queries['6.7.11.DescendantNodeJoinCondition'] = 'SELECT * FROM [nt:file] INNER JOIN [nt:folder] ON ISDESCENDANTNODE(descendant, ancestor)';
4848

49+
/**
50+
* 6.7.12. Constraint (operator precedence)
51+
*/
52+
$queries['6.7.12.Constraint.Precedence.1'] = array(
53+
'SELECT * FROM [nt:file] WHERE sel1.prop1 = \'1\' OR sel1.prop2 = \'2\' AND sel1.prop3 = \'3\'',
54+
'SELECT * FROM [nt:file] WHERE (sel1.prop1 = \'1\' OR (sel1.prop2 = \'2\' AND sel1.prop3 = \'3\'))',
55+
);
56+
$queries['6.7.12.Constraint.Precedence.2'] = array(
57+
'SELECT * FROM [nt:file] WHERE sel1.prop1 = \'1\' AND sel1.prop2 = \'2\' OR sel1.prop3 = \'3\'',
58+
'SELECT * FROM [nt:file] WHERE ((sel1.prop1 = \'1\' AND sel1.prop2 = \'2\') OR sel1.prop3 = \'3\')',
59+
);
60+
61+
$queries['6.7.12.Constraint.Precedence.3'] = array(
62+
'SELECT * FROM [nt:file] WHERE NOT sel1.prop1 = \'1\' OR sel1.prop2 = \'2\' AND NOT sel1.prop3 = \'3\'',
63+
'SELECT * FROM [nt:file] WHERE (NOT sel1.prop1 = \'1\' OR (sel1.prop2 = \'2\' AND NOT sel1.prop3 = \'3\'))',
64+
);
65+
66+
$queries['6.7.12.Constraint.Precedence.4'] = array(
67+
'SELECT * FROM [nt:file] WHERE
68+
sel1.prop1 IS NOT NULL AND sel1.prop2 IS NOT NULL
69+
AND sel1.prop3 IS NOT NULL
70+
OR sel1.prop4 IS NOT NULL AND sel1.prop5 IS NOT NULL
71+
AND sel1.prop6 IS NOT NULL AND sel1.prop7 IS NOT NULL',
72+
73+
'SELECT * FROM [nt:file] WHERE (((sel1.prop1 IS NOT NULL AND sel1.prop2 IS NOT NULL) AND sel1.prop3 IS NOT NULL) OR (((sel1.prop4 IS NOT NULL AND sel1.prop5 IS NOT NULL) AND sel1.prop6 IS NOT NULL) AND sel1.prop7 IS NOT NULL))',
74+
);
75+
76+
$queries['6.7.12.Constraint.Precedence.5'] = array(
77+
'SELECT * FROM [nt:file] WHERE
78+
NOT sel1.prop1 IS NOT NULL AND NOT NOT sel1.prop2 IS NOT NULL
79+
OR NOT sel1.prop3 = \'hello\' AND sel1.prop4 <> \'hello\'',
80+
81+
'SELECT * FROM [nt:file] WHERE ((NOT sel1.prop1 IS NOT NULL AND NOT NOT sel1.prop2 IS NOT NULL) OR (NOT sel1.prop3 = \'hello\' AND sel1.prop4 <> \'hello\'))',
82+
);
83+
4984
/**
5085
* 6.7.13. AndConstraint
5186
*/

0 commit comments

Comments
 (0)