From 1087d70288cb5aa7015d53f3d0abfdbefcf61896 Mon Sep 17 00:00:00 2001 From: Richard Snijders Date: Fri, 12 Feb 2016 09:41:26 +0100 Subject: [PATCH] Added queries testing nested joins --- tests/Query/QOM/QomTestQueries.php | 17 ++++++++++++++++ tests/Query/QOM/Sql2TestQueries.php | 4 ++++ tests/Query/QuerySql2OperationsTest.php | 27 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/tests/Query/QOM/QomTestQueries.php b/tests/Query/QOM/QomTestQueries.php index 054454e4..0818f7ba 100644 --- a/tests/Query/QOM/QomTestQueries.php +++ b/tests/Query/QOM/QomTestQueries.php @@ -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 */ diff --git a/tests/Query/QOM/Sql2TestQueries.php b/tests/Query/QOM/Sql2TestQueries.php index 1754feb8..66f61165 100644 --- a/tests/Query/QOM/Sql2TestQueries.php +++ b/tests/Query/QOM/Sql2TestQueries.php @@ -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 diff --git a/tests/Query/QuerySql2OperationsTest.php b/tests/Query/QuerySql2OperationsTest.php index a883996b..a7e28f0a 100644 --- a/tests/Query/QuerySql2OperationsTest.php +++ b/tests/Query/QuerySql2OperationsTest.php @@ -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 */