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