Skip to content

Commit bd8b7e0

Browse files
committed
Merge pull request #102 from wjzijderveld/more-join-tests
Added 2 tests, LEFT OUTER JOIN and RIGHT OUTER JOIN
2 parents 5e5fdd2 + 9959589 commit bd8b7e0

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/06_Query/QuerySql2OperationsTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,68 @@ public function testQueryJoin()
114114
$this->assertEquals(array(999), $vals);
115115
}
116116

117+
public function testQueryLeftJoin()
118+
{
119+
/** @var $query QueryInterface */
120+
$query = $this->sharedFixture['qm']->createQuery(
121+
'SELECT file.[jcr:name], target.longNumberToCompare
122+
FROM [nt:file] AS file
123+
LEFT OUTER JOIN [nt:unstructured] AS target
124+
ON ISDESCENDANTNODE(target, file)
125+
',
126+
QueryInterface::JCR_SQL2
127+
);
128+
129+
$this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
130+
$result = $query->execute();
131+
$this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
132+
$vals = array();
133+
foreach ($result->getRows() as $row) {
134+
$vals[basename($row->getPath('file'))] = $row->getValue('target.longNumberToCompare');
135+
}
136+
137+
// We get 9 results (idExample comes back multiple times because of the join)
138+
$this->assertCount(9, $result->getRows());
139+
$this->assertEquals(array(
140+
'index.txt' => null,
141+
'idExample' => null,
142+
'numberPropertyNode' => null,
143+
'NumberPropertyNodeToCompare1' => 2,
144+
'NumberPropertyNodeToCompare2' => 10,
145+
), $vals);
146+
}
147+
148+
public function testQueryRightJoin()
149+
{
150+
/** @var $query QueryInterface */
151+
$query = $this->sharedFixture['qm']->createQuery(
152+
'SELECT file.[jcr:name], target.stringToCompare
153+
FROM [nt:unstructured] AS target
154+
RIGHT OUTER JOIN [nt:file] AS file
155+
ON ISDESCENDANTNODE(target, file)
156+
',
157+
QueryInterface::JCR_SQL2
158+
);
159+
160+
$this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
161+
$result = $query->execute();
162+
$this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
163+
$vals = array();
164+
foreach ($result->getRows() as $row) {
165+
$vals[basename($row->getPath('file'))] = $row->getValue('target.stringToCompare');
166+
}
167+
168+
// We get 9 results (idExample comes back multiple times because of the join)
169+
$this->assertCount(9, $result->getRows());
170+
$this->assertEquals(array(
171+
'index.txt' => null,
172+
'idExample' => null,
173+
'numberPropertyNode' => null,
174+
'NumberPropertyNodeToCompare1' => '2',
175+
'NumberPropertyNodeToCompare2' => '10',
176+
), $vals);
177+
}
178+
117179
public function testQueryJoinReference()
118180
{
119181
/** @var $query QueryInterface */

0 commit comments

Comments
 (0)