‪TYPO3CMS  10.4
DefaultValuesTest.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 
23 
28 {
32  const ‪PAGE_DATAHANDLER = 88;
33 
37  protected ‪$scenarioDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/';
38 
39  protected function ‪setUp(): void
40  {
41  parent::setUp();
42  $this->‪importScenarioDataSet('LiveDefaultPages');
43  $this->‪importScenarioDataSet('LiveDefaultElements');
44  $this->backendUser->workspace = 0;
45  }
46 
51  {
52  ‪$GLOBALS['TCA']['pages']['columns']['keywords']['config']['default'] = 'a few,random,keywords';
53  $map = $this->actionService->createNewRecord('pages', self::PAGE_DATAHANDLER, [
54  'title' => 'A new age'
55  ]);
56  $newPageId = reset($map['pages']);
57  $newPageRecord = ‪BackendUtility::getRecord('pages', $newPageId);
58  self::assertEquals($newPageRecord['keywords'], ‪$GLOBALS['TCA']['pages']['columns']['keywords']['config']['default']);
59 
60  ‪$GLOBALS['TCA']['tt_content']['columns']['header']['config']['default'] = 'Pre-set header';
61  $map = $this->actionService->createNewRecord('tt_content', $newPageId, [
62  'header' => '',
63  'bodytext' => 'Random bodytext'
64  ]);
65  $newContentId = reset($map['tt_content']);
66  $newContentRecord = ‪BackendUtility::getRecord('tt_content', $newContentId);
67  // Empty header is used, because it was handed in
68  self::assertEquals($newContentRecord['header'], '');
69 
70  $map = $this->actionService->createNewRecord('tt_content', $newPageId, [
71  'bodytext' => 'Random bodytext'
72  ]);
73  $newContentId = reset($map['tt_content']);
74  $newContentRecord = ‪BackendUtility::getRecord('tt_content', $newContentId);
75  self::assertEquals($newContentRecord['header'], ‪$GLOBALS['TCA']['tt_content']['columns']['header']['config']['default']);
76  }
77 
82  {
84 TCAdefaults.pages.keywords = from pagets, with love
85 TCAdefaults.tt_content.header = global space');
86  $map = $this->actionService->createNewRecord('pages', self::PAGE_DATAHANDLER, [
87  'title' => 'A new age'
88  ]);
89  $newPageId = reset($map['pages']);
90  $newPageRecord = ‪BackendUtility::getRecord('pages', $newPageId);
91  self::assertEquals($newPageRecord['keywords'], 'from pagets, with love');
92 
93  $map = $this->actionService->createNewRecord('tt_content', $newPageId, [
94  'header' => '',
95  'bodytext' => 'Random bodytext'
96  ]);
97  $newContentId = reset($map['tt_content']);
98  $newContentRecord = ‪BackendUtility::getRecord('tt_content', $newContentId);
99  // Empty header is used, because it was handed in
100  self::assertEquals($newContentRecord['header'], '');
101 
102  $map = $this->actionService->createNewRecord('tt_content', $newPageId, [
103  'bodytext' => 'Random bodytext'
104  ]);
105  $newContentId = reset($map['tt_content']);
106  $newContentRecord = ‪BackendUtility::getRecord('tt_content', $newContentId);
107  self::assertEquals($newContentRecord['header'], 'global space');
108  }
109 
114  {
116 TCAdefaults.pages.keywords = from pagets, with love
117 TCAdefaults.tt_content.header = global space');
118  $this->actionService->modifyRecord('pages', self::PAGE_DATAHANDLER, [
119  'TSconfig' => '
120 
121 TCAdefaults.pages.keywords = I am specific, not generic
122 TCAdefaults.tt_content.header = local space
123 
124 ']);
125  $map = $this->actionService->createNewRecord('pages', self::PAGE_DATAHANDLER, [
126  'title' => 'A new age'
127  ]);
128  $newPageId = reset($map['pages']);
129  $newPageRecord = ‪BackendUtility::getRecord('pages', $newPageId);
130  self::assertEquals($newPageRecord['keywords'], 'I am specific, not generic');
131 
132  $map = $this->actionService->createNewRecord('tt_content', $newPageId, [
133  'header' => '',
134  'bodytext' => 'Random bodytext'
135  ]);
136  $newContentId = reset($map['tt_content']);
137  $newContentRecord = ‪BackendUtility::getRecord('tt_content', $newContentId);
138  // Empty header is used, because it was handed in
139  self::assertEquals($newContentRecord['header'], '');
140 
141  $map = $this->actionService->createNewRecord('tt_content', $newPageId, [
142  'bodytext' => 'Random bodytext'
143  ]);
144  $newContentId = reset($map['tt_content']);
145  $newContentRecord = ‪BackendUtility::getRecord('tt_content', $newContentId);
146  self::assertEquals($newContentRecord['header'], 'local space');
147  }
148 
152  public function ‪defaultValueForNullTextfieldsIsConsidered(): void
153  {
154  // New content element without bodytext
155  ‪$GLOBALS['TCA']['tt_content']['columns']['bodytext']['l10n_mode'] = 'exclude';
156  ‪$GLOBALS['TCA']['tt_content']['columns']['bodytext']['config']['enableRichtext'] = true;
157  $map = $this->actionService->createNewRecord('tt_content', self::PAGE_DATAHANDLER, [
158  'header' => 'Random header',
159  'bodytext' => null
160  ]);
161  $newContentId = reset($map['tt_content']);
162  $map = $this->actionService->localizeRecord('tt_content', $newContentId, 1);
163  $translatedContentId = reset($map['tt_content']);
164  $newContentRecord = ‪BackendUtility::getRecord('tt_content', $translatedContentId);
165  self::assertNull($newContentRecord['bodytext']);
166  }
167 }
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler
Definition: DefaultValuesTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\DefaultValuesTest\defaultValuesFromTCAForNewRecordsIsRespected
‪defaultValuesFromTCAForNewRecordsIsRespected()
Definition: DefaultValuesTest.php:49
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\DefaultValuesTest\setUp
‪setUp()
Definition: DefaultValuesTest.php:38
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\DefaultValuesTest
Definition: DefaultValuesTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\DefaultValuesTest\defaultValuesFromPageSpecificTSconfigForNewRecordsIsRespected
‪defaultValuesFromPageSpecificTSconfigForNewRecordsIsRespected()
Definition: DefaultValuesTest.php:112
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
Definition: AbstractDataHandlerActionTestCase.php:37
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\DefaultValuesTest\$scenarioDataSetDirectory
‪string $scenarioDataSetDirectory
Definition: DefaultValuesTest.php:36
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\DefaultValuesTest\defaultValueForNullTextfieldsIsConsidered
‪defaultValueForNullTextfieldsIsConsidered()
Definition: DefaultValuesTest.php:151
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\DefaultValuesTest\defaultValuesFromGlobalTSconfigForNewRecordsIsRespected
‪defaultValuesFromGlobalTSconfigForNewRecordsIsRespected()
Definition: DefaultValuesTest.php:80
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\addPageTSConfig
‪static addPageTSConfig($content)
Definition: ExtensionManagementUtility.php:985
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\DefaultValuesTest\PAGE_DATAHANDLER
‪const PAGE_DATAHANDLER
Definition: DefaultValuesTest.php:32
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\importScenarioDataSet
‪importScenarioDataSet($dataSetName)
Definition: AbstractDataHandlerActionTestCase.php:201