Inheritance: implements Neos\Flow\Property\PropertyMappingConfigurationInterface
 /**
  * @test
  */
 public function convertFromConvertsDateTimeImmutableObjects()
 {
     $date = new \DateTimeImmutable('1980-12-13');
     $propertyMappingConfiguration = new PropertyMappingConfiguration();
     $propertyMappingConfiguration->setTypeConverterOption(StringConverter::class, StringConverter::CONFIGURATION_DATE_FORMAT, 'd.m.Y');
     $this->assertEquals('13.12.1980', $this->converter->convertFrom($date, 'string', [], $propertyMappingConfiguration));
 }
 /**
  * @test
  */
 public function getTypeOfChildPropertyImmediatelyReturnsConfiguredTargetTypeIfSetSo()
 {
     $propertyName = 'somePropertyName';
     $expectedTargetType = 'someExpectedTargetType';
     $configuration = new PropertyMappingConfiguration();
     $configuration->forProperty($propertyName)->setTypeConverterOption(ObjectConverter::class, ObjectConverter::CONFIGURATION_TARGET_TYPE, $expectedTargetType);
     $actual = $this->converter->getTypeOfChildProperty('irrelevant', $propertyName, $configuration);
     $this->assertEquals($expectedTargetType, $actual);
 }
Example #3
0
 /**
  * @test
  */
 public function convertSkipsUnknownPropertiesIfConfiguredTo()
 {
     $source = ['firstProperty' => 1, 'secondProperty' => 2];
     $typeConverters = ['array' => ['stdClass' => [10 => $this->getMockTypeConverter('array2object', true, $source, 'integer')]], 'integer' => ['integer' => [10 => $this->getMockTypeConverter('integer2integer')]]];
     $configuration = new PropertyMappingConfiguration();
     $propertyMapper = $this->getAccessibleMock(PropertyMapper::class, ['dummy']);
     $propertyMapper->_set('typeConverters', $typeConverters);
     $propertyMapper->convert($source, 'stdClass', $configuration->allowProperties('firstProperty')->skipUnknownProperties());
     // dummy assertion to avoid PHPUnit warning
     $this->assertTrue(true);
 }
 /**
  * @test
  */
 public function convertFromProperlyConvertsArrayWithDateAsArray()
 {
     $source = ['day' => '13', 'month' => '10', 'year' => '2010'];
     $mappingConfiguration = new PropertyMappingConfiguration();
     $mappingConfiguration->setTypeConverterOption(DateTimeConverter::class, DateTimeConverter::CONFIGURATION_DATE_FORMAT, 'Y-m-d');
     $date = $this->converter->convertFrom($source, 'DateTime', [], $mappingConfiguration);
     $actualResult = $date->format('Y-m-d');
     $this->assertSame('2010-10-13', $actualResult);
 }
 /**
  * @param array $typeConverterOptions
  * @return PropertyMappingConfiguration
  */
 protected function buildConfiguration($typeConverterOptions)
 {
     $configuration = new PropertyMappingConfiguration();
     $configuration->setTypeConverterOptions(PersistentObjectConverter::class, $typeConverterOptions);
     return $configuration;
 }
