/** * @depends testAddPropertyAddsProperty */ public function testAddPropertiesAddsAListOfProperties() { $properties = new Properties(); $stringProperty = new PropertyString('stringProp', 'stringPropValue'); $properties->addProperty($stringProperty); $stringProperty2 = new PropertyString('stringProp2', 'stringPropValue2'); $stringProperty3 = new PropertyString('stringProp3', 'stringPropValue3'); $properties->addProperties(array($stringProperty2, $stringProperty3)); $this->assertAttributeSame(array($stringProperty->getId() => $stringProperty, $stringProperty2->getId() => $stringProperty2, $stringProperty3->getId() => $stringProperty3), 'properties', $properties); }
public function testConvertPropertiesToQueryArrayConvertsPropertiesIntoAnArray() { $sessionMock = $this->getSessionMock(); /** @var PHPUnit_Framework_MockObject_MockObject|AbstractBrowserBindingService $binding */ $binding = $this->getMockBuilder(self::CLASS_TO_TEST)->setConstructorArgs(array($sessionMock))->getMockForAbstractClass(); $properties = new Properties(); $currentTime = new \DateTime('now'); $singleValueStringProperty = new PropertyString('stringProp', 'stringValue'); $multiValueStringProperty = new PropertyString('stringProp2', array('stringValue1', 'stringValue2')); $singleValueBooleanProperty = new PropertyBoolean('booleanProp', true); $singleValueDecimalProperty = new PropertyDecimal('decimalProp', 1.2); $singleValueDateTimeProperty = new PropertyDateTime('dateTimeProp', $currentTime); $singleValueIdProperty = new PropertyId('idProp', 'idValue'); $properties->addProperties(array($singleValueStringProperty, $multiValueStringProperty, $singleValueBooleanProperty, $singleValueDecimalProperty, $singleValueDateTimeProperty, $singleValueIdProperty)); $expectedArray = array(Constants::CONTROL_PROP_ID => array(0 => 'stringProp', 1 => 'stringProp2', 2 => 'booleanProp', 3 => 'decimalProp', 4 => 'dateTimeProp', 5 => 'idProp'), Constants::CONTROL_PROP_VALUE => array(0 => 'stringValue', 1 => array(0 => 'stringValue1', 1 => 'stringValue2'), 2 => true, 3 => 1.2, 4 => $currentTime->getTimestamp() * 1000, 5 => 'idValue')); $this->assertEquals($expectedArray, $this->getMethod(self::CLASS_TO_TEST, 'convertPropertiesToQueryArray')->invokeArgs($binding, array($properties))); }
public function testGetBaseTypeIdReturnsFirstValueOfIdMultiValuePropertyValue() { $idProperty = new PropertyId(PropertyIds::BASE_TYPE_ID, array('cmis:item', 'cmis:document')); $properties = new Properties(); $properties->addProperty($idProperty); $this->objectData->setProperties($properties); $this->assertEquals(BaseTypeId::cast(BaseTypeId::CMIS_ITEM), $this->objectData->getBaseTypeId()); }
/** * @dataProvider deleteContentStreamDataProvider * @param string $expectedUrl * @param string $repositoryId * @param string $objectId * @param StreamInterface $contentStream * @param boolean $overwriteFlag * @param string|null $changeToken * @param array $sessionParameterMap */ public function testDeleteContentStreamCallsPostFunctionWithParameterizedQuery($expectedUrl, $repositoryId, $objectId, $changeToken = null, $sessionParameterMap = array()) { $responseData = array('foo' => 'bar'); $responseMock = $this->getMockBuilder('\\GuzzleHttp\\Message\\Response')->disableOriginalConstructor()->setMethods(array('json'))->getMock(); $responseMock->expects($this->any())->method('json')->willReturn($responseData); $jsonConverterMock = $this->getMockBuilder('\\Dkd\\PhpCmis\\Converter\\JsonConverter')->setMethods(array('convertObject'))->getMock(); /** @var ObjectData|PHPUnit_Framework_MockObject_MockObject $dummyObjectData */ $dummyObjectData = $this->getMockBuilder('\\Dkd\\PhpCmis\\ObjectData\\ObjectData')->setMethods(array('getId', 'getProperties'))->getMock(); $newObjectId = 'foo-id'; $newChangeTokenId = 'newTokenId'; $dummyProperties = new Properties(); $newChangeTokenProperty = new PropertyId('cmis:changeToken', $newChangeTokenId); $dummyProperties->addProperty($newChangeTokenProperty); $dummyObjectData->expects($this->any())->method('getId')->willReturn($newObjectId); $dummyObjectData->expects($this->any())->method('getProperties')->willReturn($dummyProperties); $jsonConverterMock->expects($this->atLeastOnce())->method('convertObject')->with($responseData)->willReturn($dummyObjectData); $cmisBindingsHelperMock = $this->getMockBuilder('\\Dkd\\PhpCmis\\Bindings\\CmisBindingsHelper')->setMethods(array('getJsonConverter'))->getMock(); $cmisBindingsHelperMock->expects($this->atLeastOnce())->method('getJsonConverter')->willReturn($jsonConverterMock); $sessionMock = $this->getSessionMock($sessionParameterMap); /** @var ObjectService|PHPUnit_Framework_MockObject_MockObject $objectService */ $objectService = $this->getMockBuilder(self::CLASS_TO_TEST)->setConstructorArgs(array($sessionMock, $cmisBindingsHelperMock))->setMethods(array('getObjectUrl', 'post', 'getSession'))->getMock(); $objectService->expects($this->atLeastOnce())->method('getObjectUrl')->with($repositoryId, $objectId)->willReturn(Url::createFromUrl(self::BROWSER_URL_TEST)); $objectService->expects($this->atLeastOnce())->method('post')->with($expectedUrl)->willReturn($responseMock); $objectService->expects($this->atLeastOnce())->method('getSession')->willReturn($sessionMock); $objectService->deleteContentStream($repositoryId, $objectId, $changeToken); $this->assertEquals($objectId, $newObjectId); if ($changeToken !== null) { $this->assertEquals($changeToken, $newChangeTokenId); } }
/** * @covers Dkd\PhpCmis\Converter\JsonConverter::convertProperties * @covers Dkd\PhpCmis\Converter\JsonConverter::getPropertyByPropertyType * @covers Dkd\PhpCmis\Converter\JsonConverter::convertStringValues * @covers Dkd\PhpCmis\Converter\JsonConverter::convertBooleanValues * @covers Dkd\PhpCmis\Converter\JsonConverter::convertIntegerValues * @covers Dkd\PhpCmis\Converter\JsonConverter::convertDecimalValues * @return Properties */ public function testConvertPropertiesConvertsArrayToPropertiesObject() { $properties = new Properties(); $htmlProperty = new PropertyHtml('HtmlProp', 'dummy value'); $htmlProperty->setLocalName('HtmlProp'); $htmlProperty->setQueryName('HtmlProp'); $htmlProperty->setDisplayName('Sample Html Property'); $properties->addProperty($htmlProperty); $idProperty = new PropertyId('IdProp', 'dummy value'); $idProperty->setLocalName('IdProp'); $idProperty->setQueryName('IdProp'); $idProperty->setDisplayName('Sample Id Property'); $properties->addProperty($idProperty); $dateTimeMultiValueProperty = new PropertyDateTime('DateTimePropMV', array(new \DateTime('@1342160128'), new \DateTime('@1342170128'))); $dateTimeMultiValueProperty->setLocalName('DateTimePropMV'); $dateTimeMultiValueProperty->setQueryName('DateTimePropMV'); $dateTimeMultiValueProperty->setDisplayName('Sample DateTime multi-value Property'); $properties->addProperty($dateTimeMultiValueProperty); $uriProperty = new PropertyUri('UriProp', 'dummy value'); $uriProperty->setLocalName('UriProp'); $uriProperty->setQueryName('UriProp'); $uriProperty->setDisplayName('Sample Uri Property'); $properties->addProperty($uriProperty); $decimalProperty = new PropertyDecimal('DecimalProp', 1.2); $decimalProperty->setLocalName('DecimalProp'); $decimalProperty->setQueryName('DecimalProp'); $decimalProperty->setDisplayName('Sample Decimal Property'); $properties->addProperty($decimalProperty); $uriMultiValueProperty = new PropertyUri('UriPropMV', array('dummy value', 'dummy value')); $uriMultiValueProperty->setLocalName('UriPropMV'); $uriMultiValueProperty->setQueryName('UriPropMV'); $uriMultiValueProperty->setDisplayName('Sample Uri multi-value Property'); $properties->addProperty($uriMultiValueProperty); $booleanProperty = new PropertyBoolean('BooleanProp', true); $booleanProperty->setLocalName('BooleanProp'); $booleanProperty->setQueryName('BooleanProp'); $booleanProperty->setDisplayName('Sample Boolean Property'); $properties->addProperty($booleanProperty); $idMultiValueProperty = new PropertyId('IdPropMV', array('dummy value', 'dummy value')); $idMultiValueProperty->setLocalName('IdPropMV'); $idMultiValueProperty->setQueryName('IdPropMV'); $idMultiValueProperty->setDisplayName('Sample Id Html multi-value Property'); $properties->addProperty($idMultiValueProperty); $pickListProperty = new PropertyString('PickListProp', 'blue'); $pickListProperty->setLocalName('PickListProp'); $pickListProperty->setQueryName('PickListProp'); $pickListProperty->setDisplayName('Sample Pick List Property'); $properties->addProperty($pickListProperty); $htmlMultiValueProperty = new PropertyHtml('HtmlPropMV', array('dummy value', 'dummy value')); $htmlMultiValueProperty->setLocalName('HtmlPropMV'); $htmlMultiValueProperty->setQueryName('HtmlPropMV'); $htmlMultiValueProperty->setDisplayName('Sample Html multi-value Property'); $properties->addProperty($htmlMultiValueProperty); $intProperty = new PropertyInteger('IntProp', 12); $intProperty->setLocalName('IntProp'); $intProperty->setQueryName('IntProp'); $intProperty->setDisplayName('Sample Int Property'); $properties->addProperty($intProperty); $stringProperty = new PropertyString('StringProp', 'My Doc StringProperty 18'); $stringProperty->setLocalName('StringProp'); $stringProperty->setQueryName('StringProp'); $stringProperty->setDisplayName('Sample String Property'); $properties->addProperty($stringProperty); $decimalMultiValueProperty = new PropertyDecimal('DecimalPropMV', array(1.2, 2.3)); $decimalMultiValueProperty->setLocalName('DecimalPropMV'); $decimalMultiValueProperty->setQueryName('DecimalPropMV'); $decimalMultiValueProperty->setDisplayName('Sample Decimal multi-value Property'); $properties->addProperty($decimalMultiValueProperty); $dateTimeProperty = new PropertyDateTime('DateTimeProp', new \DateTime('@1342160128')); $dateTimeProperty->setLocalName('DateTimeProp'); $dateTimeProperty->setQueryName('DateTimeProp'); $dateTimeProperty->setDisplayName('Sample DateTime Property'); $properties->addProperty($dateTimeProperty); $booleanMultiValueProperty = new PropertyBoolean('BooleanPropMV', array(true, false)); $booleanMultiValueProperty->setLocalName('BooleanPropMV'); $booleanMultiValueProperty->setQueryName('BooleanPropMV'); $booleanMultiValueProperty->setDisplayName('Sample Boolean multi-value Property'); $properties->addProperty($booleanMultiValueProperty); $intMultiValueProperty = new PropertyInteger('IntPropMV', array(1, 2)); $intMultiValueProperty->setLocalName('IntPropMV'); $intMultiValueProperty->setQueryName('IntPropMV'); $intMultiValueProperty->setDisplayName('Sample Int multi-value Property'); $properties->addProperty($intMultiValueProperty); $properties->setExtensions($this->cmisExtensionsDummy); $getObjectResponse = $this->getResponseFixtureContentAsArray('Cmis/v1.1/BrowserBinding/getObject-response.log'); $result = $this->jsonConverter->convertProperties($getObjectResponse[JSONConstants::JSON_OBJECT_PROPERTIES], $getObjectResponse[JSONConstants::JSON_OBJECT_PROPERTIES_EXTENSION]); $this->assertEquals($properties, $result); return $result; }
/** * @param PropertyDataInterface[] $propertiesData * @return Properties */ public function createPropertiesData(array $propertiesData) { $properties = new Properties(); $properties->addProperties($propertiesData); return $properties; }
/** * @param array|null $data * @param array $extensions * @return null|Properties * @throws CmisRuntimeException */ public function convertProperties(array $data = null, $extensions = array()) { if (empty($data)) { return null; } $properties = new Properties(); foreach ($data as $propertyData) { $id = !empty($propertyData[JSONConstants::JSON_PROPERTY_ID]) ? $propertyData[JSONConstants::JSON_PROPERTY_ID] : null; $queryName = !empty($propertyData[JSONConstants::JSON_PROPERTY_QUERYNAME]) ? $propertyData[JSONConstants::JSON_PROPERTY_QUERYNAME] : null; // A Property must always have an ID except if it used in a query result. // In a query result a Property should have an ID and must have a query name. if ($id === null && $queryName === null) { throw new CmisRuntimeException('Invalid property! Neither a property ID nor a query name is provided!'); } try { $propertyType = PropertyType::cast($propertyData[JSONConstants::JSON_PROPERTY_DATATYPE]); } catch (InvalidEnumerationValueException $exception) { throw new CmisRuntimeException(sprintf('Unknown property type "%s"!', $propertyData[JSONConstants::JSON_PROPERTY_DATATYPE])); } if (empty($propertyData[JSONConstants::JSON_PROPERTY_VALUE])) { $propertyValues = array(); } elseif (!is_array($propertyData[JSONConstants::JSON_PROPERTY_VALUE])) { $propertyValues = array($propertyData[JSONConstants::JSON_PROPERTY_VALUE]); } else { $propertyValues = $propertyData[JSONConstants::JSON_PROPERTY_VALUE]; } // get property keys without JSON-response-specific cardinality properties $jsonPropertyKeys = JSONConstants::getPropertyKeys(); $propertyKeys = array_values(array_diff($jsonPropertyKeys, array(JSONConstants::JSON_PROPERTY_CARDINALITY, JSONConstants::JSON_PROPERTY_VALUE, JSONConstants::JSON_PROPERTY_ID, JSONConstants::JSON_PROPERTY_DATATYPE))); $property = $this->getPropertyByPropertyType($propertyType, $id, $propertyValues); $property->populate($propertyData, $propertyKeys, true); $property->setExtensions($this->convertExtension($propertyData, $jsonPropertyKeys)); $properties->addProperty($property); } if (!empty($extensions)) { $properties->setExtensions($this->convertExtension($extensions)); } return $properties; }
public function testGetPropertyValueByQueryNameReturnsFirstPropertyValueFromSelectedProperty() { $sessionMock = $this->getMockBuilder('\\Dkd\\PhpCmis\\SessionInterface')->setMethods(array('getObjectFactory', 'getDefaultContext'))->getMockForAbstractClass(); $objectFactory = new ObjectFactory(); $objectFactory->initialize($sessionMock); $operationContext = new OperationContext(); $sessionMock->expects($this->once())->method('getObjectFactory')->willReturn($objectFactory); $sessionMock->expects($this->any())->method('getDefaultContext')->willReturn($operationContext); $values1 = array('foobar', 'barbaz', 'foobaz'); $property1 = new PropertyString('foo', $values1); $property1->setQueryName('baz:foo'); $values2 = array(123, 234, 345); $property2 = new PropertyInteger('bar', $values2); $property2->setQueryName('baz:bar'); $properties = new Properties(); $properties->addProperties(array($property1, $property2)); $objectData = new ObjectData(); $objectData->setProperties($properties); $queryResult = new QueryResult($sessionMock, $objectData); $this->assertEquals('foobar', $queryResult->getPropertyValueByQueryName('baz:foo')); $this->assertEquals(123, $queryResult->getPropertyValueByQueryName('baz:bar')); $this->assertEquals(null, $queryResult->getPropertyValueByQueryName('not:exists')); }