‪TYPO3CMS  9.5
AbstractDataHandlerActionTestCase.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
22 use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\DoesNotHaveRecordConstraint;
23 use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\HasRecordConstraint;
24 use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\StructureDoesNotHaveRecordConstraint;
25 use TYPO3\TestingFramework\Core\Functional\Framework\Constraint\RequestSection\StructureHasRecordConstraint;
26 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\ActionService;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 
32 abstract class ‪AbstractDataHandlerActionTestCase extends FunctionalTestCase
33 {
35 
40 
45 
52  protected ‪$expectedErrorLogEntries = 0;
53 
57  protected ‪$testExtensionsToLoad = [
58  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/irre_tutorial',
59  ];
60 
64  protected ‪$pathsToLinkInTestInstance = [
65  'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
66  ];
67 
71  protected ‪$recordIds = [];
72 
76  protected ‪$actionService;
77 
81  protected ‪$backendUser;
82 
83  protected function ‪setUp()
84  {
85  parent::setUp();
86 
87  $this->backendUser = $this->setUpBackendUserFromFixture(self::VALUE_BackendUserId);
88  // By default make tests on live workspace
89  $this->‪setWorkspaceId(0);
90 
91  $this->actionService = $this->‪getActionService();
93  }
94 
95  protected function ‪tearDown()
96  {
97  $this->‪assertErrorLogEntries();
98  unset($this->actionService);
99  unset($this->recordIds);
100  parent::tearDown();
101  }
102 
106  protected function ‪setWorkspaceId(int $workspaceId)
107  {
108  $this->backendUser->workspace = $workspaceId;
109  GeneralUtility::makeInstance(Context::class)->setAspect('workspace', new ‪WorkspaceAspect($workspaceId));
110  }
111 
115  protected function ‪getActionService()
116  {
117  return GeneralUtility::makeInstance(
118  ActionService::class
119  );
120  }
121 
125  protected function ‪importScenarioDataSet($dataSetName)
126  {
127  $fileName = rtrim($this->scenarioDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
128  $fileName = GeneralUtility::getFileAbsFileName($fileName);
129  $this->importCSVDataSet($fileName);
130  }
131 
132  protected function ‪assertAssertionDataSet($dataSetName)
133  {
134  $fileName = rtrim($this->assertionDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
135  $fileName = GeneralUtility::getFileAbsFileName($fileName);
136  $this->assertCSVDataSet($fileName);
137  }
138 
142  protected function ‪assertErrorLogEntries()
143  {
144  if ($this->expectedErrorLogEntries === null) {
145  return;
146  }
147 
148  $queryBuilder = $this->getConnectionPool()
149  ->getQueryBuilderForTable('sys_log');
150  $queryBuilder->getRestrictions()->removeAll();
151  $statement = $queryBuilder
152  ->select('*')
153  ->from('sys_log')
154  ->where(
155  $queryBuilder->expr()->in(
156  'error',
157  $queryBuilder->createNamedParameter([1, 2], Connection::PARAM_INT_ARRAY)
158  )
159  )
160  ->execute();
161 
162  $actualErrorLogEntries = (int)$queryBuilder
163  ->count('uid')
164  ->execute()
165  ->fetchColumn(0);
166  if ($actualErrorLogEntries === (int)‪$this->expectedErrorLogEntries) {
167  $this->assertSame($this->expectedErrorLogEntries, $actualErrorLogEntries);
168  } else {
169  $failureMessage = 'Expected ' . $this->expectedErrorLogEntries . ' entries in sys_log, but got ' . $actualErrorLogEntries . LF;
170  while ($entry = $statement->fetch()) {
171  $entryData = unserialize($entry['log_data']);
172  $entryMessage = vsprintf($entry['details'], $entryData);
173  $failureMessage .= '* ' . $entryMessage . LF;
174  }
175  $this->fail($failureMessage);
176  }
177  }
178 
183  {
184  return new HasRecordConstraint();
185  }
186 
191  {
192  return new DoesNotHaveRecordConstraint();
193  }
194 
199  {
200  return new StructureHasRecordConstraint();
201  }
202 
207  {
208  return new StructureDoesNotHaveRecordConstraint();
209  }
210 }
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:29
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\getRequestSectionHasRecordConstraint
‪HasRecordConstraint getRequestSectionHasRecordConstraint()
Definition: AbstractDataHandlerActionTestCase.php:174
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\setUp
‪setUp()
Definition: AbstractDataHandlerActionTestCase.php:75
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\getRequestSectionStructureHasRecordConstraint
‪StructureHasRecordConstraint getRequestSectionStructureHasRecordConstraint()
Definition: AbstractDataHandlerActionTestCase.php:190
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\$expectedErrorLogEntries
‪int null $expectedErrorLogEntries
Definition: AbstractDataHandlerActionTestCase.php:49
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\VALUE_BackendUserId
‪const VALUE_BackendUserId
Definition: AbstractDataHandlerActionTestCase.php:34
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\$pathsToLinkInTestInstance
‪array $pathsToLinkInTestInstance
Definition: AbstractDataHandlerActionTestCase.php:59
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\getRequestSectionStructureDoesNotHaveRecordConstraint
‪StructureDoesNotHaveRecordConstraint getRequestSectionStructureDoesNotHaveRecordConstraint()
Definition: AbstractDataHandlerActionTestCase.php:198
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
Definition: AbstractDataHandlerActionTestCase.php:33
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\$backendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication $backendUser
Definition: AbstractDataHandlerActionTestCase.php:73
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\$scenarioDataSetDirectory
‪string $scenarioDataSetDirectory
Definition: AbstractDataHandlerActionTestCase.php:38
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\tearDown
‪tearDown()
Definition: AbstractDataHandlerActionTestCase.php:87
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\setWorkspaceId
‪setWorkspaceId(int $workspaceId)
Definition: AbstractDataHandlerActionTestCase.php:98
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\$assertionDataSetDirectory
‪string $assertionDataSetDirectory
Definition: AbstractDataHandlerActionTestCase.php:42
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\$recordIds
‪array $recordIds
Definition: AbstractDataHandlerActionTestCase.php:65
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\assertAssertionDataSet
‪assertAssertionDataSet($dataSetName)
Definition: AbstractDataHandlerActionTestCase.php:124
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\getRequestSectionDoesNotHaveRecordConstraint
‪DoesNotHaveRecordConstraint getRequestSectionDoesNotHaveRecordConstraint()
Definition: AbstractDataHandlerActionTestCase.php:182
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\$actionService
‪ActionService $actionService
Definition: AbstractDataHandlerActionTestCase.php:69
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\getActionService
‪ActionService getActionService()
Definition: AbstractDataHandlerActionTestCase.php:107
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:31
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:50
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\assertErrorLogEntries
‪assertErrorLogEntries()
Definition: AbstractDataHandlerActionTestCase.php:134
‪TYPO3\CMS\Core\Tests\Functional\DataHandling
Definition: AbstractDataHandlerActionTestCase.php:2
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\importScenarioDataSet
‪importScenarioDataSet($dataSetName)
Definition: AbstractDataHandlerActionTestCase.php:117
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static Bootstrap null initializeLanguageObject()
Definition: Bootstrap.php:986
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: AbstractDataHandlerActionTestCase.php:53