‪TYPO3CMS  11.5
CreatablePropertyCollectionElementPropertiesValidatorTest.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 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
27 {
32  {
33  $this->expectException(PropertyException::class);
34  $this->expectExceptionCode(1528591502);
35 
36  $validationDto = new ‪ValidationDto('standard', null, 'test-1', 'label', 'validators', 'StringLength');
37  $typeConverter = $this->getAccessibleMock(
38  CreatablePropertyCollectionElementPropertiesValidator::class,
39  ['getConfigurationService'],
40  [[], '', $validationDto]
41  );
42  $configurationService = $this->createMock(ConfigurationService::class);
43  $configurationService->method(
44  'getPropertyCollectionPredefinedDefaultValueFromFormEditorSetup'
45  )->willReturn('default');
46  $typeConverter->method('getConfigurationService')->willReturn($configurationService);
47 
48  $input = 'xxx';
49  $typeConverter->_call('validatePropertyCollectionElementPredefinedDefaultValue', $input, $validationDto);
50  }
51 
56  {
57  $validationDto = new ‪ValidationDto(null, null, 'test-1', 'label', 'validators', 'StringLength');
58  $typeConverter = $this->getAccessibleMock(
59  CreatablePropertyCollectionElementPropertiesValidator::class,
60  ['getConfigurationService'],
61  [[], '', $validationDto]
62  );
63  $configurationService = $this->createMock(ConfigurationService::class);
64  $configurationService->method(
65  'getPropertyCollectionPredefinedDefaultValueFromFormEditorSetup'
66  )->willReturn('default');
67  $typeConverter->method('getConfigurationService')->willReturn($configurationService);
68 
69  $input = 'default';
70 
71  $failed = false;
72  try {
73  $typeConverter->_call('validatePropertyCollectionElementPredefinedDefaultValue', $input, $validationDto);
74  } catch (‪PropertyException $e) {
75  $failed = true;
76  }
77  self::assertFalse($failed);
78  }
79 
81  {
82  return [
83  [
84  'input' => 'foo',
85  'allowedValues' => [],
86  'untranslatedAllowedValues' => [],
87  ],
88  [
89  'input' => 'foo',
90  'allowedValues' => ['bar', 'baz'],
91  'untranslatedAllowedValues' => ['bar', 'baz'],
92  ],
93  [
94  'input' => 1,
95  'allowedValues' => ['1', 2],
96  'untranslatedAllowedValues' => ['1', 2],
97  ],
98  ];
99  }
100 
105  public function ‪validatePropertyCollectionPropertyValueThrowsExceptionIfValueDoesNotMatch($input, array $allowedValues, array $untranslatedAllowedValues): void
106  {
107  $this->expectException(PropertyException::class);
108 
109  $validationDto = new ‪ValidationDto('standard', null, 'test-1', 'label', 'validators', 'StringLength');
110  $validatorMock = $this->getAccessibleMock(
111  CreatablePropertyCollectionElementPropertiesValidator::class,
112  ['getConfigurationService'],
113  [[], '', $validationDto]
114  );
115 
116  $configurationServiceMock = $this->createMock(ConfigurationService::class);
117  $configurationServiceMock->method(
118  'getAllowedValuesForPropertyCollectionPropertyFromFormEditorSetup'
119  )->willReturnMap([
120  [$validationDto, true, $allowedValues],
121  [$validationDto, false, $untranslatedAllowedValues],
122  ]);
123 
124  $validatorMock->method('getConfigurationService')->willReturn($configurationServiceMock);
125 
126  $validatorMock->_call('validatePropertyCollectionPropertyValue', $input, $validationDto);
127  }
128 
130  {
131  return [
132  [
133  'input' => 'foo',
134  'allowedValues' => ['foo'],
135  'untranslatedAllowedValues' => ['foo'],
136  'allPossibleAllowedValuesTranslations' => [],
137  ],
138  [
139  'input' => 'foo',
140  'allowedValues' => ['bar'],
141  'untranslatedAllowedValues' => ['foo'],
142  'allPossibleAllowedValuesTranslations' => [],
143  ],
144  [
145  'input' => 'foo',
146  'allowedValues' => ['bar'],
147  'untranslatedAllowedValues' => ['baz'],
148  'allPossibleAllowedValuesTranslations' => ['default' => ['foo'], 'de' => ['bar']],
149  ],
150  [
151  'input' => 'foo',
152  'allowedValues' => ['foo', 'baz'],
153  'untranslatedAllowedValues' => ['foo', 'baz'],
154  'allPossibleAllowedValuesTranslations' => [],
155  ],
156  [
157  'input' => 1,
158  'allowedValues' => ['1', 1, 2],
159  'untranslatedAllowedValues' => ['1', 1, 2],
160  'allPossibleAllowedValuesTranslations' => [],
161  ],
162  ];
163  }
164 
169  public function ‪validatePropertyCollectionPropertyValueThrowsNoExceptionIfValueMatches($input, array $allowedValues, array $untranslatedAllowedValues, array $allPossibleAllowedValuesTranslations): void
170  {
171  $validationDto = new ‪ValidationDto('standard', null, 'test-1', 'label', 'validators', 'StringLength');
172  $validatorMock = $this->getAccessibleMock(
173  CreatablePropertyCollectionElementPropertiesValidator::class,
174  ['getConfigurationService'],
175  [[], '', $validationDto]
176  );
177 
178  $configurationServiceMock = $this->createMock(ConfigurationService::class);
179  $configurationServiceMock->method(
180  'getAllowedValuesForPropertyCollectionPropertyFromFormEditorSetup'
181  )->willReturnMap([
182  [$validationDto, true, $allowedValues],
183  [$validationDto, false, $untranslatedAllowedValues],
184  ]);
185  $configurationServiceMock->method('getAllBackendTranslationsForTranslationKeys')->willReturn($allPossibleAllowedValuesTranslations);
186  $validatorMock->method('getConfigurationService')->willReturn($configurationServiceMock);
187 
188  $failed = false;
189  try {
190  $validatorMock->_call('validatePropertyCollectionPropertyValue', $input, $validationDto);
191  } catch (‪PropertyException $e) {
192  $failed = true;
193  }
194  self::assertFalse($failed);
195  }
196 }
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidatorTest
Definition: CreatablePropertyCollectionElementPropertiesValidatorTest.php:27
‪TYPO3\CMS\Extbase\Property\Exception
Definition: DuplicateObjectException.php:18
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidatorTest\validatePropertyCollectionElementPredefinedDefaultValueThrowsExceptionIfValueDoesNotMatch
‪validatePropertyCollectionElementPredefinedDefaultValueThrowsExceptionIfValueDoesNotMatch()
Definition: CreatablePropertyCollectionElementPropertiesValidatorTest.php:31
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidatorTest\validatePropertyCollectionPropertyValueThrowsNoExceptionIfValueMatches
‪validatePropertyCollectionPropertyValueThrowsNoExceptionIfValueMatches($input, array $allowedValues, array $untranslatedAllowedValues, array $allPossibleAllowedValuesTranslations)
Definition: CreatablePropertyCollectionElementPropertiesValidatorTest.php:169
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\ValidationDto
Definition: ValidationDto.php:23
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidatorTest\validatePropertyCollectionElementPredefinedDefaultValueThrowsNoExceptionIfValueMatches
‪validatePropertyCollectionElementPredefinedDefaultValueThrowsNoExceptionIfValueMatches()
Definition: CreatablePropertyCollectionElementPropertiesValidatorTest.php:55
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidatorTest\validatePropertyCollectionPropertyValueThrowsNoExceptionIfValueMatchesDataProvider
‪validatePropertyCollectionPropertyValueThrowsNoExceptionIfValueMatchesDataProvider()
Definition: CreatablePropertyCollectionElementPropertiesValidatorTest.php:129
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinition\Validators
Definition: CreatableFormElementPropertiesValidatorTest.php:18
‪TYPO3\CMS\Form\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidator
Definition: CreatablePropertyCollectionElementPropertiesValidator.php:27
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidatorTest\validatePropertyCollectionPropertyValueThrowsExceptionIfValueDoesNotMatch
‪validatePropertyCollectionPropertyValueThrowsExceptionIfValueDoesNotMatch($input, array $allowedValues, array $untranslatedAllowedValues)
Definition: CreatablePropertyCollectionElementPropertiesValidatorTest.php:105
‪TYPO3\CMS\Form\Domain\Configuration\ConfigurationService
Definition: ConfigurationService.php:50
‪TYPO3\CMS\Form\Domain\Configuration\Exception\PropertyException
Definition: PropertyException.php:25
‪TYPO3\CMS\Form\Tests\Unit\Domain\Configuration\FormDefinition\Validators\CreatablePropertyCollectionElementPropertiesValidatorTest\validatePropertyCollectionPropertyValueThrowsExceptionIfValueDoesNotMatchDataProvider
‪validatePropertyCollectionPropertyValueThrowsExceptionIfValueDoesNotMatchDataProvider()
Definition: CreatablePropertyCollectionElementPropertiesValidatorTest.php:80