‪TYPO3CMS  ‪main
FlexFormSegmentTest.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;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
27 final class ‪FlexFormSegmentTest extends UnitTestCase
28 {
30 
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34  $this->subject = new ‪FlexFormSegment();
35  }
36 
37  #[Test]
38  public function ‪compileReturnsIncomingData(): void
39  {
40  $orderingServiceMock = $this->createMock(DependencyOrderingService::class);
41  GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceMock);
42  $orderingServiceMock->method('orderByDependencies')->withAnyParameters()->willReturnArgument(0);
43 
44  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [];
45 
46  $input = ['foo'];
47 
48  self::assertEquals($input, $this->subject->compile($input));
49  }
50 
51  #[Test]
53  {
54  $orderingServiceMock = $this->createMock(DependencyOrderingService::class);
55  GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceMock);
56  $orderingServiceMock->method('orderByDependencies')->withAnyParameters()->willReturnArgument(0);
57 
58  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
59  \stdClass::class => [],
60  ];
61  GeneralUtility::addInstance(
62  \stdClass::class,
63  new class () extends \stdClass implements ‪FormDataProviderInterface {
64  public function addData(array $result)
65  {
66  return ['foo'];
67  }
68  }
69  );
70 
71  self::assertEquals(['foo'], $this->subject->compile([]));
72  }
73 
74  #[Test]
76  {
77  $orderingServiceMock = $this->createMock(DependencyOrderingService::class);
78  GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceMock);
79  $orderingServiceMock->method('orderByDependencies')->withAnyParameters()->willReturnArgument(0);
80 
81  ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['flexFormSegment'] = [
82  \stdClass::class => [],
83  ];
84 
85  $this->expectException(\UnexpectedValueException::class);
86  $this->expectExceptionCode(1485299408);
87 
88  $this->subject->compile([]);
89  }
90 }
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataGroup\FlexFormSegmentTest\compileThrowsExceptionIfDataProviderDoesNotImplementInterface
‪compileThrowsExceptionIfDataProviderDoesNotImplementInterface()
Definition: FlexFormSegmentTest.php:75
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataGroup\FlexFormSegmentTest\compileReturnsIncomingData
‪compileReturnsIncomingData()
Definition: FlexFormSegmentTest.php:38
‪TYPO3\CMS\Backend\Form\FormDataGroup\FlexFormSegment
Definition: FlexFormSegment.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataGroup\FlexFormSegmentTest\compileReturnsResultChangedByDataProvider
‪compileReturnsResultChangedByDataProvider()
Definition: FlexFormSegmentTest.php:52
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataGroup\FlexFormSegmentTest\$subject
‪FlexFormSegment $subject
Definition: FlexFormSegmentTest.php:29
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪TYPO3\CMS\Backend\Form\FormDataProviderInterface
Definition: FormDataProviderInterface.php:23
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataGroup\FlexFormSegmentTest\setUp
‪setUp()
Definition: FlexFormSegmentTest.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataGroup
Definition: FlexFormSegmentTest.php:18
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Tests\Unit\Form\FormDataGroup\FlexFormSegmentTest
Definition: FlexFormSegmentTest.php:28