Skip to content
Merged
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
27 changes: 16 additions & 11 deletions fixtures/general/query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:unstructured</sv:value>
</sv:property>

<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:query</sv:value>
</sv:property>
<sv:property sv:name="jcr:language" sv:type="String">
<sv:value>JCR-SQL2</sv:value>
</sv:property>
<sv:property sv:name="jcr:statement" sv:type="String">
<sv:value>SELECT * FROM [nt:file] WHERE [nt:file].[jcr:mimeType] = "text/plain"</sv:value>
</sv:property>
</sv:node>
<sv:node sv:name="queryNode">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
<sv:value>nt:query</sv:value>
</sv:property>
<sv:property sv:name="jcr:language" sv:type="String">
<sv:value>JCR-SQL2</sv:value>
</sv:property>
<sv:property sv:name="jcr:statement" sv:type="String">
<sv:value>SELECT * FROM [nt:file] WHERE [nt:file].[jcr:mimeType] = "text/plain"</sv:value>
</sv:property>
</sv:node>
</sv:node>
3 changes: 3 additions & 0 deletions tests/04_Connecting/RepositoryFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace PHPCR\Tests\Connecting;

use PHPCR\RepositoryFactoryInterface;

require_once(__DIR__ . '/../../inc/BaseCase.php');

class RepositoryFactoryTest extends \PHPCR\Test\BaseCase
Expand All @@ -15,6 +17,7 @@ public static function setupBeforeClass($fixtures = false)
public function testRepositoryFactory()
{
$class = self::$loader->getRepositoryFactoryClass();
/** @var $factory RepositoryFactoryInterface */
$factory = new $class;
$repo = $factory->getRepository(self::$loader->getRepositoryFactoryParameters());
$this->assertInstanceOf('PHPCR\RepositoryInterface', $repo);
Expand Down
9 changes: 8 additions & 1 deletion tests/06_Query/QueryBaseCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions tests/06_Query/QueryManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -31,15 +31,15 @@ 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);
$this->assertInstanceOf('PHPCR\Query\QueryInterface', $query);
}

/**
* @expectedException PHPCR\Query\InvalidQueryException
* @expectedException \PHPCR\Query\InvalidQueryException
*/
public function testGetQueryInvalid()
{
Expand Down
17 changes: 11 additions & 6 deletions tests/06_Query/QueryObjectQOMTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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();

Expand All @@ -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
Expand All @@ -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());
}

/**
Expand All @@ -78,7 +83,7 @@ public function testGetLanguage()

/**
* a transient query has no stored query path
* @expectedException PHPCR\ItemNotFoundException
* @expectedException \PHPCR\ItemNotFoundException
*/
public function testGetStoredQueryPathItemNotFound()
{
Expand All @@ -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();
}
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/06_Query/QueryObjectSql2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
10 changes: 8 additions & 2 deletions tests/06_Query/QueryResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down
61 changes: 38 additions & 23 deletions tests/06_Query/QuerySql2OperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand All @@ -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
);

Expand All @@ -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
);

Expand All @@ -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
);

Expand Down Expand Up @@ -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
);

Expand All @@ -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
);
Expand Down
14 changes: 9 additions & 5 deletions tests/06_Query/Sql1/QueryOperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand All @@ -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()
Expand All @@ -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
);
Expand All @@ -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);
}

}
Loading