Skip to content

Added queries testing nested joins #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/Query/QOM/QomTestQueries.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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