‪TYPO3CMS  10.4
PersistentObjectConverterTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 class ‪PersistentObjectConverterTest extends FunctionalTestCase
29 {
30  protected function ‪setUp(): void
31  {
32  parent::setUp();
33  $this->importDataSet(__DIR__ . '/../Fixtures/DatabaseImports/be_users.xml');
34  }
35 
40  {
41  $propertyMapper = $this->getContainer()->get(PropertyMapper::class);
42 
43  self::assertNull($propertyMapper->convert(0, BackendUser::class));
44  self::assertNull($propertyMapper->convert('', BackendUser::class));
45  }
46 
51  {
52  static::expectException(Exception::class);
53  static::expectExceptionCode(1297759968);
54  static::expectExceptionMessage('Exception while property mapping at property path "": The identity property "foo" is no UID.');
55 
56  $this->getContainer()->get(PropertyMapper::class)->convert('foo', BackendUser::class);
57  }
58 
63  {
64  static::expectException(TargetNotFoundException::class);
65  static::expectExceptionCode(1297933823);
66  static::expectExceptionMessage('Object of type TYPO3\CMS\Extbase\Domain\Model\BackendUser with identity "2" not found.');
67 
68  $this->getContainer()->get(PropertyMapper::class)->convert(2, BackendUser::class);
69  }
70 
75  {
76  $propertyMapper = $this->getContainer()->get(PropertyMapper::class);
77 
78  $backendUser = $propertyMapper->convert(1, BackendUser::class);
79 
80  self::assertInstanceOf(BackendUser::class, $backendUser);
81  self::assertSame(1, $backendUser->getUid());
82  }
83 
88  {
89  $propertyMapper = $this->getContainer()->get(PropertyMapper::class);
90 
91  $backendUser = $propertyMapper->convert('1', BackendUser::class);
92 
93  self::assertInstanceOf(BackendUser::class, $backendUser);
94  self::assertSame(1, $backendUser->getUid());
95  }
96 
101  {
102  $propertyMapper = $this->getContainer()->get(PropertyMapper::class);
103 
104  $backendUser = $propertyMapper->convert([], BackendUser::class);
105 
106  self::assertInstanceOf(BackendUser::class, $backendUser);
107  self::assertNull($backendUser->getUid());
108  }
109 
114  {
115  $propertyMapper = $this->getContainer()->get(PropertyMapper::class);
116 
117  $backendUser = $propertyMapper->convert(['__identity' => 1], BackendUser::class);
118 
119  self::assertInstanceOf(BackendUser::class, $backendUser);
120  self::assertSame(1, $backendUser->getUid());
121  }
122 
127  {
128  static::expectException(Exception::class);
129  static::expectExceptionCode(1297759968);
130  static::expectExceptionMessage('Exception while property mapping at property path "": Creation of objects not allowed. To enable this, you need to set the PropertyMappingConfiguration Value "CONFIGURATION_CREATION_ALLOWED" to TRUE');
131 
132  $propertyMapperConfiguration = new ‪PropertyMappingConfiguration();
133  $propertyMapperConfiguration->setTypeConverterOption(
134  PersistentObjectConverter::class,
136  false
137  );
138 
139  $this->getContainer()->get(PropertyMapper::class)->convert(
140  [],
141  BackendUser::class,
142  $propertyMapperConfiguration
143  );
144  }
145 
150  {
151  $propertyMapper = $this->getContainer()->get(PropertyMapper::class);
152 
153  $backendUser = $propertyMapper->convert(['userName' => 'johndoe'], BackendUser::class);
154 
155  self::assertInstanceOf(BackendUser::class, $backendUser);
156  self::assertNull($backendUser->getUid());
157  self::assertSame('johndoe', $backendUser->getUserName());
158  }
159 
164  {
165  static::expectException(Exception::class);
166  static::expectExceptionCode(1297759968);
167  static::expectExceptionMessage('Exception while property mapping at property path "": Property "nonExistant" was not found in target object of type "TYPO3\CMS\Extbase\Domain\Model\BackendUser".');
168 
169  $this->getContainer()->get(PropertyMapper::class)->convert(['nonExistant' => 'johndoe'], BackendUser::class);
170  }
171 
176  {
177  static::expectException(Exception::class);
178  static::expectExceptionCode(1297759968);
179  static::expectExceptionMessage('Exception while property mapping at property path "": Property "uid" having a value of type "integer" could not be set in target object of type "TYPO3\CMS\Extbase\Domain\Model\BackendUser"');
180 
181  $this->getContainer()->get(PropertyMapper::class)->convert(['uid' => 7], BackendUser::class);
182  }
183 }
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\converterFetchesObjectFromPersistenceIfSourceIsAnArrayWithIdentityKey
‪converterFetchesObjectFromPersistenceIfSourceIsAnArrayWithIdentityKey()
Definition: PersistentObjectConverterTest.php:113
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest
Definition: PersistentObjectConverterTest.php:29
‪TYPO3\CMS\Extbase\Property\Exception
Definition: DuplicateObjectException.php:18
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\converterRespectsAndSetsProperties
‪converterRespectsAndSetsProperties()
Definition: PersistentObjectConverterTest.php:149
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\converterBuildsEmptyObjectIfSourceIsAnEmptyArray
‪converterBuildsEmptyObjectIfSourceIsAnEmptyArray()
Definition: PersistentObjectConverterTest.php:100
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\converterReturnsNullWithEmptyStringsOrIntegers
‪converterReturnsNullWithEmptyStringsOrIntegers()
Definition: PersistentObjectConverterTest.php:39
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\getTypeOfChildPropertyThrowsInvalidTargetExceptionIfPropertyIsNonExistant
‪getTypeOfChildPropertyThrowsInvalidTargetExceptionIfPropertyIsNonExistant()
Definition: PersistentObjectConverterTest.php:163
‪TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter\CONFIGURATION_CREATION_ALLOWED
‪const CONFIGURATION_CREATION_ALLOWED
Definition: PersistentObjectConverter.php:52
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\fetchObjectFromPersistenceThrowsInvalidSourceExceptionIfSourceIANonNumericString
‪fetchObjectFromPersistenceThrowsInvalidSourceExceptionIfSourceIANonNumericString()
Definition: PersistentObjectConverterTest.php:50
‪TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter
Definition: PersistentObjectConverter.php:43
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\fetchObjectFromPersistenceThrowsTargetNotFoundExceptionIfObjectIsNotToBeFoundInThePersistence
‪fetchObjectFromPersistenceThrowsTargetNotFoundExceptionIfObjectIsNotToBeFoundInThePersistence()
Definition: PersistentObjectConverterTest.php:62
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter
Definition: ArrayConverterTest.php:18
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration
Definition: PropertyMappingConfiguration.php:22
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\handleArrayDataThrowsInvalidPropertyMappingConfigurationExceptionIfCreationOfObjectsIsNotAllowed
‪handleArrayDataThrowsInvalidPropertyMappingConfigurationExceptionIfCreationOfObjectsIsNotAllowed()
Definition: PersistentObjectConverterTest.php:126
‪TYPO3\CMS\Extbase\Property\PropertyMapper
Definition: PropertyMapper.php:37
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\setUp
‪setUp()
Definition: PersistentObjectConverterTest.php:30
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\converterFetchesObjectFromPersistenceIfSourceIsANumericString
‪converterFetchesObjectFromPersistenceIfSourceIsANumericString()
Definition: PersistentObjectConverterTest.php:87
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\convertFromThrowsInvalidTargetExceptionIfSourceContainsANonSettableProperty
‪convertFromThrowsInvalidTargetExceptionIfSourceContainsANonSettableProperty()
Definition: PersistentObjectConverterTest.php:175
‪TYPO3\CMS\Extbase\Tests\Functional\Property\TypeConverter\PersistentObjectConverterTest\converterFetchesObjectFromPersistenceIfSourceIsAnInteger
‪converterFetchesObjectFromPersistenceIfSourceIsAnInteger()
Definition: PersistentObjectConverterTest.php:74
‪TYPO3\CMS\Extbase\Domain\Model\BackendUser
Definition: BackendUser.php:25
‪TYPO3\CMS\Extbase\Property\Exception\TargetNotFoundException
Definition: TargetNotFoundException.php:26