Example #6
0
 /**
  * Data provider with invalid configuration for target type overrides
  *
  * @return array
  */
 public function invalidTypeConverterConfigurationsForOverridingTargetTypes()
 {
     $configurationWithNoSetting = new PropertyMappingConfiguration();
     $configurationWithOverrideOff = new PropertyMappingConfiguration();
     $configurationWithOverrideOff->setTypeConverterOption(ObjectConverter::class, ObjectConverter::CONFIGURATION_OVERRIDE_TARGET_TYPE_ALLOWED, false);
     return [[null], [$configurationWithNoSetting], [$configurationWithOverrideOff]];
 }
 /**
  * @test
  */
 public function getTypeOfChildPropertyShouldRemoveLeadingBackslashesForAnnotationParameters()
 {
     $this->mockReflectionService->expects($this->any())->method('getMethodParameters')->with('TheTargetType', '__construct')->will($this->returnValue([]));
     $this->mockReflectionService->expects($this->any())->method('hasMethod')->with('TheTargetType', 'setThePropertyName')->will($this->returnValue(false));
     $this->mockReflectionService->expects($this->any())->method('getClassPropertyNames')->with('TheTargetType')->will($this->returnValue(['thePropertyName']));
     $this->mockReflectionService->expects($this->any())->method('getPropertyTagValues')->with('TheTargetType', 'thePropertyName')->will($this->returnValue(['\\TheTypeOfSubObject']));
     $configuration = new PropertyMappingConfiguration();
     $configuration->setTypeConverterOptions(ObjectConverter::class, []);
     $this->assertEquals('TheTypeOfSubObject', $this->converter->getTypeOfChildProperty('TheTargetType', 'thePropertyName', $configuration));
 }
 /**
  * Modify the passed $propertyMappingConfiguration according to the $propertyConfiguration which
  * has been generated by Fluid. In detail, if the $propertyConfiguration contains
  * an __identity field, we allow modification of objects; else we allow creation.
  *
  * All other properties are specified as allowed properties.
  *
  * @param array $propertyConfiguration
  * @param PropertyMappingConfiguration $propertyMappingConfiguration
  * @return void
  */
 protected function modifyPropertyMappingConfiguration($propertyConfiguration, PropertyMappingConfiguration $propertyMappingConfiguration)
 {
     if (!is_array($propertyConfiguration)) {
         return;
     }
     if (isset($propertyConfiguration['__identity'])) {
         $propertyMappingConfiguration->setTypeConverterOption(PersistentObjectConverter::class, PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED, true);
         unset($propertyConfiguration['__identity']);
     } else {
         $propertyMappingConfiguration->setTypeConverterOption(PersistentObjectConverter::class, PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true);
     }
     foreach ($propertyConfiguration as $innerKey => $innerValue) {
         if (is_array($innerValue)) {
             $this->modifyPropertyMappingConfiguration($innerValue, $propertyMappingConfiguration->forProperty($innerKey));
         }
         $propertyMappingConfiguration->allowProperties($innerKey);
     }
 }
 /**
  * @test
  * @expectedException \Neos\Flow\I18n\Exception\InvalidLocaleIdentifierException
  */
 public function convertFromThrowsExceptionIfLocaleIsInvalid()
 {
     $configuration = new PropertyMappingConfiguration();
     $configuration->setTypeConverterOption(FloatConverter::class, 'locale', 'some-non-existent-locale-identifier');
     $this->converter->convertFrom('84,42', 'float', [], $configuration);
 }
 /**
  * @test
  */
 public function forPropertyWithAsteriskAllowsArbitraryPropertyNamesWithShouldMap()
 {
     $this->propertyMappingConfiguration->forProperty('items.*')->setTypeConverterOptions('stdClass', ['k1' => 'v1']);
     $configuration = $this->propertyMappingConfiguration->forProperty('items');
     $this->assertTrue($configuration->shouldMap(6));
 }
 /**
  * Parses the request body according to the media type.
  *
  * @param HttpRequest $httpRequest
  * @return array
  */
 protected function parseRequestBody(HttpRequest $httpRequest)
 {
     $requestBody = $httpRequest->getContent();
     if ($requestBody === null || $requestBody === '') {
         return [];
     }
     $mediaTypeConverter = $this->objectManager->get(MediaTypeConverterInterface::class);
     $propertyMappingConfiguration = new PropertyMappingConfiguration();
     $propertyMappingConfiguration->setTypeConverter($mediaTypeConverter);
     $propertyMappingConfiguration->setTypeConverterOption(MediaTypeConverterInterface::class, MediaTypeConverterInterface::CONFIGURATION_MEDIA_TYPE, $httpRequest->getHeader('Content-Type'));
     $arguments = $this->propertyMapper->convert($requestBody, 'array', $propertyMappingConfiguration);
     return $arguments;
 }
 /**
  * @test
  */
 public function unknownNodePropertiesAreSkippedIfTypeConverterIsConfiguredLikeThis()
 {
     $this->setupNodeWithShadowNodeInPersonalWorkspace();
     $input = array('__contextNodePath' => '/headline@' . $this->currentTestWorkspaceName, 'title' => 'New title', 'non-existing-input' => 'test');
     $propertyMappingConfiguration = new PropertyMappingConfiguration();
     $propertyMappingConfiguration->skipUnknownProperties();
     $headlineNode = $this->convert($input, $propertyMappingConfiguration);
     $this->assertSame('New title', $headlineNode->getProperty('title'));
     $this->assertSame('Brave new world', $headlineNode->getProperty('subtitle'));
     $this->assertFalse($headlineNode->hasProperty('non-existing-input'));
 }
 /**
  * @param PropertyMappingConfiguration $propertyMappingConfiguration
  * @param string $typeConverterClass
  * @param string $dataType
  * @return void
  */
 protected function setTypeConverterOptionsForType(PropertyMappingConfiguration $propertyMappingConfiguration, $typeConverterClass, $dataType)
 {
     if (!isset($this->typesConfiguration[$dataType]['typeConverterOptions']) || !is_array($this->typesConfiguration[$dataType]['typeConverterOptions'])) {
         return;
     }
     foreach ($this->typesConfiguration[$dataType]['typeConverterOptions'] as $option => $value) {
         $propertyMappingConfiguration->setTypeConverterOption($typeConverterClass, $option, $value);
     }
 }
 /**
  * @test
  */
 public function convertFromReturnsNullIfResourcePropertyIsNotConverted()
 {
     $this->mockObjectManager->expects($this->any())->method('getClassNameByObjectName')->will($this->returnCallback(function ($objectType) {
         return $objectType;
     }));
     $configuration = new PropertyMappingConfiguration();
     $configuration->setTypeConverterOption(ImageInterfaceConverter::class, PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED, true);
     $this->assertNull($this->converter->convertFrom(array(), Image::class, array(), $configuration));
 }