‪TYPO3CMS  ‪main
AbstractSectionTest.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 
20 use PHPUnit\Framework\Attributes\Test;
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
32 final class ‪AbstractSectionTest extends UnitTestCase
33 {
34  protected bool ‪$resetSingletonInstances = true;
35 
36  #[Test]
38  {
39  $this->expectException(IdentifierNotValidException::class);
40  $this->expectExceptionCode(1477082501);
41  new ‪AbstractSectionFixture('', 'foobar');
42  }
43 
44  #[Test]
46  {
47  $subject = new ‪AbstractSectionFixture('foobar', '');
48  self::assertInstanceOf(AbstractSection::class, $subject);
49  }
50 
51  #[Test]
53  {
54  $rootForm = $this->createMock(FormDefinition::class);
55  $this->expectException(TypeDefinitionNotFoundException::class);
56  $this->expectExceptionCode(1382364019);
57  $subject = new ‪AbstractSectionFixture('identifier', '');
58  $subject->setParentRenderable($rootForm);
59  $subject->createElement('', '');
60  }
61 
62  #[Test]
64  {
65  $rootForm = $this->createMock(FormDefinition::class);
66  $rootForm->method('getRenderingOptions')->willReturn(['skipUnknownElements' => true]);
67  GeneralUtility::addInstance(UnknownFormElement::class, new ‪UnknownFormElement('foo', 'bar'));
68  $subject = new ‪AbstractSectionFixture('testing', '');
69  $subject->setParentRenderable($rootForm);
70  $result = $subject->createElement('foo', 'bar');
71  self::assertInstanceOf(UnknownFormElement::class, $result);
72  self::assertSame('foo', $result->getIdentifier());
73  self::assertSame('bar', $result->getType());
74  }
75 
76  #[Test]
78  {
79  $this->expectException(TypeDefinitionNotFoundException::class);
80  $this->expectExceptionCode(1325689855);
81  $rootForm = $this->createMock(FormDefinition::class);
82  $rootForm->method('getTypeDefinitions')->willReturn(['foobar' => []]);
83  $subject = new ‪AbstractSectionFixture('testing', '');
84  $subject->setParentRenderable($rootForm);
85  $subject->createElement('id', 'foobar');
86  }
87 
88  #[Test]
90  {
91  $this->expectException(TypeDefinitionNotValidException::class);
92  $this->expectExceptionCode(1327318156);
93  $rootForm = $this->createMock(FormDefinition::class);
94  $rootForm->method('getTypeDefinitions')->willReturn([
95  'foobar' => [
96  'implementationClassName' => self::class,
97  ],
98  ]);
99  $subject = new ‪AbstractSectionFixture('testing', '');
100  $subject->setParentRenderable($rootForm);
101  GeneralUtility::addInstance(self::class, $this);
102  $subject->createElement('id', 'foobar');
103  }
104 
105  #[Test]
107  {
108  $implementationMock = $this->createMock(TestingFormElement::class);
109  $typeDefinition = [
110  'foo' => 'bar',
111  'implementationClassName' => get_class($implementationMock),
112  'fizz' => 'buzz',
113  ];
114  $typeDefinitionWithoutImplementationClassName = $typeDefinition;
115  unset($typeDefinitionWithoutImplementationClassName['implementationClassName']);
116  $implementationMock->expects(self::once())->method('initializeFormElement');
117  $implementationMock->expects(self::once())->method('setOptions')->with($typeDefinitionWithoutImplementationClassName);
118  $rootForm = $this->createMock(FormDefinition::class);
119  $rootForm->method('getTypeDefinitions')->willReturn(['foobar' => $typeDefinition]);
120  $subject = new ‪AbstractSectionFixture('testing', '');
121  $subject->setParentRenderable($rootForm);
122  GeneralUtility::addInstance(get_class($implementationMock), $implementationMock);
123  $subject->createElement('id', 'foobar');
124  }
125 }
‪TYPO3\CMS\Form\Domain\Exception\TypeDefinitionNotFoundException
Definition: TypeDefinitionNotFoundException.php:30
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\AbstractSectionTest\createElementThrowsExceptionIfTypeDefinitionIsNotSet
‪createElementThrowsExceptionIfTypeDefinitionIsNotSet()
Definition: AbstractSectionTest.php:77
‪TYPO3\CMS\Form\Domain\Exception\IdentifierNotValidException
Definition: IdentifierNotValidException.php:30
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\AbstractSectionTest\createElementThrowsExceptionIfTypeDefinitionNotFoundAndSkipUnknownElementsIsFalse
‪createElementThrowsExceptionIfTypeDefinitionNotFoundAndSkipUnknownElementsIsFalse()
Definition: AbstractSectionTest.php:52
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements
Definition: AbstractFormElementTest.php:18
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\Fixtures\TestingFormElement
Definition: TestingFormElement.php:26
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\AbstractSectionTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: AbstractSectionTest.php:34
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\AbstractSectionTest\constructThrowsExceptionWhenIdentifierIsEmpty
‪constructThrowsExceptionWhenIdentifierIsEmpty()
Definition: AbstractSectionTest.php:37
‪TYPO3\CMS\Form\Domain\Model\FormElements\AbstractSection
Definition: AbstractSection.php:43
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\AbstractSectionTest\createElementExpectedToAddAndInitializeElement
‪createElementExpectedToAddAndInitializeElement()
Definition: AbstractSectionTest.php:106
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\AbstractSectionTest\createElementThrowsExceptionIfTypeDefinitionNotInstanceOfFormElementInterface
‪createElementThrowsExceptionIfTypeDefinitionNotInstanceOfFormElementInterface()
Definition: AbstractSectionTest.php:89
‪TYPO3\CMS\Form\Domain\Model\FormElements\UnknownFormElement
Definition: UnknownFormElement.php:34
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\AbstractSectionTest\createElementReturnsUnknownElementsIfTypeDefinitionIsNotFoundAndSkipUnknownElementsIsTrue
‪createElementReturnsUnknownElementsIfTypeDefinitionIsNotFoundAndSkipUnknownElementsIsTrue()
Definition: AbstractSectionTest.php:63
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\AbstractSectionTest
Definition: AbstractSectionTest.php:33
‪TYPO3\CMS\Form\Domain\Model\FormDefinition
Definition: FormDefinition.php:224
‪TYPO3\CMS\Form\Domain\Exception\TypeDefinitionNotValidException
Definition: TypeDefinitionNotValidException.php:30
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\AbstractSectionTest\constructMustNotThrowExceptionWhenIdentifierIsNonEmptyString
‪constructMustNotThrowExceptionWhenIdentifierIsNonEmptyString()
Definition: AbstractSectionTest.php:45
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\Fixtures\AbstractSectionFixture
Definition: AbstractSectionFixture.php:22