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