@@ -316,13 +316,35 @@ public function testQueryMultiValuedProperty()
316316 $ this ->assertSame ('foo bar ' , $ rows ->current ()->getValue ('tags ' ));
317317 }
318318
319- public function testQueryWithLengthOperand ()
319+ public function testLengthOperandOnStringProperty ()
320320 {
321321 /** @var $query QueryInterface */
322322 $ query = $ this ->sharedFixture ['qm ' ]->createQuery ('
323323 SELECT data.*
324324 FROM [nt:unstructured] AS data
325- WHERE LENGTH(data.jcr:data) = 121
325+ WHERE
326+ data.foo IS NOT NULL
327+ AND LENGTH(data.foo) = 3
328+ AND ISDESCENDANTNODE([/tests_general_base])
329+ ' ,
330+ QueryInterface::JCR_SQL2
331+ );
332+
333+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryInterface ' , $ query );
334+ $ result = $ query ->execute ();
335+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryResultInterface ' , $ result );
336+
337+ $ rows = $ result ->getRows ();
338+
339+ $ this ->assertCount (1 , $ rows , 'Expected 1 node with property "foo" with a value with 3 characters (bar) ' );
340+
341+ /** @var $query QueryInterface */
342+ $ query = $ this ->sharedFixture ['qm ' ]->createQuery ('
343+ SELECT data.*
344+ FROM [nt:unstructured] AS data
345+ WHERE
346+ data.foo IS NOT NULL
347+ AND LENGTH(data.foo) = 4
326348 AND ISDESCENDANTNODE([/tests_general_base])
327349 ' ,
328350 QueryInterface::JCR_SQL2
@@ -334,15 +356,77 @@ public function testQueryWithLengthOperand()
334356
335357 $ rows = $ result ->getRows ();
336358
337- $ this ->assertCount (3 , $ rows , 'Expected 3 nodes with a jcr:data property with length 121 ' );
359+ $ this ->assertCount (1 , $ rows , 'Expected 1 node with property "foo" with a value with 4 characters (bar2) ' );
338360
361+ /** @var $query QueryInterface */
362+ $ query = $ this ->sharedFixture ['qm ' ]->createQuery ('
363+ SELECT data.*
364+ FROM [nt:unstructured] AS data
365+ WHERE
366+ data.foo IS NOT NULL
367+ AND LENGTH(data.foo) > 2
368+ AND ISDESCENDANTNODE([/tests_general_base])
369+ ' ,
370+ QueryInterface::JCR_SQL2
371+ );
372+
373+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryInterface ' , $ query );
374+ $ result = $ query ->execute ();
375+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryResultInterface ' , $ result );
376+
377+ $ rows = $ result ->getRows ();
378+
379+ $ this ->assertCount (2 , $ rows , 'Expected 2 nodes with property "foo" with a value with more then 2 characters (bar and bar2) ' );
380+ }
381+
382+ public function testLengthOperandOnEmptyProperty ()
383+ {
339384 /** @var $query QueryInterface */
340385 $ query = $ this ->sharedFixture ['qm ' ]->createQuery ('
341386 SELECT data.*
342387 FROM [nt:unstructured] AS data
343388 WHERE
344389 data.empty-value IS NOT NULL
345390 AND LENGTH(data.empty-value) < 1
391+ AND ISDESCENDANTNODE([/tests_general_base])
392+ ' ,
393+ QueryInterface::JCR_SQL2
394+ );
395+
396+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryInterface ' , $ query );
397+ $ result = $ query ->execute ();
398+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryResultInterface ' , $ result );
399+
400+ $ rows = $ result ->getRows ();
401+
402+ $ this ->assertCount (1 , $ rows , 'Expected 1 node with property "empty-value" with a length smaller then 1 ' );
403+
404+ /** @var $query QueryInterface */
405+ $ query = $ this ->sharedFixture ['qm ' ]->createQuery ('
406+ SELECT data.*
407+ FROM [nt:unstructured] AS data
408+ WHERE
409+ data.empty-value IS NOT NULL
410+ AND LENGTH(data.empty-value) = 0
411+ AND ISDESCENDANTNODE([/tests_general_base])
412+ ' ,
413+ QueryInterface::JCR_SQL2
414+ );
415+
416+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryInterface ' , $ query );
417+ $ result = $ query ->execute ();
418+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryResultInterface ' , $ result );
419+
420+ $ rows = $ result ->getRows ();
421+
422+ $ this ->assertCount (1 , $ rows , 'Expected 1 node with property "empty-value" with a length equal to 0 ' );
423+
424+ /** @var $query QueryInterface */
425+ $ query = $ this ->sharedFixture ['qm ' ]->createQuery ('
426+ SELECT data.*
427+ FROM [nt:unstructured] AS data
428+ WHERE
429+ data.empty-value IS NOT NULL
346430 AND LENGTH(data.empty-value) > -1
347431 AND ISDESCENDANTNODE([/tests_general_base])
348432 ' ,
@@ -355,7 +439,28 @@ public function testQueryWithLengthOperand()
355439
356440 $ rows = $ result ->getRows ();
357441
358- $ this ->assertCount (1 , $ rows , 'Expected 1 node with property "empty-value" with a length smaller then 1 and greater then -1 ' );
442+ $ this ->assertCount (1 , $ rows , 'Expected 1 node with property "empty-value" with a length greater then -1 ' );
443+ }
444+
445+ public function testLengthOperandOnBinaryProperty ()
446+ {
447+ /** @var $query QueryInterface */
448+ $ query = $ this ->sharedFixture ['qm ' ]->createQuery ('
449+ SELECT data.*
450+ FROM [nt:unstructured] AS data
451+ WHERE LENGTH(data.jcr:data) = 121
452+ AND ISDESCENDANTNODE([/tests_general_base])
453+ ' ,
454+ QueryInterface::JCR_SQL2
455+ );
456+
457+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryInterface ' , $ query );
458+ $ result = $ query ->execute ();
459+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryResultInterface ' , $ result );
460+
461+ $ rows = $ result ->getRows ();
462+
463+ $ this ->assertCount (3 , $ rows , 'Expected 3 nodes with a (binary) jcr:data property with length 121 ' );
359464 }
360465
361466}
0 commit comments