TYPO3 CMS  TYPO3_8-7
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 
26 
30 abstract class AbstractDataHandlerActionTestCase extends FunctionalTestCase
31 {
33 
38 
43 
50  protected $expectedErrorLogEntries = 0;
51 
55  protected $testExtensionsToLoad = [
56  'typo3/sysext/core/Tests/Functional/Fixtures/Extensions/irre_tutorial',
57  ];
58 
63  'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/AdditionalConfiguration.php' => 'typo3conf/AdditionalConfiguration.php',
64  ];
65 
69  protected $recordIds = [];
70 
74  protected $actionService;
75 
79  protected $backendUser;
80 
81  protected function setUp()
82  {
83  parent::setUp();
84 
85  $this->backendUser = $this->setUpBackendUserFromFixture(self::VALUE_BackendUserId);
86  // By default make tests on live workspace
87  $this->backendUser->workspace = 0;
88 
89  $this->actionService = $this->getActionService();
90  Bootstrap::getInstance()->initializeLanguageObject();
91  }
92 
93  protected function tearDown()
94  {
95  $this->assertErrorLogEntries();
96  unset($this->actionService);
97  unset($this->recordIds);
98  parent::tearDown();
99  }
100 
104  protected function getActionService()
105  {
107  ActionService::class
108  );
109  }
110 
114  protected function importScenarioDataSet($dataSetName)
115  {
116  $fileName = rtrim($this->scenarioDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
117  $fileName = GeneralUtility::getFileAbsFileName($fileName);
118  $this->importCSVDataSet($fileName);
119  }
120 
121  protected function assertAssertionDataSet($dataSetName)
122  {
123  $fileName = rtrim($this->assertionDataSetDirectory, '/') . '/' . $dataSetName . '.csv';
124  $fileName = GeneralUtility::getFileAbsFileName($fileName);
125  $this->assertCSVDataSet($fileName);
126  }
127 
131  protected function assertErrorLogEntries()
132  {
133  if ($this->expectedErrorLogEntries === null) {
134  return;
135  }
136 
137  $queryBuilder = $this->getConnectionPool()
138  ->getQueryBuilderForTable('sys_log');
139  $queryBuilder->getRestrictions()->removeAll();
140  $statement = $queryBuilder
141  ->select('*')
142  ->from('sys_log')
143  ->where(
144  $queryBuilder->expr()->in(
145  'error',
146  $queryBuilder->createNamedParameter([1, 2], Connection::PARAM_INT_ARRAY)
147  )
148  )
149  ->execute();
150 
151  $actualErrorLogEntries = $statement->rowCount();
152  if ($actualErrorLogEntries === $this->expectedErrorLogEntries) {
153  $this->assertSame($this->expectedErrorLogEntries, $actualErrorLogEntries);
154  } else {
155  $failureMessage = 'Expected ' . $this->expectedErrorLogEntries . ' entries in sys_log, but got ' . $actualErrorLogEntries . LF;
156  while ($entry = $statement->fetch()) {
157  $entryData = unserialize($entry['log_data']);
158  $entryMessage = vsprintf($entry['details'], $entryData);
159  $failureMessage .= '* ' . $entryMessage . LF;
160  }
161  $this->fail($failureMessage);
162  }
163  }
164 
169  {
170  return new HasRecordConstraint();
171  }
172 
177  {
178  return new DoesNotHaveRecordConstraint();
179  }
180 
185  {
186  return new StructureHasRecordConstraint();
187  }
188 
193  {
194  return new StructureDoesNotHaveRecordConstraint();
195  }
196 }
static getFileAbsFileName($filename, $_=null, $_2=null)
static makeInstance($className,... $constructorArguments)