@@ -316,4 +316,151 @@ public function testQueryMultiValuedProperty()
316
316
$ this ->assertSame ('foo bar ' , $ rows ->current ()->getValue ('tags ' ));
317
317
}
318
318
319
+ public function testLengthOperandOnStringProperty ()
320
+ {
321
+ /** @var $query QueryInterface */
322
+ $ query = $ this ->sharedFixture ['qm ' ]->createQuery ('
323
+ SELECT data.*
324
+ FROM [nt:unstructured] AS data
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
348
+ AND ISDESCENDANTNODE([/tests_general_base])
349
+ ' ,
350
+ QueryInterface::JCR_SQL2
351
+ );
352
+
353
+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryInterface ' , $ query );
354
+ $ result = $ query ->execute ();
355
+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryResultInterface ' , $ result );
356
+
357
+ $ rows = $ result ->getRows ();
358
+
359
+ $ this ->assertCount (1 , $ rows , 'Expected 1 node with property "foo" with a value with 4 characters (bar2) ' );
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
+ {
384
+ /** @var $query QueryInterface */
385
+ $ query = $ this ->sharedFixture ['qm ' ]->createQuery ('
386
+ SELECT data.*
387
+ FROM [nt:unstructured] AS data
388
+ WHERE
389
+ data.empty-value IS NOT NULL
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
430
+ AND LENGTH(data.empty-value) > -1
431
+ AND ISDESCENDANTNODE([/tests_general_base])
432
+ ' ,
433
+ QueryInterface::JCR_SQL2
434
+ );
435
+
436
+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryInterface ' , $ query );
437
+ $ result = $ query ->execute ();
438
+ $ this ->assertInstanceOf ('\PHPCR\Query\QueryResultInterface ' , $ result );
439
+
440
+ $ rows = $ result ->getRows ();
441
+
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 ' );
464
+ }
465
+
319
466
}
0 commit comments