Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #61 from chregu/xpath_support

XPath tests
  • Loading branch information...
commit cdcf55198cc27044155da8e03af07bf03bf6d444 2 parents 750ce01 + e748d54
David Buchmann dbu authored
22 tests/06_Query/XPath/QueryBaseCase.php
View
@@ -0,0 +1,22 @@
+<?php
+namespace PHPCR\Tests\Query\XPath;
+
+require_once(__DIR__ . '/../../../inc/BaseCase.php');
+require_once(__DIR__ . '/../QueryBaseCase.php');
+
+/**
+ * a base class for all query tests
+ */
+abstract class QueryBaseCase extends \PHPCR\Tests\Query\QueryBaseCase
+{
+ /**
+ * in addition to base stuff, prepare $this->query with a simple select query
+ */
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->query = $this->sharedFixture['qm']->createQuery("//element(*,nt:folder)", \PHPCR\Query\QueryInterface::JCR_XPATH);
+ }
+
+}
77 tests/06_Query/XPath/QueryOperationsTest.php
View
@@ -0,0 +1,77 @@
+<?php
+namespace PHPCR\Tests\Query\XPath;
+
+require_once('QueryBaseCase.php');
+
+/**
+ * Run non-trivial queries to try out where, the join features and such
+ */
+class QueryOperationsTest extends QueryBaseCase
+{
+ public function testQueryField()
+ {
+ $query = $this->sharedFixture['qm']->createQuery(
+ '//element(*,nt:unstructured)[@foo = "bar"]/@foo',
+ \PHPCR\Query\QueryInterface::JCR_XPATH
+ );
+
+ $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
+ $result = $query->execute();
+ $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
+ $vals = array();
+ foreach ($result->getNodes() as $node) {
+ $vals[] = $node->getPropertyValue('foo');
+ }
+ $this->assertEquals(array('bar'), $vals);
+
+ $vals = array();
+ foreach ($result->getRows() as $row) {
+ $vals[] = $row->getValue('foo');
+ }
+ $this->assertEquals(array('bar'), $vals);
+ }
+
+ public function testQueryFieldSomenull()
+ {
+ $query = $this->sharedFixture['qm']->createQuery(
+ '//element(*,nt:unstructured)/@foo',
+ \PHPCR\Query\QueryInterface::JCR_XPATH
+ );
+
+ $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
+ $result = $query->execute();
+ $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
+ $vals = array();
+ foreach ($result->getNodes() as $node) {
+ $vals[] = ($node->hasProperty('foo') ? $node->getPropertyValue('foo') : null);
+ }
+ $this->assertContains('bar', $vals);
+ $this->assertEquals(8, count($vals));
+
+ $vals = array();
+ foreach ($result->getRows() as $row) {
+ $vals[] = $row->getValue('foo');
+ }
+ $this->assertContains('bar', $vals);
+ $this->assertEquals(8, count($vals));
+ }
+
+ public function testQueryOrder()
+ {
+ $query = $this->sharedFixture['qm']->createQuery(
+ '//element(*, nt:unstructured)/@zeronumber order by @zeronumber',
+ \PHPCR\Query\QueryInterface::JCR_XPATH
+ );
+
+ $this->assertInstanceOf('\PHPCR\Query\QueryInterface', $query);
+ $result = $query->execute();
+ $this->assertInstanceOf('\PHPCR\Query\QueryResultInterface', $result);
+ $vals = array();
+ foreach ($result->getRows() as $row) {
+ $vals[] = $row->getValue('zeronumber');
+ }
+ // rows that do not have that field are null. empty is before fields with values
+ $this->assertEquals(array(null, null, null, null, null, null, null, 0), $vals);
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.