Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jackalope/jackalope
Browse files Browse the repository at this point in the history
  • Loading branch information
rndstr committed Aug 18, 2010
2 parents d9c82d0 + b487372 commit 9e44d2c
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 24 deletions.
38 changes: 22 additions & 16 deletions src/jackalope/transport/DavexClient.php
Expand Up @@ -120,29 +120,26 @@ public function getRepositoryDescriptors() {
* TODO: should we call this getNode? does not work for property. (see ObjectManager::getPropertyByPath for more on properties)
* @param path absolute path to item
* @return array for the node (decoded from json)
* @throws PHPCR_RepositoryException if now logged in
*/
public function getItem($path) {
if ('/' != substr($path, 0, 1)) {
//sanity check
throw new PHPCR_RepositoryException("Implementation error: '$path' is not an absolute path");
}
if (empty($this->workspaceUri)) {
throw new PHPCR_RepositoryException("Implementation error: Please login before accessing content");
}

$this->checkLogin();
return $this->getJsonFromBackend(self::GET, $this->workspaceUriRoot . $path . '.0.json');
}
/**
* Get the node path from a JCR uuid
* @param uuid the id in JCR format
* @return string path to the node
* @throws PHPCR_ItemNotFoundException if the backend does not know the uuid
* @throws PHPCR_RepositoryException if now logged in
*/
public function getNodePathForIdentifier($uuid) {
if (empty($this->workspaceUri)) {
throw new PHPCR_RepositoryException("Implementation error: Please login before accessing content");
}

$this->checkLogin();

$dom = $this->getDomFromBackend(self::REPORT, $this->workspaceUri,
self::buildLocateRequest($uuid));
/* answer looks like
Expand All @@ -167,11 +164,10 @@ public function getNodePathForIdentifier($uuid) {
/**
* get the registered namespaces mappings from the backend
* @return associative array of prefix => uri
* @throws PHPCR_RepositoryException if now logged in
*/
public function getNamespaces() {
if (empty($this->workspaceUri)) {
throw new PHPCR_RepositoryException("Implementation error: Please login before accessing content");
}
$this->checkLogin();

$dom = $this->getDomFromBackend(self::REPORT, $this->workspaceUri,
self::buildReportRequest('dcr:registerednamespaces'));
Expand All @@ -191,21 +187,31 @@ public function getNamespaces() {
* Returns node types
* @param array nodetypes to request
* @return dom with the definitions
* @throws PHPCR_RepositoryException if now logged in
*/
public function getNodeTypes($nodeTypes = array()) {
if (empty($this->workspaceUri)) {
throw new PHPCR_RepositoryException("Implementation error: Please login before accessing content");
}
$this->checkLogin();

$dom = $this->getDomFromBackend(
self::REPORT, $this->workspaceUri . '/jcr:root/tests_level1_access_base',
self::REPORT, $this->workspaceUri . '/jcr:root',
self::buildNodeTypesRequest($nodeTypes)
);
if ($dom->firstChild->localName != 'nodeTypes') {
throw new PHPCR_RepositoryException('Error talking to the backend. '.$dom->saveXML());
}
return $dom;
}


/**
* Throws an error if the there is no login
* @throws PHPCR_RepositoryException if now logged in
*/
protected function checkLogin() {
if (empty($this->workspaceUri)) {
throw new PHPCR_RepositoryException("Implementation error: Please login before accessing content");
}
}

/**
* Returns the XML required to request nodetypes
* @param array the nodetypes you want to request
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/empty.xml
@@ -0,0 +1,2 @@
<?xml version="1.0"?>
<empty/>
9 changes: 5 additions & 4 deletions tests/fixtures/nodetypes.xml
@@ -1,7 +1,5 @@
<?xml version="1.0"?>
<nodeTypes>
<nodeType hasOrderableChildNodes="false" isAbstract="false" isMixin="true" isQueryable="true" name="mix:created">
<supertypes/>
<?xml version="1.0" encoding="UTF-8"?>
<nodeTypes><nodeType hasOrderableChildNodes="false" isAbstract="false" isMixin="true" isQueryable="true" name="mix:created">
<propertyDefinition autoCreated="true" declaringNodeType="mix:created" fullTextSearchable="true" mandatory="false" multiple="false" name="jcr:createdBy" onParentVersion="COPY" protected="true" queryOrderable="true" requiredType="String">
<valueConstraints/>
<availableQueryOperators>
Expand Down Expand Up @@ -1575,3 +1573,6 @@
</childNodeDefinition>
</nodeType>
</nodeTypes>



23 changes: 23 additions & 0 deletions tests/fixtures/small_nodetypes.xml
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<nodeTypes>
<nodeType hasOrderableChildNodes="false" isAbstract="false" isMixin="false" isQueryable="true" name="nt:folder">
<supertypes>
<supertype>nt:hierarchyNode</supertype>
</supertypes>
<childNodeDefinition autoCreated="false" declaringNodeType="nt:folder" mandatory="false" name="*" onParentVersion="VERSION" protected="false" sameNameSiblings="false">
<requiredPrimaryTypes>
<requiredPrimaryType>nt:hierarchyNode</requiredPrimaryType>
</requiredPrimaryTypes>
</childNodeDefinition>
</nodeType>
<nodeType hasOrderableChildNodes="false" isAbstract="false" isMixin="false" isQueryable="true" name="nt:file" primaryItemName="jcr:content">
<supertypes>
<supertype>nt:hierarchyNode</supertype>
</supertypes>
<childNodeDefinition autoCreated="false" declaringNodeType="nt:file" mandatory="true" name="jcr:content" onParentVersion="COPY" protected="false" sameNameSiblings="false">
<requiredPrimaryTypes>
<requiredPrimaryType>nt:base</requiredPrimaryType>
</requiredPrimaryTypes>
</childNodeDefinition>
</nodeType>
</nodeTypes>
67 changes: 63 additions & 4 deletions tests/transport/DavexClient.php
@@ -1,6 +1,12 @@
<?php
require_once(dirname(__FILE__) . '/../inc/baseCase.php');

class jackalope_transport_DavexClient_Mock extends jackalope_transport_DavexClient {
static public function buildNodeTypesRequestMock(Array $params) {
return self::buildNodeTypesRequest($params);
}
}

class jackalope_tests_transport_DavexClient extends jackalope_baseCase {
public function testGetRepositoryDescriptors() {
$t = new jackalope_transport_DavexClient($this->config['url']);
Expand All @@ -17,6 +23,15 @@ public function testGetRepositoryDescriptors() {
}
}
}

/**
* @expectedException PHPCR_RepositoryException
*/
public function testCheckLoginFail() {
$t = new jackalope_transport_DavexClient('http://localhost:1/server');
$t->getNodeTypes();
}

/**
* @expectedException PHPCR_RepositoryException
*/
Expand Down Expand Up @@ -71,13 +86,57 @@ public function testGetNamespaces() {
}
}

/** START TESTING NODE TYPES **/
protected function setUpNodeTypeMock($params, $fixture) {
$dom = new DOMDocument();
$dom->load($fixture);

$requestStr = jackalope_transport_DavexClient_Mock::buildNodeTypesRequestMock($params);

$t = $this->getMock('jackalope_transport_DavexClient', array('getDomFromBackend', 'checkLogin', '__construct'), array(null));
$t->expects($this->once())
->method('getDomFromBackend')
->with(jackalope_transport_DavexClient::REPORT, '/jcr:root', $requestStr)
->will($this->returnValue($dom));
return $t;
}

public function testGetAllNodeTypesRequest() {
$xmlStr = '<?xml version="1.0" encoding="utf-8" ?><jcr:nodetypes xmlns:jcr="http://www.day.com/jcr/webdav/1.0"><jcr:all-nodetypes/></jcr:nodetypes>';
$this->assertEquals($xmlStr, jackalope_transport_DavexClient_Mock::buildNodeTypesRequestMock(array()));
}

public function testSpecificNodeTypesRequest() {
$xmlStr= '<?xml version="1.0" encoding="utf-8" ?><jcr:nodetypes xmlns:jcr="http://www.day.com/jcr/webdav/1.0"><jcr:nodetype><jcr:nodetypename>foo</jcr:nodetypename></jcr:nodetype><jcr:nodetype><jcr:nodetypename>bar</jcr:nodetypename></jcr:nodetype><jcr:nodetype><jcr:nodetypename>foobar</jcr:nodetypename></jcr:nodetype></jcr:nodetypes>';
$this->assertEquals($xmlStr, jackalope_transport_DavexClient_Mock::buildNodeTypesRequestMock(array('foo', 'bar', 'foobar')));
}

public function testGetNodeTypes() {
$t = new jackalope_transport_DavexClient($this->config['url']);
$x = $t->login($this->credentials, $this->config['workspace']);
$this->assertTrue($x);
$t = $this->setUpNodeTypeMock(array(), 'fixtures/nodetypes.xml');

$nt = $t->getNodeTypes();
$this->assertTrue($nt instanceOf DOMDocument);
$this->assertEquals('mix:created', $nt->firstChild->firstChild->getAttribute('name'));
}

public function testSpecificGetNodeTypes() {
$t = $this->setUpNodeTypeMock(array('nt:folder', 'nt:file'), 'fixtures/small_nodetypes.xml');

$nt = $t->getNodeTypes(array('nt:folder', 'nt:file'));
$this->assertTrue($nt instanceOf DOMDocument);
$this->assertType('DOMDocument', $nt);
$xp = new DOMXpath($nt);
$res = $xp->query('//nodeType');
$this->assertEquals(2, $res->length);
$this->assertEquals('nt:folder', $res->item(0)->getAttribute('name'));
$this->assertEquals('nt:file', $res->item(1)->getAttribute('name'));
}

public function testEmptyGetNodeTypes() {
$t = $this->setUpNodeTypeMock(array(), 'fixtures/empty.xml');

$this->setExpectedException('PHPCR_RepositoryException');
$nt = $t->getNodeTypes();
}

/** END TESTING NODE TYPES **/
}

0 comments on commit 9e44d2c

Please sign in to comment.