‪TYPO3CMS  ‪main
CheckboxValidationTest.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 TYPO3\CMS\Backend\Utility\BackendUtility;
26 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 
47 final class ‪CheckboxValidationTest extends FunctionalTestCase
48 {
49  protected const ‪PAGE_ID = 200;
50  protected const ‪PAGE_ID_OTHER = 300;
51 
52  protected array ‪$testExtensionsToLoad = [
53  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/test_datahandler',
54  ];
55 
56  protected array ‪$coreExtensionsToLoad = ['workspaces'];
57 
59 
60  protected function ‪setUp(): void
61  {
62  parent::setUp();
63  $this->importCSVDataSet(__DIR__ . '/DataSet/CheckboxRecordsEval.csv');
64  $this->importCSVDataSet(__DIR__ . '/../../Fixtures/be_users_admin.csv');
65  $this->backendUserAuthentication = $this->setUpBackendUser(1);
66  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($this->backendUserAuthentication);
67  }
68 
69  #[Test]
71  {
72  $actionService = new ActionService();
73  $map = $actionService->createNewRecord('tt_content', self::PAGE_ID, [
74  'tx_testdatahandler_checkbox_with_eval' => 1,
75  ]);
76  $newContentId = reset($map['tt_content']);
77  $newContentRecord = BackendUtility::getRecord('tt_content', $newContentId);
78 
79  self::assertEquals(1, $newContentRecord['tx_testdatahandler_checkbox_with_eval']);
80  }
81 
82  #[Test]
84  {
85  $actionService = new ActionService();
86  $actionService->createNewRecord('tt_content', self::PAGE_ID, [
87  'tx_testdatahandler_checkbox_with_eval' => 1,
88  ]);
89  $map = $actionService->createNewRecord('tt_content', self::PAGE_ID, [
90  'tx_testdatahandler_checkbox_with_eval' => 1,
91  ]);
92  $newContentId = reset($map['tt_content']);
93  $newContentRecord = BackendUtility::getRecord('tt_content', $newContentId);
94 
95  self::assertEquals(0, $newContentRecord['tx_testdatahandler_checkbox_with_eval']);
96  }
97 
98  #[Test]
100  {
101  $actionService = new ActionService();
102  $map = $actionService->createNewRecord('tt_content', self::PAGE_ID_OTHER, [
103  'tx_testdatahandler_checkbox_with_eval' => 1,
104  ]);
105  $newContentId = reset($map['tt_content']);
106  $newContentRecord = BackendUtility::getRecord('tt_content', $newContentId);
107 
108  self::assertEquals(1, $newContentRecord['tx_testdatahandler_checkbox_with_eval']);
109  }
110 
111  #[Test]
113  {
114  $actionService = new ActionService();
115  $actionService->createNewRecord('tt_content', self::PAGE_ID_OTHER, [
116  'tx_testdatahandler_checkbox_with_eval' => 1,
117  ]);
118  $map = $actionService->createNewRecord('tt_content', self::PAGE_ID_OTHER, [
119  'tx_testdatahandler_checkbox_with_eval' => 1,
120  ]);
121  $newContentId = reset($map['tt_content']);
122  $newContentRecord = BackendUtility::getRecord('tt_content', $newContentId);
123 
124  self::assertEquals(0, $newContentRecord['tx_testdatahandler_checkbox_with_eval']);
125  }
126 
127  #[Test]
129  {
130  $actionService = new ActionService();
131  $this->backendUserAuthentication->workspace = 1;
132  (new ‪Context())->setAspect('workspace', new ‪WorkspaceAspect(1));
133  $map = $actionService->createNewRecord('tt_content', self::PAGE_ID, [
134  'tx_testdatahandler_checkbox_with_eval' => 1,
135  ]);
136  $newContentId = reset($map['tt_content']);
137  $newContentRecord = BackendUtility::getRecord('tt_content', $newContentId);
138 
139  self::assertEquals(0, $newContentRecord['tx_testdatahandler_checkbox_with_eval']);
140  }
141 
142  #[Test]
144  {
145  $actionService = new ActionService();
146  $this->backendUserAuthentication->workspace = 1;
147  (new ‪Context())->setAspect('workspace', new ‪WorkspaceAspect(1));
148  $map = $actionService->createNewRecord('tt_content', self::PAGE_ID_OTHER, [
149  'tx_testdatahandler_checkbox_with_eval' => 1,
150  ]);
151  $newContentId = reset($map['tt_content']);
152  $newContentRecord = BackendUtility::getRecord('tt_content', $newContentId);
153 
154  self::assertEquals(0, $newContentRecord['tx_testdatahandler_checkbox_with_eval']);
155  }
156 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\validMaximumRecordsCheckedInPidPermitsPersisting
‪validMaximumRecordsCheckedInPidPermitsPersisting()
Definition: CheckboxValidationTest.php:99
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler
Definition: CheckboxValidationTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\PAGE_ID_OTHER
‪const PAGE_ID_OTHER
Definition: CheckboxValidationTest.php:50
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:31
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\violationOfMaximumRecordsCheckedInPidInWorkspaceResetsValueToZero
‪violationOfMaximumRecordsCheckedInPidInWorkspaceResetsValueToZero()
Definition: CheckboxValidationTest.php:143
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\PAGE_ID
‪const PAGE_ID
Definition: CheckboxValidationTest.php:49
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\validMaximumRecordsCheckedPermitsPersisting
‪validMaximumRecordsCheckedPermitsPersisting()
Definition: CheckboxValidationTest.php:70
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\violationOfMaximumRecordsCheckedInPidResetsValueToZero
‪violationOfMaximumRecordsCheckedInPidResetsValueToZero()
Definition: CheckboxValidationTest.php:112
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: CheckboxValidationTest.php:56
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\setUp
‪setUp()
Definition: CheckboxValidationTest.php:60
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest
Definition: CheckboxValidationTest.php:48
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\violationOfMaximumRecordsCheckedResetsValueToZero
‪violationOfMaximumRecordsCheckedResetsValueToZero()
Definition: CheckboxValidationTest.php:83
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\$backendUserAuthentication
‪BackendUserAuthentication $backendUserAuthentication
Definition: CheckboxValidationTest.php:58
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: CheckboxValidationTest.php:52
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\CheckboxValidationTest\violationOfMaximumRecordsCheckedInWorkspaceResetsValueToZero
‪violationOfMaximumRecordsCheckedInWorkspaceResetsValueToZero()
Definition: CheckboxValidationTest.php:128