1+ <?php
2+ namespace PHPCR \Tests \Util \QOM ;
3+
4+
5+ use Jackalope \Factory ;
6+ use Jackalope \Query \QOM \QueryObjectModelFactory ;
7+ use PHPCR \Query \QOM \QueryObjectModelFactoryInterface ;
8+ use PHPCR \Util \QOM \Sql2ToQomQueryConverter ;
9+
10+ class Sql2ToQomQueryConverterTest extends \PHPUnit_Framework_TestCase
11+ {
12+ /** @var QueryObjectModelFactoryInterface */
13+ protected $ factory ;
14+
15+ /** @var Sql2ToQomQueryConverter */
16+ protected $ converter ;
17+
18+ public function setUp ()
19+ {
20+ $ this ->factory = new QueryObjectModelFactory (new Factory ());
21+ $ this ->converter = new Sql2ToQomQueryConverter ($ this ->factory );
22+ }
23+
24+ public function testPropertyComparison ()
25+ {
26+ $ qom = $ this ->converter ->parse ('
27+ SELECT data
28+ FROM [nt:unstructured] AS data
29+ WHERE data.property = "String with spaces"
30+ ' );
31+
32+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\ComparisonInterface ' , $ qom ->getConstraint ());
33+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\PropertyValueInterface ' , $ qom ->getConstraint ()->getOperand1 ());
34+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\LiteralInterface ' , $ qom ->getConstraint ()->getOperand2 ());
35+
36+ $ this ->assertEquals ('property ' , $ qom ->getConstraint ()->getOperand1 ()->getPropertyName ());
37+ $ this ->assertEquals ('String with spaces ' , $ qom ->getConstraint ()->getOperand2 ()->getLiteralValue ());
38+ }
39+
40+ public function testPropertyExistence ()
41+ {
42+ $ qom = $ this ->converter ->parse ('
43+ SELECT data
44+ FROM [nt:unstructured] AS data
45+ WHERE data.property IS NULL
46+ ' );
47+
48+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\NotInterface ' , $ qom ->getConstraint ());
49+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\PropertyExistenceInterface ' , $ qom ->getConstraint ()->getConstraint ());
50+
51+ $ qom = $ this ->converter ->parse ('
52+ SELECT data
53+ FROM [nt:unstructured] AS data
54+ WHERE data.property IS NOT NULL
55+ ' );
56+
57+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\PropertyExistenceInterface ' , $ qom ->getConstraint ());
58+ }
59+
60+ public function testComposedConstraint ()
61+ {
62+ $ qom = $ this ->converter ->parse ('
63+ SELECT data
64+ FROM [nt:unstructured] AS data
65+ WHERE data.property = "foo"
66+ OR data.property = "bar"
67+ ' );
68+
69+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\OrInterface ' , $ qom ->getConstraint ());
70+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\ComparisonInterface ' , $ qom ->getConstraint ()->getConstraint1 ());
71+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\ComparisonInterface ' , $ qom ->getConstraint ()->getConstraint2 ());
72+
73+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\PropertyValueInterface ' , $ qom ->getConstraint ()->getConstraint1 ()->getOperand1 ());
74+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\LiteralInterface ' , $ qom ->getConstraint ()->getConstraint1 ()->getOperand2 ());
75+ }
76+
77+ public function testJoinConstraint ()
78+ {
79+ $ qom = $ this ->converter ->parse ('
80+ SELECT data
81+ FROM [nt:unstructured] AS data
82+ JOIN [nt:folder] AS folder ON data.folder = folder.[jcr:uuid]
83+ ' );
84+
85+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\JoinInterface ' , $ qom ->getSource ());
86+ $ this ->assertInstanceOf ('PHPCR\Query\QOM\EquiJoinConditionInterface ' , $ qom ->getSource ()->getJoinCondition ());
87+ $ this ->assertEquals (\PHPCR \Query \QOM \QueryObjectModelConstantsInterface::JCR_JOIN_TYPE_INNER , $ qom ->getSource ()->getJoinType ());
88+ }
89+ }
0 commit comments