Skip to content

Commit 3095c00

Browse files
committed
Merge pull request #118 from phpcr/sort_test
provide a separate test for ordering with and without missing properties
2 parents 3179185 + c01d8ef commit 3095c00

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

fixtures/general/base.xml

+4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@
100100
<sv:value>2009-04-27T13:01:07.472+02:00</sv:value>
101101
</sv:property>
102102

103+
<sv:property sv:name="foo" sv:type="String">
104+
<sv:value>bar2</sv:value>
105+
</sv:property>
106+
103107
<sv:property sv:name="jcr:mimeType" sv:type="String">
104108
<sv:value>text/plain</sv:value>
105109
</sv:property>

tests/06_Query/QuerySql2OperationsTest.php

+26-2
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,30 @@ public function testQueryJoinReference()
247247
}
248248

249249
public function testQueryOrder()
250+
{
251+
/** @var $query QueryInterface */
252+
$query = $this->sharedFixture['qm']->createQuery('
253+
SELECT data.foo
254+
FROM [nt:unstructured] AS data
255+
WHERE ISDESCENDANTNODE([/tests_general_base]) AND data.foo IS NOT NULL
256+
ORDER BY data.foo
257+
',
258+
QueryInterface::JCR_SQL2
259+
);
260+
261+
$this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
262+
$result = $query->execute();
263+
$this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
264+
$vals = array();
265+
foreach ($result->getRows() as $row) {
266+
$vals[] = $row->getValue('data.foo');
267+
}
268+
269+
// rows that do not have that field are empty string. empty is before fields with values
270+
$this->assertEquals(array('bar', 'bar2'), $vals);
271+
}
272+
273+
public function testQueryOrderWithMissingProperty()
250274
{
251275
/** @var $query QueryInterface */
252276
$query = $this->sharedFixture['qm']->createQuery('
@@ -265,8 +289,8 @@ public function testQueryOrder()
265289
foreach ($result->getRows() as $row) {
266290
$vals[] = $row->getValue('data.zeronumber');
267291
}
268-
// rows that do not have that field are null. empty is before fields with values
269-
$this->assertEquals(array(null, null, null, null, null, null, null, null, 0), $vals);
292+
// rows that do not have that field are empty string. empty is before fields with values
293+
$this->assertEquals(array('', '', '', '', '', '', '', '', 0), $vals);
270294
}
271295

272296
public function testQueryMultiValuedProperty()

0 commit comments

Comments
 (0)