@@ -316,13 +316,35 @@ public function testQueryMultiValuedProperty()
316
316
$ this ->assertSame ('foo bar ' , $ rows ->current ()->getValue ('tags ' ));
317
317
}
318
318
319
- public function testQueryWithLengthOperand ()
319
+ public function testLengthOperandOnStringProperty ()
320
320
{
321
321
/** @var $query QueryInterface */
322
322
$ query = $ this ->sharedFixture ['qm ' ]->createQuery ('
323
323
SELECT data.*
324
324
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
326
348
AND ISDESCENDANTNODE([/tests_general_base])
327
349
' ,
328
350
QueryInterface::JCR_SQL2
@@ -334,15 +356,77 @@ public function testQueryWithLengthOperand()
334
356
335
357
$ rows = $ result ->getRows ();
336
358
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) ' );
338
360
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
+ {
339
384
/** @var $query QueryInterface */
340
385
$ query = $ this ->sharedFixture ['qm ' ]->createQuery ('
341
386
SELECT data.*
342
387
FROM [nt:unstructured] AS data
343
388
WHERE
344
389
data.empty-value IS NOT NULL
345
390
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
346
430
AND LENGTH(data.empty-value) > -1
347
431
AND ISDESCENDANTNODE([/tests_general_base])
348
432
' ,
@@ -355,7 +439,28 @@ public function testQueryWithLengthOperand()
355
439
356
440
$ rows = $ result ->getRows ();
357
441
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 ' );
359
464
}
360
465
361
466
}
0 commit comments