Skip to content

Commit f8da741

Browse files
author
Willem-Jan Zijderveld
committed
Added test for LENGTH operand (TODO: phpcr namespace)
1 parent 7726fec commit f8da741

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

fixtures/general/base.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
xmlns:jcr="http://www.jcp.org/jcr/1.0"
1414
xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
1515
xmlns:rep="internal"
16+
xmlns:phpcr="http://phpcr.github.io/jcr/phpcr/1.0"
1617

1718
sv:name="tests_general_base">
1819
<sv:property sv:name="jcr:primaryType" sv:type="Name">

tests/06_Query/QuerySql2OperationsTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,46 @@ public function testQueryMultiValuedProperty()
316316
$this->assertSame('foo bar', $rows->current()->getValue('tags'));
317317
}
318318

319+
public function testQueryWithLengthOperand()
320+
{
321+
/** @var $query QueryInterface */
322+
$query = $this->sharedFixture['qm']->createQuery('
323+
SELECT data.*
324+
FROM [nt:unstructured] AS data
325+
WHERE LENGTH(data.jcr:data) = 121
326+
AND ISDESCENDANTNODE([/tests_general_base])
327+
',
328+
QueryInterface::JCR_SQL2
329+
);
330+
331+
$this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
332+
$result = $query->execute();
333+
$this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
334+
335+
$rows = $result->getRows();
336+
337+
$this->assertCount(3, $rows, 'Expected 3 nodes with a jcr:data property with length 121');
338+
339+
/** @var $query QueryInterface */
340+
$query = $this->sharedFixture['qm']->createQuery('
341+
SELECT data.*
342+
FROM [nt:unstructured] AS data
343+
WHERE
344+
data.empty-value IS NOT NULL
345+
AND LENGTH(data.empty-value) < 1
346+
AND LENGTH(data.empty-value) > -1
347+
AND ISDESCENDANTNODE([/tests_general_base])
348+
',
349+
QueryInterface::JCR_SQL2
350+
);
351+
352+
$this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
353+
$result = $query->execute();
354+
$this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
355+
356+
$rows = $result->getRows();
357+
358+
$this->assertCount(1, $rows, 'Expected 1 node with property "empty-value" with a length smaller then 1 and greater then -1');
359+
}
360+
319361
}

0 commit comments

Comments
 (0)