‪TYPO3CMS  ‪main
ActionTest.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;
23 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 final class ‪ActionTest extends FunctionalTestCase
27 {
28  private const ‪VALUE_ContentId = 100;
29 
30  protected function ‪setUp(): void
31  {
32  parent::setUp();
33  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
34  $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultElements.csv');
35  $this->importCSVDataSet(__DIR__ . '/../../Fixtures/be_users_admin.csv');
36  $backendUser = $this->setUpBackendUser(1);
37  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
38  }
39 
40  #[Test]
42  {
43  ‪$GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds']['default'] = '<?xml version="1.0" encoding="UTF-8"?>
44 <T3DataStructure>
45  <meta>
46  <langDisable>0</langDisable>
47  </meta>
48  <ROOT type="array">
49  <type>array</type>
50  <el type="array">
51  <settings.bodytext>
52  <label>Random Bodytext</label>
53  <config type="array">
54  <type>text</type>
55  <cols>48</cols>
56  <rows>5</rows>
57  <enableRichtext>1</enableRichtext>
58  <richtextConfiguration>default</richtextConfiguration>
59  </config>
60  </settings.bodytext>
61  </el>
62  </ROOT>
63 </T3DataStructure>';
64 
65  $expected = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
66 <T3FlexForms>
67  <data>
68  <sheet index="sDEF">
69  <language index="lDEF">
70  <field index="settings.isNotDefined">1</field>
71  <field index="settings.bodytext">
72  <value index="vDEF">&lt;p class=&quot;align-right&quot;&gt;First line&lt;/p&gt;
73 &lt;p&gt;Last line&lt;/p&gt;</value>
74  </field>
75  </language>
76  </sheet>
77  </data>
78 </T3FlexForms>';
79 
80  $actionService = new ActionService();
81  $actionService->modifyRecords(1, [
82  'tt_content' => [
83  'uid' => self::VALUE_ContentId,
84  'pi_flexform' => [
85  'data' => [
86  'sDEF' => [
87  'lDEF' => [
88  'settings.isNotDefined' => '1',
89  'settings.bodytext' => [
90  'vDEF' => '<p class="align-right">First line</p>
91 
92 <p>Last line</p>',
93  ],
94  ],
95  ],
96  ],
97  ],
98  ],
99  ]);
100 
101  $queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable('tt_content');
102  $queryBuilder->getRestrictions()->removeAll();
103  $flexFormContent = $queryBuilder
104  ->select('pi_flexform')
105  ->from('tt_content')
106  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(self::VALUE_ContentId, ‪Connection::PARAM_INT)))
107  ->executeQuery()
108  ->fetchOne();
109 
110  self::assertEquals($expected, $flexFormContent);
111  }
112 
113  #[Test]
115  {
116  ‪$GLOBALS['TCA']['tt_content']['columns']['pi_flexform']['config']['ds']['default'] = '<T3DataStructure>
117  <meta>
118  <langDisable>1</langDisable>
119  </meta>
120  <sheets>
121  <sheet1>
122  <ROOT>
123  <sheetTitle>Text Example with an RTE field</sheetTitle>
124  <type>array</type>
125  <el>
126  <settings.bodytext>
127  <label>Random Bodytext</label>
128  <config>
129  <type>text</type>
130  <rows>5</rows>
131  <cols>30</cols>
132  <required>1</required>
133  <eval>trim</eval>
134  <enableRichtext>1</enableRichtext>
135  <richtextConfiguration>default</richtextConfiguration>
136  </config>
137  </settings.bodytext>
138  </el>
139  </ROOT>
140  </sheet1>
141  </sheets>
142 </T3DataStructure>';
143 
144  $expected = '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
145 <T3FlexForms>
146  <data>
147  <sheet index="sheet1">
148  <language index="lDEF">
149  <field index="settings.isNotDefined">1</field>
150  <field index="settings.bodytext">
151  <value index="vDEF">&lt;p class=&quot;align-right&quot;&gt;First line&lt;/p&gt;
152 &lt;p&gt;Last line&lt;/p&gt;</value>
153  </field>
154  </language>
155  </sheet>
156  </data>
157 </T3FlexForms>';
158 
159  $actionService = new ActionService();
160  $actionService->modifyRecords(1, [
161  'tt_content' => [
162  'uid' => self::VALUE_ContentId,
163  'pi_flexform' => [
164  'data' => [
165  'sheet1' => [
166  'lDEF' => [
167  'settings.isNotDefined' => '1',
168  'settings.bodytext' => [
169  'vDEF' => '<p class="align-right">First line</p>
170 
171 <p>Last line</p>',
172  ],
173  ],
174  ],
175  ],
176  ],
177  ],
178  ]);
179 
180  $queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable('tt_content');
181  $queryBuilder->getRestrictions()->removeAll();
182  $flexFormContent = $queryBuilder
183  ->select('pi_flexform')
184  ->from('tt_content')
185  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(self::VALUE_ContentId, ‪Connection::PARAM_INT)))
186  ->executeQuery()
187  ->fetchOne();
188 
189  self::assertEquals($expected, $flexFormContent);
190  }
191 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Flexform\ActionTest\setUp
‪setUp()
Definition: ActionTest.php:30
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Flexform\ActionTest\transformationAppliesForRichTextFieldsWithoutSheets
‪transformationAppliesForRichTextFieldsWithoutSheets()
Definition: ActionTest.php:41
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Flexform\ActionTest\VALUE_ContentId
‪const VALUE_ContentId
Definition: ActionTest.php:28
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Flexform\ActionTest
Definition: ActionTest.php:27
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Flexform\ActionTest\transformationAppliesForRichTextFieldsWithSheets
‪transformationAppliesForRichTextFieldsWithSheets()
Definition: ActionTest.php:114
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Flexform
Definition: ActionTest.php:18