‪TYPO3CMS  9.5
GridContainerTest.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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪GridContainerTest extends UnitTestCase
29 {
30 
35  {
37  $gridContainerInterfaceMock = $this->createMock(GridContainerInterface::class);
38  $gridContainerInterfaceMock
39  ->expects($this->any())
40  ->method('getIdentifier')
41  ->willReturn('bar');
42 
44  $gridContainerMock = $this->getMockBuilder(GridContainer::class)
45  ->setMethods(['getIdentifier', 'getElementsRecursively'])
46  ->disableOriginalConstructor()
47  ->getMock();
48 
49  $gridContainerMock
50  ->expects($this->any())
51  ->method('getIdentifier')
52  ->willReturn('foo');
53 
54  $gridContainerMock
55  ->expects($this->any())
56  ->method('getElementsRecursively')
57  ->willReturn([$gridContainerInterfaceMock]);
58 
59  $this->assertSame([$gridContainerInterfaceMock], $gridContainerMock->getElementsRecursively());
60  $this->assertTrue($gridContainerMock->getElementsRecursively()[0] instanceof ‪GridContainerInterface);
61 
62  $this->expectException(TypeDefinitionNotValidException::class);
63  $this->expectExceptionCode(1489412790);
64 
65  $gridContainerMock->registerInFormIfPossible();
66  }
67 
72  {
74  $element = $this->createMock(FormElementInterface::class);
75 
77  $gridContainer = $this->getMockBuilder(GridContainer::class)
78  ->setMethods(['getElementsRecursively'])
79  ->disableOriginalConstructor()
80  ->getMock();
81 
82  $element
83  ->expects($this->any())
84  ->method('getIdentifier')
85  ->willReturn('foobar');
86 
87  $element
88  ->expects($this->any())
89  ->method('getType')
90  ->willReturn('FormElementOrSomethingLikeThat');
91 
92  $gridContainer
93  ->expects($this->any())
94  ->method('getElementsRecursively')
95  ->willReturn($element);
96 
97  $this->expectException(TypeDefinitionNotValidException::class);
98  $this->expectExceptionCode(1489486301);
99 
100  $gridContainer->addElement($element);
101  }
102 
107  {
109  $element = $this->createMock(GridRowInterface::class);
110 
112  $gridContainer = $this->getAccessibleMockForAbstractClass(
113  GridContainer::class,
114  [],
115  '',
116  [],
117  true,
118  true,
119  ['addRenderable']
120  );
121 
122  $gridContainer->expects($this->once())->method('addRenderable');
123  $gridContainer->addElement($element);
124  }
125 }
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements
Definition: AbstractFormElementTest.php:3
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\GridContainerTest\addElementExpectedCallAddRenderableIfInstanceOfGridRowInterface
‪addElementExpectedCallAddRenderableIfInstanceOfGridRowInterface()
Definition: GridContainerTest.php:106
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\GridContainerTest\registerInFormIfPossibleThrowsTypeDefinitionNotValidExceptionIfAChildIsGridContainerInterface
‪registerInFormIfPossibleThrowsTypeDefinitionNotValidExceptionIfAChildIsGridContainerInterface()
Definition: GridContainerTest.php:34
‪TYPO3\CMS\Form\Domain\Model\FormElements\FormElementInterface
Definition: FormElementInterface.php:36
‪TYPO3\CMS\Form\Domain\Model\FormElements\GridContainerInterface
Definition: GridContainerInterface.php:22
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\GridContainerTest
Definition: GridContainerTest.php:29
‪TYPO3\CMS\Form\Domain\Model\FormElements\GridRowInterface
Definition: GridRowInterface.php:22
‪TYPO3\CMS\Form\Domain\Model\FormElements\GridContainer
Definition: GridContainer.php:29
‪TYPO3\CMS\Form\Domain\Exception\TypeDefinitionNotValidException
Definition: TypeDefinitionNotValidException.php:27
‪TYPO3\CMS\Form\Tests\Unit\Domain\FormElements\GridContainerTest\addElementThrowsTypeDefinitionNotValidExceptionIfNotInstanceOfGridRowInterface
‪addElementThrowsTypeDefinitionNotValidExceptionIfNotInstanceOfGridRowInterface()
Definition: GridContainerTest.php:71