‪TYPO3CMS  ‪main
FilesControlContainerTest.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;
21 use Symfony\Component\DependencyInjection\Container;
30 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
31 
32 final class ‪FilesControlContainerTest extends FunctionalTestCase
33 {
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37  ‪$GLOBALS['BE_USER'] = new ‪BackendUserAuthentication();
38  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default');
39  }
40 
41  #[Test]
42  public function ‪customFileControlsEventIsCalled(): void
43  {
44  $customFileControlsEvent = null;
45  $controls = ['foo', 'bar'];
46  $databaseRow = [
47  'uid' => 123,
48  ];
49  $fieldConfig = [
50  'minitems' => 1,
51  'maxitems' => 2,
52  ];
53  $fieldName = 'assets';
54  $tableName = 'tx_table';
55  $formFieldIdentifier = 'data-123-tx_table-123-assets';
56  $formFieldName = 'data[tx_table][123][assets]';
57 
59  $container = $this->get('service_container');
60  $container->set(
61  'custom-file-controls-listener',
62  static function (‪CustomFileControlsEvent $event) use (&$customFileControlsEvent, $controls) {
63  $customFileControlsEvent = $event;
64  $event->‪setControls($controls);
65  $event->‪setResultArray(['javaScriptModules' => ['fooJavaScriptModule']]);
66  }
67  );
68 
69  $eventListener = $this->get(ListenerProvider::class);
70  $eventListener->addListener(CustomFileControlsEvent::class, 'custom-file-controls-listener');
71 
72  $subject = $this->get(FilesControlContainer::class);
73  $subject->setData([
74  'inlineData' => [],
75  'inlineStructure' => [],
76  'inlineFirstPid' => 123,
77  'fieldName' => $fieldName,
78  'tableName' => $tableName,
79  'renderType' => 'file',
80  'databaseRow' => $databaseRow,
81  'tabAndInlineStack' => '',
82  'request' => (new ‪ServerRequest())
83  ->withAttribute('route', new ‪Route('', []))
84  ->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE),
85  'parameterArray' => [
86  'itemFormElName' => '',
87  'fieldConf' => [
88  'label' => 'foobar',
89  'config' => $fieldConfig,
90  'children' => [],
91  ],
92  ],
93  'returnUrl' => '',
94  ]);
95  $result = $subject->render();
96 
97  self::assertInstanceOf(CustomFileControlsEvent::class, $customFileControlsEvent);
98  self::assertContains('fooJavaScriptModule', $result['javaScriptModules']);
99  self::assertContains('fooJavaScriptModule', $customFileControlsEvent->getResultArray()['javaScriptModules']);
100  self::assertEquals($controls, $customFileControlsEvent->getControls());
101  self::assertEquals($databaseRow, $customFileControlsEvent->getDatabaseRow());
102  self::assertArrayHasKey('minitems', $customFileControlsEvent->getFieldConfig());
103  self::assertArrayHasKey('maxitems', $customFileControlsEvent->getFieldConfig());
104  self::assertEquals($fieldName, $customFileControlsEvent->getFieldName());
105  self::assertEquals($formFieldIdentifier, $customFileControlsEvent->getFormFieldIdentifier());
106  self::assertEquals($formFieldName, $customFileControlsEvent->getFormFieldName());
107  self::assertEquals($tableName, $customFileControlsEvent->getTableName());
108  }
109 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Backend\Routing\Route
Definition: Route.php:24
‪TYPO3\CMS\Backend\Tests\Functional\Form\Container
Definition: FilesControlContainerTest.php:18
‪TYPO3\CMS\Backend\Form\Container\FilesControlContainer
Definition: FilesControlContainer.php:49
‪TYPO3\CMS\Backend\Form\Event\CustomFileControlsEvent\setControls
‪setControls(array $controls)
Definition: CustomFileControlsEvent.php:56
‪TYPO3\CMS\Backend\Tests\Functional\Form\Container\FilesControlContainerTest\customFileControlsEventIsCalled
‪customFileControlsEventIsCalled()
Definition: FilesControlContainerTest.php:42
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Functional\Form\Container\FilesControlContainerTest\setUp
‪setUp()
Definition: FilesControlContainerTest.php:34
‪TYPO3\CMS\Backend\Form\Event\CustomFileControlsEvent
Definition: CustomFileControlsEvent.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Form\Event\CustomFileControlsEvent\setResultArray
‪setResultArray(array $resultArray)
Definition: CustomFileControlsEvent.php:46
‪TYPO3\CMS\Backend\Tests\Functional\Form\Container\FilesControlContainerTest
Definition: FilesControlContainerTest.php:33
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30