From f8da741ad3587d40da6bd3e64babec7489db9b87 Mon Sep 17 00:00:00 2001 From: Willem-Jan Zijderveld Date: Mon, 30 Dec 2013 23:16:48 +0100 Subject: [PATCH 1/3] Added test for LENGTH operand (TODO: phpcr namespace) --- fixtures/general/base.xml | 1 + tests/06_Query/QuerySql2OperationsTest.php | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/fixtures/general/base.xml b/fixtures/general/base.xml index 9da9e31e..5a79a5a4 100644 --- a/fixtures/general/base.xml +++ b/fixtures/general/base.xml @@ -13,6 +13,7 @@ xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:rep="internal" + xmlns:phpcr="http://phpcr.github.io/jcr/phpcr/1.0" sv:name="tests_general_base"> diff --git a/tests/06_Query/QuerySql2OperationsTest.php b/tests/06_Query/QuerySql2OperationsTest.php index 7b90991c..f244b65f 100644 --- a/tests/06_Query/QuerySql2OperationsTest.php +++ b/tests/06_Query/QuerySql2OperationsTest.php @@ -316,4 +316,46 @@ public function testQueryMultiValuedProperty() $this->assertSame('foo bar', $rows->current()->getValue('tags')); } + public function testQueryWithLengthOperand() + { + /** @var $query QueryInterface */ + $query = $this->sharedFixture['qm']->createQuery(' + SELECT data.* + FROM [nt:unstructured] AS data + WHERE LENGTH(data.jcr:data) = 121 + AND ISDESCENDANTNODE([/tests_general_base]) + ', + QueryInterface::JCR_SQL2 + ); + + $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query); + $result = $query->execute(); + $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result); + + $rows = $result->getRows(); + + $this->assertCount(3, $rows, 'Expected 3 nodes with a jcr:data property with length 121'); + + /** @var $query QueryInterface */ + $query = $this->sharedFixture['qm']->createQuery(' + SELECT data.* + FROM [nt:unstructured] AS data + WHERE + data.empty-value IS NOT NULL + AND LENGTH(data.empty-value) < 1 + AND LENGTH(data.empty-value) > -1 + AND ISDESCENDANTNODE([/tests_general_base]) + ', + QueryInterface::JCR_SQL2 + ); + + $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query); + $result = $query->execute(); + $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result); + + $rows = $result->getRows(); + + $this->assertCount(1, $rows, 'Expected 1 node with property "empty-value" with a length smaller then 1 and greater then -1'); + } + } From 87f6c47fb268958700b745f44384cd38cc89c7a4 Mon Sep 17 00:00:00 2001 From: Willem-Jan Zijderveld Date: Sat, 4 Jan 2014 14:45:50 +0100 Subject: [PATCH 2/3] Removed unused namespace --- fixtures/general/base.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/fixtures/general/base.xml b/fixtures/general/base.xml index 5a79a5a4..9da9e31e 100644 --- a/fixtures/general/base.xml +++ b/fixtures/general/base.xml @@ -13,7 +13,6 @@ xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:rep="internal" - xmlns:phpcr="http://phpcr.github.io/jcr/phpcr/1.0" sv:name="tests_general_base"> From bce9d16d860b534515f8a454f45a5925902ec429 Mon Sep 17 00:00:00 2001 From: Willem-Jan Zijderveld Date: Wed, 8 Jan 2014 20:18:37 +0100 Subject: [PATCH 3/3] Updated tests: split into multiple tests and isolated each comparison in a separate query --- tests/06_Query/QuerySql2OperationsTest.php | 113 ++++++++++++++++++++- 1 file changed, 109 insertions(+), 4 deletions(-) diff --git a/tests/06_Query/QuerySql2OperationsTest.php b/tests/06_Query/QuerySql2OperationsTest.php index f244b65f..4d082001 100644 --- a/tests/06_Query/QuerySql2OperationsTest.php +++ b/tests/06_Query/QuerySql2OperationsTest.php @@ -316,13 +316,35 @@ public function testQueryMultiValuedProperty() $this->assertSame('foo bar', $rows->current()->getValue('tags')); } - public function testQueryWithLengthOperand() + public function testLengthOperandOnStringProperty() { /** @var $query QueryInterface */ $query = $this->sharedFixture['qm']->createQuery(' SELECT data.* FROM [nt:unstructured] AS data - WHERE LENGTH(data.jcr:data) = 121 + WHERE + data.foo IS NOT NULL + AND LENGTH(data.foo) = 3 + AND ISDESCENDANTNODE([/tests_general_base]) + ', + QueryInterface::JCR_SQL2 + ); + + $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query); + $result = $query->execute(); + $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result); + + $rows = $result->getRows(); + + $this->assertCount(1, $rows, 'Expected 1 node with property "foo" with a value with 3 characters (bar)'); + + /** @var $query QueryInterface */ + $query = $this->sharedFixture['qm']->createQuery(' + SELECT data.* + FROM [nt:unstructured] AS data + WHERE + data.foo IS NOT NULL + AND LENGTH(data.foo) = 4 AND ISDESCENDANTNODE([/tests_general_base]) ', QueryInterface::JCR_SQL2 @@ -334,8 +356,31 @@ public function testQueryWithLengthOperand() $rows = $result->getRows(); - $this->assertCount(3, $rows, 'Expected 3 nodes with a jcr:data property with length 121'); + $this->assertCount(1, $rows, 'Expected 1 node with property "foo" with a value with 4 characters (bar2)'); + /** @var $query QueryInterface */ + $query = $this->sharedFixture['qm']->createQuery(' + SELECT data.* + FROM [nt:unstructured] AS data + WHERE + data.foo IS NOT NULL + AND LENGTH(data.foo) > 2 + AND ISDESCENDANTNODE([/tests_general_base]) + ', + QueryInterface::JCR_SQL2 + ); + + $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query); + $result = $query->execute(); + $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result); + + $rows = $result->getRows(); + + $this->assertCount(2, $rows, 'Expected 2 nodes with property "foo" with a value with more then 2 characters (bar and bar2)'); + } + + public function testLengthOperandOnEmptyProperty() + { /** @var $query QueryInterface */ $query = $this->sharedFixture['qm']->createQuery(' SELECT data.* @@ -343,6 +388,45 @@ public function testQueryWithLengthOperand() WHERE data.empty-value IS NOT NULL AND LENGTH(data.empty-value) < 1 + AND ISDESCENDANTNODE([/tests_general_base]) + ', + QueryInterface::JCR_SQL2 + ); + + $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query); + $result = $query->execute(); + $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result); + + $rows = $result->getRows(); + + $this->assertCount(1, $rows, 'Expected 1 node with property "empty-value" with a length smaller then 1'); + + /** @var $query QueryInterface */ + $query = $this->sharedFixture['qm']->createQuery(' + SELECT data.* + FROM [nt:unstructured] AS data + WHERE + data.empty-value IS NOT NULL + AND LENGTH(data.empty-value) = 0 + AND ISDESCENDANTNODE([/tests_general_base]) + ', + QueryInterface::JCR_SQL2 + ); + + $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query); + $result = $query->execute(); + $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result); + + $rows = $result->getRows(); + + $this->assertCount(1, $rows, 'Expected 1 node with property "empty-value" with a length equal to 0'); + + /** @var $query QueryInterface */ + $query = $this->sharedFixture['qm']->createQuery(' + SELECT data.* + FROM [nt:unstructured] AS data + WHERE + data.empty-value IS NOT NULL AND LENGTH(data.empty-value) > -1 AND ISDESCENDANTNODE([/tests_general_base]) ', @@ -355,7 +439,28 @@ public function testQueryWithLengthOperand() $rows = $result->getRows(); - $this->assertCount(1, $rows, 'Expected 1 node with property "empty-value" with a length smaller then 1 and greater then -1'); + $this->assertCount(1, $rows, 'Expected 1 node with property "empty-value" with a length greater then -1'); + } + + public function testLengthOperandOnBinaryProperty() + { + /** @var $query QueryInterface */ + $query = $this->sharedFixture['qm']->createQuery(' + SELECT data.* + FROM [nt:unstructured] AS data + WHERE LENGTH(data.jcr:data) = 121 + AND ISDESCENDANTNODE([/tests_general_base]) + ', + QueryInterface::JCR_SQL2 + ); + + $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query); + $result = $query->execute(); + $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result); + + $rows = $result->getRows(); + + $this->assertCount(3, $rows, 'Expected 3 nodes with a (binary) jcr:data property with length 121'); } }