2 declare(strict_types = 1);
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
39 $this->expectException(IdentifierNotValidException::class);
40 $this->expectExceptionCode(1477082501);
42 $this->getAccessibleMockForAbstractClass(AbstractSection::class, [
'',
'foobar']);
50 $mock = $this->getAccessibleMockForAbstractClass(AbstractSection::class, [
'foobar',
'foobar']);
51 $this->assertInstanceOf(AbstractSection::class, $mock);
60 $rootForm = $this->getMockBuilder(FormDefinition::class)
61 ->setMethods([
'getRenderingOptions',
'getTypeDefinitions'])
62 ->disableOriginalConstructor()
65 ->expects($this->any())
66 ->method(
'getRenderingOptions')
67 ->willReturn([
'skipUnknownElements' =>
false]);
69 ->expects($this->any())
70 ->method(
'getTypeDefinitions')
73 $mockAbstractSection = $this->getAccessibleMockForAbstractClass(
74 AbstractSection::class,
86 ->expects($this->once())
87 ->method(
'getRootForm')
88 ->willReturn($rootForm);
90 $this->expectException(TypeDefinitionNotFoundException::class);
91 $this->expectExceptionCode(1382364019);
93 $mockAbstractSection->_call(
'createElement',
'',
'');
102 $rootForm = $this->getMockBuilder(FormDefinition::class)
103 ->setMethods([
'getRenderingOptions',
'getTypeDefinitions'])
104 ->disableOriginalConstructor()
107 ->expects($this->any())
108 ->method(
'getRenderingOptions')
109 ->willReturn([
'skipUnknownElements' =>
true]);
111 ->expects($this->any())
112 ->method(
'getTypeDefinitions')
116 $mockAbstractSection = $this->getAccessibleMockForAbstractClass(
117 AbstractSection::class,
130 ->expects($this->any())
131 ->method(
'getRootForm')
132 ->willReturn($rootForm);
134 $objectManager = $this->getMockBuilder(ObjectManager::class)
135 ->setMethods([
'get'])
136 ->disableOriginalConstructor()
140 ->expects($this->any())
144 GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager);
145 $result = $mockAbstractSection->createElement(
'foo',
'bar');
146 GeneralUtility::removeSingletonInstance(ObjectManager::class, $objectManager);
148 $this->assertInstanceOf(UnknownFormElement::class, $result);
149 $this->assertSame(
'foo', $result->getIdentifier());
150 $this->assertSame(
'bar', $result->getType());
159 $rootForm = $this->getMockBuilder(FormDefinition::class)
160 ->setMethods([
'getRenderingOptions',
'getTypeDefinitions'])
161 ->disableOriginalConstructor()
164 ->expects($this->any())
165 ->method(
'getRenderingOptions')
166 ->willReturn([
'skipUnknownElements' =>
true]);
168 ->expects($this->any())
169 ->method(
'getTypeDefinitions')
170 ->willReturn([
'foobar' => []]);
173 $mockAbstractSection = $this->getAccessibleMockForAbstractClass(
174 AbstractSection::class,
186 ->expects($this->any())
187 ->method(
'getRootForm')
188 ->willReturn($rootForm);
190 $this->expectException(TypeDefinitionNotFoundException::class);
191 $this->expectExceptionCode(1325689855);
193 $mockAbstractSection->createElement(
'id',
'foobar');
201 $this->resetSingletonInstances =
true;
203 $mockAbstractSection = $this->getAccessibleMockForAbstractClass(
204 AbstractSection::class,
216 $rootForm = $this->getMockBuilder(FormDefinition::class)
217 ->setMethods([
'getRenderingOptions',
'getTypeDefinitions'])
218 ->disableOriginalConstructor()
221 ->expects($this->any())
222 ->method(
'getRenderingOptions')
225 ->expects($this->any())
226 ->method(
'getTypeDefinitions')
230 'implementationClassName' => self::class
236 ->expects($this->any())
237 ->method(
'getRootForm')
238 ->willReturn($rootForm);
240 $objectManager = $this->createMock(ObjectManager::class);
246 GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager);
248 $this->expectException(TypeDefinitionNotValidException::class);
249 $this->expectExceptionCode(1327318156);
250 $mockAbstractSection->createElement(
'id',
'foobar');
252 GeneralUtility::removeSingletonInstance(ObjectManager::class, $objectManager);
260 $implementationMock = $this->getMockForAbstractClass(
261 AbstractFormElement::class,
267 [
'setOptions',
'initializeFormElement']
272 'implementationClassName' => get_class($implementationMock),
276 $typeDefinitionWithoutImplementationClassName = $typeDefinition;
277 unset($typeDefinitionWithoutImplementationClassName[
'implementationClassName']);
280 ->expects($this->once())
281 ->method(
'initializeFormElement');
284 ->expects($this->once())
285 ->method(
'setOptions')
286 ->with($typeDefinitionWithoutImplementationClassName);
289 $mockAbstractSection = $this->getAccessibleMockForAbstractClass(
290 AbstractSection::class,
302 $rootForm = $this->getMockBuilder(FormDefinition::class)
303 ->setMethods([
'getRenderingOptions',
'getTypeDefinitions'])
304 ->disableOriginalConstructor()
307 ->expects($this->any())
308 ->method(
'getRenderingOptions')
311 ->expects($this->any())
312 ->method(
'getTypeDefinitions')
313 ->willReturn([
'foobar' => $typeDefinition]);
316 ->expects($this->any())
317 ->method(
'getRootForm')
318 ->willReturn($rootForm);
320 $objectManager = $this->createMock(ObjectManager::class);
323 ->with(get_class($implementationMock))
324 ->willReturn($implementationMock);
326 GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager);
328 $mockAbstractSection->createElement(
'id',
'foobar');
330 GeneralUtility::removeSingletonInstance(ObjectManager::class, $objectManager);