Skip to content

Commit

Permalink
Added queries testing nested joins
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Snijders authored and dbu committed Feb 12, 2016
1 parent 4816315 commit 1087d70
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/Query/QOM/QomTestQueries.php
Expand Up @@ -78,6 +78,23 @@ public static function getQueries(QueryObjectModelFactoryInterface $factory)
array(),
array());

// SELECT * FROM [nt:folder] AS folder INNER JOIN [nt:file] AS file ON folder.[prop2]=file.[prop1] INNER JOIN [nt:folder] AS folder2 ON file.[prop1]=folder.[prop2]
$queries['6.7.8.EquiJoin.NestedJoin'] =
$factory->createQuery(
$factory->join(
$factory->join(
$factory->selector('folder', 'nt:folder'),
$factory->selector('file', 'nt:file'),
Constants::JCR_JOIN_TYPE_INNER,
$factory->equiJoinCondition('folder', 'prop2', 'file', 'prop1')
),
$factory->selector('folder2', 'nt:folder'),
Constants::JCR_JOIN_TYPE_INNER,
$factory->equiJoinCondition('file', 'prop1', 'folder', 'prop2')),
null,
array(),
array());

/*
* 6.7.9. SameNodeJoinCondition
*/
Expand Down
4 changes: 4 additions & 0 deletions tests/Query/QOM/Sql2TestQueries.php
Expand Up @@ -44,6 +44,10 @@ public static function getQueries()
'SELECT * FROM [nt:file] AS file RIGHT OUTER JOIN [nt:folder] AS folder ON file.prop1=folder.prop2',
'SELECT * FROM [nt:file] AS file RIGHT OUTER JOIN [nt:folder] AS folder ON file.[prop1]=folder.[prop2]',
);
$queries['6.7.8.EquiJoin.NestedJoin'] = array(
'SELECT * FROM [nt:folder] AS folder INNER JOIN [nt:file] AS file ON folder.[prop2]=file.[prop1] INNER JOIN [nt:folder] AS folder2 ON file.[prop1]=folder.[prop2]',
'SELECT * FROM [nt:folder] AS folder INNER JOIN [nt:file] AS file ON folder.[prop2]=file.[prop1] INNER JOIN [nt:folder] AS folder2 ON file.[prop1]=folder.[prop2]',
);

/*
* 6.7.9. SameNodeJoinCondition
Expand Down
27 changes: 27 additions & 0 deletions tests/Query/QuerySql2OperationsTest.php
Expand Up @@ -190,6 +190,33 @@ public function testQueryJoinWithAlias()
$this->assertEquals(array(999), $vals);
}

public function testQueryJoinNested()
{
/** @var $query QueryInterface */
$query = $this->sharedFixture['qm']->createQuery('
SELECT content.longNumber
FROM [nt:folder] AS folder
INNER JOIN [nt:file] AS file
ON ISDESCENDANTNODE(file, folder)
INNER JOIN [nt:unstructured] AS content
ON ISDESCENDANTNODE(content, file)
WHERE content.longNumber = 999
AND ISDESCENDANTNODE(folder, [/])
',
QueryInterface::JCR_SQL2
);

$this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
$result = $query->execute();
$this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
$vals = array();

foreach ($result->getRows() as $row) {
$vals[] = $row->getValue('content.longNumber');
}
$this->assertEquals(array(999), $vals);
}

public function testQueryLeftJoin()
{
/** @var $query QueryInterface */
Expand Down

0 comments on commit 1087d70

Please sign in to comment.