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