Skip to content

add some tests about content encoding when writing, reading and querying #119

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 1 commit into from
Oct 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions fixtures/06_Query/characters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<sv:property sv:name="quoteandbackslash" sv:type="String">
<sv:value>'a\'\'b\'\'c'</sv:value>
</sv:property>

<sv:property sv:name="ampersand" sv:type="String">
<sv:value>foo &amp; bar&amp;baz</sv:value>
Copy link
Member Author

Choose a reason for hiding this comment

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

this is xml, so & has to be escaped

</sv:property>
</sv:node>
</sv:node>
</sv:node>
Expand Down
29 changes: 24 additions & 5 deletions tests/06_Query/CharacterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace PHPCR\Tests\Query;

use PHPCR\Query\QueryInterface;
use PHPCR\Query\QueryManagerInterface;

require_once(__DIR__ . '/../../inc/BaseCase.php');

Expand All @@ -19,7 +20,7 @@ public static function setupBeforeClass($fixtures = '06_Query/characters')
*/
public function testPropertyWithBackslash()
{
/** @var QueryManager $queryManager */
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery('
SELECT data.class
Expand All @@ -40,7 +41,7 @@ public function testPropertyWithBackslash()
*/
public function testPropertyWithDoubleBackslash()
{
/** @var QueryManager $queryManager */
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery('
SELECT data.doublebackslash
Expand All @@ -61,7 +62,7 @@ public function testPropertyWithDoubleBackslash()
*/
public function testPropertyWithQuotes()
{
/** @var QueryManager $queryManager */
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery(sprintf('
SELECT data.quotes
Expand All @@ -83,7 +84,7 @@ public function testPropertyWithQuotes()
*/
public function testPropertyWithQuotesAndBackslash()
{
/** @var QueryManager $queryManager */
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery(sprintf('
SELECT data.quoteandbackslash
Expand All @@ -102,7 +103,7 @@ public function testPropertyWithQuotesAndBackslash()

public function testQueryWithColon()
{
/** @var QueryManager $queryManager */
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery('
SELECT data.property
Expand All @@ -112,4 +113,22 @@ public function testQueryWithColon()
QueryInterface::JCR_SQL2
)->execute();
}

public function testQueryWithAmpersand()
{
/** @var QueryManagerInterface $queryManager */
$queryManager = $this->sharedFixture['qm'];
$query = $queryManager->createQuery('
SELECT data.ampersand
FROM [nt:unstructured] AS data
WHERE data.ampersand = "foo & bar&baz"
',
QueryInterface::JCR_SQL2
);

$result = $query->execute();
$rows = $result->getRows();
$this->assertCount(1, $rows);
$this->assertEquals('foo & bar&baz', $rows->current()->getValue('ampersand'));
}
}
21 changes: 21 additions & 0 deletions tests/10_Writing/EncodingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,25 @@ public static function getNodeNames()
array("node-&-x"),
);
}

/**
* @dataProvider getPropertyValues
*/
public function testEncodingPropertyValues($value, $type)
{
$this->node->setProperty($type, $value);
$session = $this->saveAndRenewSession();
$this->assertEquals($value, $session->getRootNode()->getNode('tests_write_encoding')->getNode('testEncoding')->getPropertyValue($type));
}

public static function getPropertyValues()
{
return array(
array('PHPCR\Query\QueryInterface', 'backslash'),
array('PHPCR\\\\Query\\\\QueryInterface', 'doublebackslash'),
array('"\'', 'quotes'),
array('a\\\'\\\'b\\\'\\\'c', 'quotesandbackslash'),
array('foo & bar&baz', 'ampersand'),
);
}
}