diff --git a/fixtures/general/query.xml b/fixtures/general/query.xml index 2497f8fe..9784ebcd 100644 --- a/fixtures/general/query.xml +++ b/fixtures/general/query.xml @@ -8,15 +8,20 @@ xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" - sv:name="queryNode"> + sv:name="tests_general_query"> + + nt:unstructured + - - nt:query - - - JCR-SQL2 - - - SELECT * FROM [nt:file] WHERE [nt:file].[jcr:mimeType] = "text/plain" - - + + + nt:query + + + JCR-SQL2 + + + SELECT * FROM [nt:file] WHERE [nt:file].[jcr:mimeType] = "text/plain" + + + \ No newline at end of file diff --git a/tests/04_Connecting/RepositoryFactoryTest.php b/tests/04_Connecting/RepositoryFactoryTest.php index 0aa7bdf0..4f9b3eb6 100644 --- a/tests/04_Connecting/RepositoryFactoryTest.php +++ b/tests/04_Connecting/RepositoryFactoryTest.php @@ -1,6 +1,8 @@ getRepositoryFactoryClass(); + /** @var $factory RepositoryFactoryInterface */ $factory = new $class; $repo = $factory->getRepository(self::$loader->getRepositoryFactoryParameters()); $this->assertInstanceOf('PHPCR\RepositoryInterface', $repo); diff --git a/tests/06_Query/QueryBaseCase.php b/tests/06_Query/QueryBaseCase.php index f68223b6..3b7777d6 100644 --- a/tests/06_Query/QueryBaseCase.php +++ b/tests/06_Query/QueryBaseCase.php @@ -38,7 +38,14 @@ public function setUp() { parent::setUp(); - $this->query = $this->sharedFixture['qm']->createQuery("SELECT * FROM [nt:folder]", \PHPCR\Query\QueryInterface::JCR_SQL2); + $this->query = $this->sharedFixture['qm']->createQuery(" + SELECT * + FROM [nt:folder] + WHERE ISDESCENDANTNODE([/tests_general_base]) + OR ISSAMENODE([/tests_general_base]) + ", + \PHPCR\Query\QueryInterface::JCR_SQL2 + ); // the query result is not ordered, but these are the nodes that are to be expected in any order $this->resultPaths = array("/tests_general_base", diff --git a/tests/06_Query/QueryManagerTest.php b/tests/06_Query/QueryManagerTest.php index 58d92264..45c646d5 100644 --- a/tests/06_Query/QueryManagerTest.php +++ b/tests/06_Query/QueryManagerTest.php @@ -17,12 +17,12 @@ public static function setupBeforeClass($fixture = 'general/query') public function testCreateQuerySql2() { - $ret = $this->sharedFixture['qm']->createQuery("SELECT * FROM [nt:folder]", \PHPCR\Query\QueryInterface::JCR_SQL2); + $ret = $this->sharedFixture['qm']->createQuery("SELECT * FROM [nt:folder] WHERE ISCHILDNODE('/tests_general/base')", \PHPCR\Query\QueryInterface::JCR_SQL2); $this->assertInstanceOf('PHPCR\Query\QueryInterface', $ret); } /** - * @expectedException PHPCR\Query\InvalidQueryException + * @expectedException \PHPCR\Query\InvalidQueryException */ public function testCreateQueryInvalid() { @@ -31,7 +31,7 @@ public function testCreateQueryInvalid() public function testGetQuery() { - $qnode = $this->sharedFixture['session']->getRootNode()->getNode('queryNode'); + $qnode = $this->sharedFixture['session']->getNode('/tests_general_query/queryNode'); $this->assertInstanceOf('PHPCR\NodeInterface', $qnode); $query = $this->sharedFixture['qm']->getQuery($qnode); @@ -39,7 +39,7 @@ public function testGetQuery() } /** - * @expectedException PHPCR\Query\InvalidQueryException + * @expectedException \PHPCR\Query\InvalidQueryException */ public function testGetQueryInvalid() { diff --git a/tests/06_Query/QueryObjectQOMTest.php b/tests/06_Query/QueryObjectQOMTest.php index 1a603c22..d8e20c0e 100644 --- a/tests/06_Query/QueryObjectQOMTest.php +++ b/tests/06_Query/QueryObjectQOMTest.php @@ -14,9 +14,10 @@ class QueryObjectQOMTest extends QueryBaseCase { /** - * @var PHPCR\Query\QOM\QueryObjectManagerFactory + * @var \PHPCR\Query\QOM\QueryObjectModelFactoryInterface */ protected $factory; + /** @var \PHPCR\Query\QueryInterface */ protected $query; public function setUp() @@ -30,7 +31,10 @@ public function setUp() } $source = $this->factory->selector('nt:folder','data'); - $constraint = null; + $constraint = $this->factory->orConstraint( + $this->factory->descendantNode('/tests_general_base'), + $this->factory->sameNode('/tests_general_base') + ); $orderings = array(); $columns = array(); @@ -46,7 +50,7 @@ public function testExecute() } /** - * @expectedException PHPCR\Query\InvalidQueryException + * @expectedException \PHPCR\Query\InvalidQueryException * * the doc claims there would just be a PHPCR\RepositoryException * it makes sense that there is a InvalidQueryException @@ -64,7 +68,8 @@ public function testExecuteInvalid() public function testGetStatement() { - $this->assertEquals('SELECT * FROM [nt:folder] AS data', $this->query->getStatement()); + $this->assertEquals('SELECT * FROM [nt:folder] AS data '. + 'WHERE (ISDESCENDANTNODE([/tests_general_base]) OR ISSAMENODE([/tests_general_base]))', $this->query->getStatement()); } /** @@ -78,7 +83,7 @@ public function testGetLanguage() /** * a transient query has no stored query path - * @expectedException PHPCR\ItemNotFoundException + * @expectedException \PHPCR\ItemNotFoundException */ public function testGetStoredQueryPathItemNotFound() { @@ -90,7 +95,7 @@ public function testStoreAsNode() { $qstr = '//idExample[jcr:mimeType="text/plain"]'; $query = $this->sharedFixture['qm']->createQuery($qstr, 'xpath'); - $query->storeAsNode('/queryNode'); + $query->storeAsNode('/test_query/queryNode'); $this->sharedFixture['session']->save(); } */ diff --git a/tests/06_Query/QueryObjectSql2Test.php b/tests/06_Query/QueryObjectSql2Test.php index 3c431faa..96adeaca 100644 --- a/tests/06_Query/QueryObjectSql2Test.php +++ b/tests/06_Query/QueryObjectSql2Test.php @@ -114,7 +114,7 @@ public function testGetStoredQueryPath() //same as QueryManager::testGetQuery $p = $query->getStoredQueryPath(); - $this->assertEquals('/queryNode', $p); + $this->assertEquals('/tests_general_query/queryNode', $p); } catch(exception $e) { //FIXME: finally? $this->sharedFixture['ie']->import('general/base'); diff --git a/tests/06_Query/QueryResultsTest.php b/tests/06_Query/QueryResultsTest.php index 8bd66ffb..b16cedb8 100644 --- a/tests/06_Query/QueryResultsTest.php +++ b/tests/06_Query/QueryResultsTest.php @@ -103,6 +103,8 @@ public function testIterateOverQueryResult() public function testReadPropertyContentFromResults() { $seekName = '/tests_general_base/multiValueProperty'; + + $this->assertTrue(count($this->qr->getNodes()) > 0); foreach ($this->qr->getNodes() as $path => $node) { if ($seekName == $path) break; } @@ -117,8 +119,12 @@ public function testReadPropertyContentFromResults() public function testCompareNumberFields() { - $query = $this->sharedFixture['qm']->createQuery( - 'SELECT data.longNumberToCompare FROM [nt:unstructured] AS data WHERE data.longNumberToCompare > 2', + $query = $this->sharedFixture['qm']->createQuery(' + SELECT data.longNumberToCompare + FROM [nt:unstructured] AS data + WHERE data.longNumberToCompare > 2 + AND ISDESCENDANTNODE([/tests_general_base]) + ', \PHPCR\Query\QueryInterface::JCR_SQL2 ); $result = $query->execute(); diff --git a/tests/06_Query/QuerySql2OperationsTest.php b/tests/06_Query/QuerySql2OperationsTest.php index 87520c44..d892de1b 100644 --- a/tests/06_Query/QuerySql2OperationsTest.php +++ b/tests/06_Query/QuerySql2OperationsTest.php @@ -13,8 +13,12 @@ class QuerySql2OperationsTest extends QueryBaseCase public function testQueryField() { /** @var $query QueryInterface */ - $query = $this->sharedFixture['qm']->createQuery( - 'SELECT foo FROM [nt:unstructured] WHERE foo = "bar"', + $query = $this->sharedFixture['qm']->createQuery(' + SELECT foo + FROM [nt:unstructured] + WHERE foo = "bar" + AND (ISSAMENODE([/tests_general_base]) OR ISDESCENDANTNODE([/tests_general_base])) + ', QueryInterface::JCR_SQL2 ); @@ -37,8 +41,11 @@ public function testQueryField() public function testQueryFieldSomenull() { /** @var $query QueryInterface */ - $query = $this->sharedFixture['qm']->createQuery( - 'SELECT foo FROM [nt:unstructured]', + $query = $this->sharedFixture['qm']->createQuery(' + SELECT foo + FROM [nt:unstructured] + WHERE ISDESCENDANTNODE([/tests_general_base]) + ', QueryInterface::JCR_SQL2 ); @@ -50,21 +57,25 @@ public function testQueryFieldSomenull() $vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null); } $this->assertContains('bar', $vals); - $this->assertEquals(10, count($vals)); + $this->assertEquals(9, count($vals)); $vals = array(); foreach ($result->getRows() as $row) { $vals[] = $row->getValue('foo'); } $this->assertContains('bar', $vals); - $this->assertEquals(10, count($vals)); + $this->assertEquals(9, count($vals)); } public function testQueryFieldSelector() { /** @var $query QueryInterface */ - $query = $this->sharedFixture['qm']->createQuery( - 'SELECT data.foo FROM [nt:unstructured] AS data WHERE data.foo = "bar"', + $query = $this->sharedFixture['qm']->createQuery(' + SELECT data.foo + FROM [nt:unstructured] AS data + WHERE data.foo = "bar" + AND ISDESCENDANTNODE([/tests_general_base]) + ', QueryInterface::JCR_SQL2 ); @@ -81,13 +92,14 @@ public function testQueryFieldSelector() public function testQueryJoin() { /** @var $query QueryInterface */ - $query = $this->sharedFixture['qm']->createQuery( - 'SELECT content.longNumber - FROM [nt:file] AS file - INNER JOIN [nt:unstructured] AS content - ON ISDESCENDANTNODE(content, file) - - WHERE content.longNumber = 999', + $query = $this->sharedFixture['qm']->createQuery(' + SELECT content.longNumber + FROM [nt:file] AS file + INNER JOIN [nt:unstructured] AS content + ON ISDESCENDANTNODE(content, file) + WHERE content.longNumber = 999 + AND ISDESCENDANTNODE(file, [/tests_general_base]) + ', QueryInterface::JCR_SQL2 ); @@ -128,10 +140,12 @@ public function testQueryJoinReference() public function testQueryOrder() { /** @var $query QueryInterface */ - $query = $this->sharedFixture['qm']->createQuery( - 'SELECT data.zeronumber - FROM [nt:unstructured] AS data - ORDER BY data.zeronumber', + $query = $this->sharedFixture['qm']->createQuery(' + SELECT data.zeronumber + FROM [nt:unstructured] AS data + WHERE ISDESCENDANTNODE([/tests_general_base]) + ORDER BY data.zeronumber + ', QueryInterface::JCR_SQL2 ); @@ -143,17 +157,18 @@ public function testQueryOrder() $vals[] = $row->getValue('data.zeronumber'); } // rows that do not have that field are null. empty is before fields with values - $this->assertEquals(array(null, null, null, null, null, null, null, null, null, 0), $vals); + $this->assertEquals(array(null, null, null, null, null, null, null, null, 0), $vals); } public function testQueryMultiValuedProperty() { /** @var $query QueryInterface */ - $query = $this->sharedFixture['qm']->createQuery( - 'SELECT data.tags + $query = $this->sharedFixture['qm']->createQuery(' + SELECT data.tags FROM [nt:unstructured] AS data WHERE data.tags = "foo" - AND data.tags = "bar" + AND data.tags = "bar" + AND ISDESCENDANTNODE([/tests_general_base]) ', QueryInterface::JCR_SQL2 ); diff --git a/tests/06_Query/Sql1/QueryOperationsTest.php b/tests/06_Query/Sql1/QueryOperationsTest.php index f0ae02b9..6c3be699 100644 --- a/tests/06_Query/Sql1/QueryOperationsTest.php +++ b/tests/06_Query/Sql1/QueryOperationsTest.php @@ -37,8 +37,11 @@ public function testQueryField() public function testQueryFieldSomenull() { /** @var $query QueryInterface */ - $query = $this->sharedFixture['qm']->createQuery( - 'SELECT foo FROM nt:unstructured', + $query = $this->sharedFixture['qm']->createQuery(' + SELECT foo + FROM nt:unstructured + WHERE jcr:path LIKE \'/tests_general_base/%\' + ', QueryInterface::SQL ); @@ -50,14 +53,14 @@ public function testQueryFieldSomenull() $vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null); } $this->assertContains('bar', $vals); - $this->assertEquals(10, count($vals)); + $this->assertEquals(9, count($vals)); $vals = array(); foreach ($result->getRows() as $row) { $vals[] = $row->getValue('foo'); } $this->assertContains('bar', $vals); - $this->assertEquals(10, count($vals)); + $this->assertEquals(9, count($vals)); } public function testQueryOrder() @@ -66,6 +69,7 @@ public function testQueryOrder() $query = $this->sharedFixture['qm']->createQuery( 'SELECT zeronumber FROM nt:unstructured + WHERE jcr:path LIKE \'/tests_general_base/%\' ORDER BY zeronumber', QueryInterface::SQL ); @@ -78,7 +82,7 @@ public function testQueryOrder() $vals[] = $row->getValue('zeronumber'); } // rows that do not have that field are null. empty is before fields with values - $this->assertEquals(array(null, null, null, null, null, null, null, null, null, 0), $vals); + $this->assertEquals(array(null, null, null, null, null, null, null, null, 0), $vals); } } diff --git a/tests/06_Query/XPath/QueryOperationsTest.php b/tests/06_Query/XPath/QueryOperationsTest.php index 0d32159f..28ab1831 100644 --- a/tests/06_Query/XPath/QueryOperationsTest.php +++ b/tests/06_Query/XPath/QueryOperationsTest.php @@ -14,7 +14,7 @@ public function testQueryField() { /** @var $query QueryInterface */ $query = $this->sharedFixture['qm']->createQuery( - '//element(*,nt:unstructured)[@foo = "bar"]/@foo', + '/jcr:root/tests_general_base//element(*,nt:unstructured)[@foo = "bar"]/@foo', QueryInterface::XPATH ); @@ -38,7 +38,7 @@ public function testQueryFieldSomenull() { /** @var $query QueryInterface */ $query = $this->sharedFixture['qm']->createQuery( - '//element(*,nt:unstructured)/@foo', + '/jcr:root/tests_general_base//element(*,nt:unstructured)/@foo', QueryInterface::XPATH ); @@ -50,21 +50,21 @@ public function testQueryFieldSomenull() $vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null); } $this->assertContains('bar', $vals); - $this->assertEquals(10, count($vals)); + $this->assertEquals(9, count($vals)); $vals = array(); foreach ($result->getRows() as $row) { $vals[] = $row->getValue('foo'); } $this->assertContains('bar', $vals); - $this->assertEquals(10, count($vals)); + $this->assertEquals(9, count($vals)); } public function testQueryOrder() { /** @var $query QueryInterface */ $query = $this->sharedFixture['qm']->createQuery( - '//element(*, nt:unstructured)/@zeronumber order by @zeronumber', + '/jcr:root/tests_general_base//element(*, nt:unstructured)/@zeronumber order by @zeronumber', QueryInterface::XPATH ); @@ -76,7 +76,7 @@ public function testQueryOrder() $vals[] = $row->getValue('zeronumber'); } // rows that do not have that field are null. empty is before fields with values - $this->assertEquals(array(null, null, null, null, null, null, null, null, null, 0), $vals); + $this->assertEquals(array(null, null, null, null, null, null, null, null, 0), $vals); } }