Skip to content

Added test for LENGTH operand #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 9, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fixtures/general/base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you create this namespace for? i don't see it used anywhere.

indeed this will cause major pain with jackrabbit, as namespaces are global and we use the phpcr namespace already.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added it because it caused an error about a invalid XML while I was testing this. But figured that the namespace isn't needed in the general JCR XML. Only in the XML used by jackalope doctrine dbal.

Removed it.


sv:name="tests_general_base">
<sv:property sv:name="jcr:primaryType" sv:type="Name">
Expand Down
42 changes: 42 additions & 0 deletions tests/06_Query/QuerySql2OperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is a very complicated way of expressing 0. what exactly is the idea? testing the smaller and bigger operators? could we do that with something more meaningful? and could you create a separate test for the LENGTH of a binary property and a string property? i guess binary will always be a special case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the idea was to test =, < and >. But might be better to test those in seperate queries.

The jcr:data is a binary property, will pull it out and put it in a separate test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(y) excellent!

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');
}

}