Skip to content

Commit 640cebd

Browse files
committed
Merge pull request #98 from phpcr/crx-tests
[WIP] adjust for crx which has the users in the same workspace
2 parents 3d1f6d6 + 5d5bbde commit 640cebd

File tree

10 files changed

+104
-59
lines changed

10 files changed

+104
-59
lines changed

fixtures/general/query.xml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@
88
xmlns:jcr="http://www.jcp.org/jcr/1.0"
99
xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
1010

11-
sv:name="queryNode">
11+
sv:name="tests_general_query">
12+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
13+
<sv:value>nt:unstructured</sv:value>
14+
</sv:property>
1215

13-
<sv:property sv:name="jcr:primaryType" sv:type="Name">
14-
<sv:value>nt:query</sv:value>
15-
</sv:property>
16-
<sv:property sv:name="jcr:language" sv:type="String">
17-
<sv:value>JCR-SQL2</sv:value>
18-
</sv:property>
19-
<sv:property sv:name="jcr:statement" sv:type="String">
20-
<sv:value>SELECT * FROM [nt:file] WHERE [nt:file].[jcr:mimeType] = "text/plain"</sv:value>
21-
</sv:property>
22-
</sv:node>
16+
<sv:node sv:name="queryNode">
17+
<sv:property sv:name="jcr:primaryType" sv:type="Name">
18+
<sv:value>nt:query</sv:value>
19+
</sv:property>
20+
<sv:property sv:name="jcr:language" sv:type="String">
21+
<sv:value>JCR-SQL2</sv:value>
22+
</sv:property>
23+
<sv:property sv:name="jcr:statement" sv:type="String">
24+
<sv:value>SELECT * FROM [nt:file] WHERE [nt:file].[jcr:mimeType] = "text/plain"</sv:value>
25+
</sv:property>
26+
</sv:node>
27+
</sv:node>

tests/04_Connecting/RepositoryFactoryTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
namespace PHPCR\Tests\Connecting;
33

4+
use PHPCR\RepositoryFactoryInterface;
5+
46
require_once(__DIR__ . '/../../inc/BaseCase.php');
57

