/** * Converts an object. * * @param array|null $data * @return null|ObjectData */ public function convertObject(array $data = null) { if (empty($data)) { return null; } $object = new ObjectData(); if (isset($data[JSONConstants::JSON_OBJECT_ACL]) && is_array($data[JSONConstants::JSON_OBJECT_ACL]) && isset($data[JSONConstants::JSON_OBJECT_EXACT_ACL])) { $acl = $this->convertAcl($data[JSONConstants::JSON_OBJECT_ACL], (bool) $data[JSONConstants::JSON_OBJECT_EXACT_ACL]); if ($acl !== null) { $object->setAcl($acl); } } if (isset($data[JSONConstants::JSON_OBJECT_ALLOWABLE_ACTIONS])) { $allowableActions = $this->convertAllowableActions($data[JSONConstants::JSON_OBJECT_ALLOWABLE_ACTIONS]); if ($allowableActions !== null) { $object->setAllowableActions($allowableActions); } } if (isset($data[JSONConstants::JSON_OBJECT_CHANGE_EVENT_INFO]) && is_array($data[JSONConstants::JSON_OBJECT_CHANGE_EVENT_INFO])) { $changeEventInfoData = $data[JSONConstants::JSON_OBJECT_CHANGE_EVENT_INFO]; $changeEventInfo = new ChangeEventInfo(); $changeEventInfo->setChangeTime($this->convertDateTimeValue($changeEventInfoData[JSONConstants::JSON_CHANGE_EVENT_TIME])); $changeEventInfo->setChangeType(ChangeType::cast($changeEventInfoData[JSONConstants::JSON_CHANGE_EVENT_TYPE])); $changeEventInfo->setExtensions($this->convertExtension($changeEventInfoData, JSONConstants::getChangeEventKeys())); $object->setChangeEventInfo($changeEventInfo); } if (isset($data[JSONConstants::JSON_OBJECT_EXACT_ACL])) { $object->setIsExactAcl((bool) $data[JSONConstants::JSON_OBJECT_EXACT_ACL]); } if (isset($data[JSONConstants::JSON_OBJECT_POLICY_IDS])) { $object->setPolicyIds($this->convertPolicyIdList($data[JSONConstants::JSON_OBJECT_POLICY_IDS])); } /** * A client MAY add the query parameter succinct (HTTP GET) or the control succinct (HTTP POST) with the * value <code>true</code> to a request. If this is set, the repository MUST return properties in a succinct * format. That is, whenever the repository renders an object or a query result, it MUST populate the * succinctProperties value and MUST NOT populate the properties value. * * @see http://docs.oasis-open.org/cmis/CMIS/v1.1/os/CMIS-v1.1-os.html#x1-552027r554 */ if (isset($data[JSONConstants::JSON_OBJECT_SUCCINCT_PROPERTIES]) && is_array($data[JSONConstants::JSON_OBJECT_SUCCINCT_PROPERTIES])) { $properties = $data[JSONConstants::JSON_OBJECT_SUCCINCT_PROPERTIES]; $propertiesExtension = null; if (isset($data[JSONConstants::JSON_OBJECT_PROPERTIES_EXTENSION])) { $propertiesExtension = $data[JSONConstants::JSON_OBJECT_PROPERTIES_EXTENSION]; } $object->setProperties($this->convertSuccinctProperties($properties, $propertiesExtension)); } elseif (isset($data[JSONConstants::JSON_OBJECT_PROPERTIES]) && is_array($data[JSONConstants::JSON_OBJECT_PROPERTIES])) { $propertiesExtension = array(); if (isset($data[JSONConstants::JSON_OBJECT_PROPERTIES_EXTENSION])) { $propertiesExtension = (array) $data[JSONConstants::JSON_OBJECT_PROPERTIES_EXTENSION]; } $properties = $this->convertProperties($data[JSONConstants::JSON_OBJECT_PROPERTIES], $propertiesExtension); if ($properties !== null) { $object->setProperties($properties); } } if (isset($data[JSONConstants::JSON_OBJECT_RELATIONSHIPS]) && is_array($data[JSONConstants::JSON_OBJECT_RELATIONSHIPS])) { $relationships = $this->convertObjects($data[JSONConstants::JSON_OBJECT_RELATIONSHIPS]); if ($relationships !== null) { $object->setRelationships($relationships); } } if (isset($data[JSONConstants::JSON_OBJECT_RENDITIONS]) && is_array($data[JSONConstants::JSON_OBJECT_RENDITIONS])) { $object->setRenditions($this->convertRenditions($data[JSONConstants::JSON_OBJECT_RENDITIONS])); } $object->setExtensions($this->convertExtension($data, JSONConstants::getObjectKeys())); return $object; }
/** * @depends testSetRelationshipsSetsProperty */ public function testGetRelationshipsReturnsPropertyValue() { $relationships = array($this->getMockForAbstractClass('\\Dkd\\PhpCmis\\Data\\ObjectDataInterface')); $this->objectData->setRelationships($relationships); $this->assertSame($relationships, $this->objectData->getRelationships()); }
public function testGetRelationshipsReturnsRelationships() { $sessionMock = $this->getMockBuilder('\\Dkd\\PhpCmis\\SessionInterface')->setMethods(array('getObjectFactory', 'getDefaultContext'))->getMockForAbstractClass(); /** @var ObjectFactory|PHPUnit_Framework_MockObject_MockObject $objectFactoryMock */ $objectFactoryMock = $this->getMockBuilder('\\Dkd\\PhpCmis\\ObjectFactory')->setMethods(array('convertObject'))->getMock(); $objectFactoryMock->initialize($sessionMock); $operationContext = new OperationContext(); $relationshipObjectData1 = $documentTypeMock = $this->getMockBuilder('\\Dkd\\PhpCmis\\DataObjects\\ObjectData')->disableOriginalConstructor()->getMock(); $relationshipObjectData2 = $documentTypeMock = $this->getMockBuilder('\\Dkd\\PhpCmis\\DataObjects\\ObjectData')->disableOriginalConstructor()->getMock(); $expectedRelationship1 = $documentTypeMock = $this->getMockBuilder('\\Dkd\\PhpCmis\\DataObjects\\Relationship')->disableOriginalConstructor()->getMock(); $expectedRelationship2 = $documentTypeMock = $this->getMockBuilder('\\Dkd\\PhpCmis\\DataObjects\\Relationship')->disableOriginalConstructor()->getMock(); $expectedRelationships = array($expectedRelationship1, $expectedRelationship2); $sessionMock->expects($this->any())->method('getDefaultContext')->willReturn($operationContext); $sessionMock->expects($this->once())->method('getObjectFactory')->willReturn($objectFactoryMock); $objectFactoryMock->expects($this->any())->method('convertObject')->will($this->returnValueMap(array(array($relationshipObjectData1, $operationContext, $expectedRelationship1), array($relationshipObjectData2, $operationContext, $expectedRelationship2)))); $objectData = new ObjectData(); $objectData->setRelationships(array($relationshipObjectData1, $relationshipObjectData2)); $queryResult = new QueryResult($sessionMock, $objectData); $this->assertEquals($expectedRelationships, $queryResult->getRelationships()); }