68
class RepositoryFactoryTest extends \PHPCR\Test\BaseCase
@@ -15,6 +17,7 @@ public static function setupBeforeClass($fixtures = false)
1517
public function testRepositoryFactory()
1618
{
1719
$class = self::$loader->getRepositoryFactoryClass();
20+
/** @var $factory RepositoryFactoryInterface */
1821
$factory = new $class;
1922
$repo = $factory->getRepository(self::$loader->getRepositoryFactoryParameters());
2023
$this->assertInstanceOf('PHPCR\RepositoryInterface', $repo);

tests/06_Query/QueryBaseCase.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ public function setUp()
3838
{
3939
parent::setUp();
4040

41-
$this->query = $this->sharedFixture['qm']->createQuery("SELECT * FROM [nt:folder]", \PHPCR\Query\QueryInterface::JCR_SQL2);
41+
$this->query = $this->sharedFixture['qm']->createQuery("
42+
SELECT *
43+
FROM [nt:folder]
44+
WHERE ISDESCENDANTNODE([/tests_general_base])
45+
OR ISSAMENODE([/tests_general_base])
46+
",
47+
\PHPCR\Query\QueryInterface::JCR_SQL2
48+
);
4249

4350
// the query result is not ordered, but these are the nodes that are to be expected in any order
4451
$this->resultPaths = array("/tests_general_base",

tests/06_Query/QueryManagerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ public static function setupBeforeClass($fixture = 'general/query')
1717

1818
public function testCreateQuerySql2()
1919
{
20-
$ret = $this->sharedFixture['qm']->createQuery("SELECT * FROM [nt:folder]", \PHPCR\Query\QueryInterface::JCR_SQL2);
20+
$ret = $this->sharedFixture['qm']->createQuery("SELECT * FROM [nt:folder] WHERE ISCHILDNODE('/tests_general/base')", \PHPCR\Query\QueryInterface::JCR_SQL2);
2121
$this->assertInstanceOf('PHPCR\Query\QueryInterface', $ret);
2222
}
2323

2424
/**
25-
* @expectedException PHPCR\Query\InvalidQueryException
25+
* @expectedException \PHPCR\Query\InvalidQueryException
2626
*/
2727
public function testCreateQueryInvalid()
2828
{
@@ -31,15 +31,15 @@ public function testCreateQueryInvalid()
3131

3232
public function testGetQuery()
3333
{
34-
$qnode = $this->sharedFixture['session']->getRootNode()->getNode('queryNode');
34+
$qnode = $this->sharedFixture['session']->getNode('/tests_general_query/queryNode');
3535
$this->assertInstanceOf('PHPCR\NodeInterface', $qnode);
3636

3737
$query = $this->sharedFixture['qm']->getQuery($qnode);
3838
$this->assertInstanceOf('PHPCR\Query\QueryInterface', $query);
3939
}
4040

4141
/**
42-
* @expectedException PHPCR\Query\InvalidQueryException
42+
* @expectedException \PHPCR\Query\InvalidQueryException
4343
*/
4444
public function testGetQueryInvalid()
4545
{

tests/06_Query/QueryObjectQOMTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ class QueryObjectQOMTest extends QueryBaseCase
1414
{
1515

1616
/**
17-
* @var PHPCR\Query\QOM\QueryObjectManagerFactory
17+
* @var \PHPCR\Query\QOM\QueryObjectModelFactoryInterface
1818
*/
1919
protected $factory;
20+
/** @var \PHPCR\Query\QueryInterface */
2021
protected $query;
2122

2223
public function setUp()
@@ -30,7 +31,10 @@ public function setUp()
3031
}
3132

3233
$source = $this->factory->selector('nt:folder','data');
33-
$constraint = null;
34+
$constraint = $this->factory->orConstraint(
35+
$this->factory->descendantNode('/tests_general_base'),
36+
$this->factory->sameNode('/tests_general_base')
37+
);
3438
$orderings = array();
3539
$columns = array();
3640

@@ -46,7 +50,7 @@ public function testExecute()
4650
}
4751

4852
/**
49-
* @expectedException PHPCR\Query\InvalidQueryException
53+
* @expectedException \PHPCR\Query\InvalidQueryException
5054
*
5155
* the doc claims there would just be a PHPCR\RepositoryException
5256
* it makes sense that there is a InvalidQueryException
@@ -64,7 +68,8 @@ public function testExecuteInvalid()
6468

6569
public function testGetStatement()
6670
{
67-
$this->assertEquals('SELECT * FROM [nt:folder] AS data', $this->query->getStatement());
71+
$this->assertEquals('SELECT * FROM [nt:folder] AS data '.
72+
'WHERE (ISDESCENDANTNODE([/tests_general_base]) OR ISSAMENODE([/tests_general_base]))', $this->query->getStatement());
6873
}
6974

7075
/**
@@ -78,7 +83,7 @@ public function testGetLanguage()
7883

7984
/**
8085
* a transient query has no stored query path
81-
* @expectedException PHPCR\ItemNotFoundException
86+
* @expectedException \PHPCR\ItemNotFoundException
8287
*/
8388
public function testGetStoredQueryPathItemNotFound()
8489
{
@@ -90,7 +95,7 @@ public function testStoreAsNode()
9095
{
9196
$qstr = '//idExample[jcr:mimeType="text/plain"]';
9297
$query = $this->sharedFixture['qm']->createQuery($qstr, 'xpath');
93-
$query->storeAsNode('/queryNode');
98+
$query->storeAsNode('/test_query/queryNode');
9499
$this->sharedFixture['session']->save();
95100
}
96101
*/

tests/06_Query/QueryObjectSql2Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testGetStoredQueryPath()
114114
//same as QueryManager::testGetQuery
115115

116116
$p = $query->getStoredQueryPath();
117-
$this->assertEquals('/queryNode', $p);
117+
$this->assertEquals('/tests_general_query/queryNode', $p);
118118
} catch(exception $e) {
119119
//FIXME: finally?
120120
$this->sharedFixture['ie']->import('general/base');

tests/06_Query/QueryResultsTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public function testIterateOverQueryResult()
103103
public function testReadPropertyContentFromResults()
104104
{
105105
$seekName = '/tests_general_base/multiValueProperty';
106+
107+
$this->assertTrue(count($this->qr->getNodes()) > 0);
106108
foreach ($this->qr->getNodes() as $path => $node) {
107109
if ($seekName == $path) break;
108110
}
@@ -117,8 +119,12 @@ public function testReadPropertyContentFromResults()
117119

118120
public function testCompareNumberFields()
119121
{
120-
$query = $this->sharedFixture['qm']->createQuery(
121-
'SELECT data.longNumberToCompare FROM [nt:unstructured] AS data WHERE data.longNumberToCompare > 2',
122+
$query = $this->sharedFixture['qm']->createQuery('
123+
SELECT data.longNumberToCompare
124+
FROM [nt:unstructured] AS data
125+
WHERE data.longNumberToCompare > 2
126+
AND ISDESCENDANTNODE([/tests_general_base])
127+
',
122128
\PHPCR\Query\QueryInterface::JCR_SQL2
123129
);
124130
$result = $query->execute();

tests/06_Query/QuerySql2OperationsTest.php

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ class QuerySql2OperationsTest extends QueryBaseCase
1313
public function testQueryField()
1414
{
1515
/** @var $query QueryInterface */
16-
$query = $this->sharedFixture['qm']->createQuery(
17-
'SELECT foo FROM [nt:unstructured] WHERE foo = "bar"',
16+
$query = $this->sharedFixture['qm']->createQuery('
17+
SELECT foo
18+
FROM [nt:unstructured]
19+
WHERE foo = "bar"
20+
AND (ISSAMENODE([/tests_general_base]) OR ISDESCENDANTNODE([/tests_general_base]))
21+
',
1822
QueryInterface::JCR_SQL2
1923
);
2024

@@ -37,8 +41,11 @@ public function testQueryField()
3741
public function testQueryFieldSomenull()
3842
{
3943
/** @var $query QueryInterface */
40-
$query = $this->sharedFixture['qm']->createQuery(
41-
'SELECT foo FROM [nt:unstructured]',
44+
$query = $this->sharedFixture['qm']->createQuery('
45+
SELECT foo
46+
FROM [nt:unstructured]
47+
WHERE ISDESCENDANTNODE([/tests_general_base])
48+
',
4249
QueryInterface::JCR_SQL2
4350
);
4451

@@ -50,21 +57,25 @@ public function testQueryFieldSomenull()
5057
$vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null);
5158
}
5259
$this->assertContains('bar', $vals);
53-
$this->assertEquals(10, count($vals));
60+
$this->assertEquals(9, count($vals));
5461

5562
$vals = array();
5663
foreach ($result->getRows() as $row) {
5764
$vals[] = $row->getValue('foo');
5865
}
5966
$this->assertContains('bar', $vals);
60-
$this->assertEquals(10, count($vals));
67+
$this->assertEquals(9, count($vals));
6168
}
6269

6370
public function testQueryFieldSelector()
6471
{
6572
/** @var $query QueryInterface */
66-
$query = $this->sharedFixture['qm']->createQuery(
67-
'SELECT data.foo FROM [nt:unstructured] AS data WHERE data.foo = "bar"',
73+
$query = $this->sharedFixture['qm']->createQuery('
74+
SELECT data.foo
75+
FROM [nt:unstructured] AS data
76+
WHERE data.foo = "bar"
77+
AND ISDESCENDANTNODE([/tests_general_base])
78+
',
6879
QueryInterface::JCR_SQL2
6980
);
7081

@@ -81,13 +92,14 @@ public function testQueryFieldSelector()
8192
public function testQueryJoin()
8293
{
8394
/** @var $query QueryInterface */
84-
$query = $this->sharedFixture['qm']->createQuery(
85-
'SELECT content.longNumber
86-
FROM [nt:file] AS file
87-
INNER JOIN [nt:unstructured] AS content
88-
ON ISDESCENDANTNODE(content, file)
89-
90-
WHERE content.longNumber = 999',
95+
$query = $this->sharedFixture['qm']->createQuery('
96+
SELECT content.longNumber
97+
FROM [nt:file] AS file
98+
INNER JOIN [nt:unstructured] AS content
99+
ON ISDESCENDANTNODE(content, file)
100+
WHERE content.longNumber = 999
101+
AND ISDESCENDANTNODE(file, [/tests_general_base])
102+
',
91103
QueryInterface::JCR_SQL2
92104
);
93105

@@ -128,10 +140,12 @@ public function testQueryJoinReference()
128140
public function testQueryOrder()
129141
{
130142
/** @var $query QueryInterface */
131-
$query = $this->sharedFixture['qm']->createQuery(
132-
'SELECT data.zeronumber
133-
FROM [nt:unstructured] AS data
134-
ORDER BY data.zeronumber',
143+
$query = $this->sharedFixture['qm']->createQuery('
144+
SELECT data.zeronumber
145+
FROM [nt:unstructured] AS data
146+
WHERE ISDESCENDANTNODE([/tests_general_base])
147+
ORDER BY data.zeronumber
148+
',
135149
QueryInterface::JCR_SQL2
136150
);
137151

@@ -143,17 +157,18 @@ public function testQueryOrder()
143157
$vals[] = $row->getValue('data.zeronumber');
144158
}
145159
// rows that do not have that field are null. empty is before fields with values
146-
$this->assertEquals(array(null, null, null, null, null, null, null, null, null, 0), $vals);
160+
$this->assertEquals(array(null, null, null, null, null, null, null, null, 0), $vals);
147161
}
148162

149163
public function testQueryMultiValuedProperty()
150164
{
151165
/** @var $query QueryInterface */
152-
$query = $this->sharedFixture['qm']->createQuery(
153-
'SELECT data.tags
166+
$query = $this->sharedFixture['qm']->createQuery('
167+
SELECT data.tags
154168
FROM [nt:unstructured] AS data
155169
WHERE data.tags = "foo"
156-
AND data.tags = "bar"
170+
AND data.tags = "bar"
171+
AND ISDESCENDANTNODE([/tests_general_base])
157172
',
158173
QueryInterface::JCR_SQL2
159174
);

tests/06_Query/Sql1/QueryOperationsTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ public function testQueryField()
3737
public function testQueryFieldSomenull()
3838
{
3939
/** @var $query QueryInterface */
40-
$query = $this->sharedFixture['qm']->createQuery(
41-
'SELECT foo FROM nt:unstructured',
40+
$query = $this->sharedFixture['qm']->createQuery('
41+
SELECT foo
42+
FROM nt:unstructured
43+
WHERE jcr:path LIKE \'/tests_general_base/%\'
44+
',
4245
QueryInterface::SQL
4346
);
4447

@@ -50,14 +53,14 @@ public function testQueryFieldSomenull()
5053
$vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null);
5154
}
5255
$this->assertContains('bar', $vals);
53-
$this->assertEquals(10, count($vals));
56+
$this->assertEquals(9, count($vals));
5457

5558
$vals = array();
5659
foreach ($result->getRows() as $row) {
5760
$vals[] = $row->getValue('foo');
5861
}
5962
$this->assertContains('bar', $vals);
60-
$this->assertEquals(10, count($vals));
63+
$this->assertEquals(9, count($vals));
6164
}
6265

6366
public function testQueryOrder()
@@ -66,6 +69,7 @@ public function testQueryOrder()
6669
$query = $this->sharedFixture['qm']->createQuery(
6770
'SELECT zeronumber
6871
FROM nt:unstructured
72+
WHERE jcr:path LIKE \'/tests_general_base/%\'
6973
ORDER BY zeronumber',
7074
QueryInterface::SQL
7175
);
@@ -78,7 +82,7 @@ public function testQueryOrder()
7882
$vals[] = $row->getValue('zeronumber');
7983
}
8084
// rows that do not have that field are null. empty is before fields with values
81-
$this->assertEquals(array(null, null, null, null, null, null, null, null, null, 0), $vals);
85+
$this->assertEquals(array(null, null, null, null, null, null, null, null, 0), $vals);
8286
}
8387

8488
}

0 commit comments

Comments
 (0)