17 use Doctrine\DBAL\Platforms\SQLServerPlatform;
41 protected function setUp()
45 $this->subject = $this->getMockBuilder(RecordCollectionRepository::class)
46 ->setMethods([
'getEnvironmentMode'])
48 $this->testTableName = $this->getUniqueId(
'tx_testtable');
55 GeneralUtility::makeInstance(ConnectionPool::class)
56 ->getConnectionForTable(
'sys_collection')
57 ->truncate(
'sys_collection');
66 $objects = $this->subject->findByType($type);
67 $this->assertNull($objects);
77 [
'uid' => 1,
'type' => $type,
'table_name' => $this->testTableName],
78 [
'uid' => 2,
'type' => $type,
'table_name' => $this->testTableName]
81 $objects = $this->subject->findByType($type);
82 $this->assertCount(2, $objects);
83 $this->assertInstanceOf(StaticRecordCollection::class, $objects[0]);
84 $this->assertInstanceOf(StaticRecordCollection::class, $objects[1]);
92 $objects = $this->subject->findByTableName($this->testTableName);
93 $this->assertNull($objects);
103 [
'uid' => 1,
'type' => $type,
'table_name' => $this->testTableName],
104 [
'uid' => 2,
'type' => $type,
'table_name' => $this->testTableName]
106 $objects = $this->subject->findByTableName($this->testTableName);
108 $this->assertCount(2, $objects);
109 $this->assertInstanceOf(StaticRecordCollection::class, $objects[0]);
110 $this->assertInstanceOf(StaticRecordCollection::class, $objects[1]);
119 $objects = $this->subject->findByTypeAndTableName($type, $this->testTableName);
121 $this->assertNull($objects);
131 [
'uid' => 1,
'type' => $type,
'table_name' => $this->testTableName],
132 [
'uid' => 2,
'type' => $type,
'table_name' => $this->testTableName]
134 $objects = $this->subject->findByTypeAndTableName($type, $this->testTableName);
136 $this->assertCount(2, $objects);
137 $this->assertInstanceOf(StaticRecordCollection::class, $objects[0]);
138 $this->assertInstanceOf(StaticRecordCollection::class, $objects[1]);
146 $this->subject->method(
'getEnvironmentMode')->willReturn(
'BE');
152 'table_name' => $this->testTableName,
159 $object = $this->subject->findByUid(1);
161 $this->assertInstanceOf(StaticRecordCollection::class, $object);
169 $this->subject->method(
'getEnvironmentMode')->willReturn(
'BE');
175 'table_name' => $this->testTableName,
182 $object = $this->subject->findByUid(1);
184 $this->assertNull($object);
192 $this->subject->method(
'getEnvironmentMode')->willReturn(
'BE');
198 'table_name' => $this->testTableName,
204 'table_name' => $this->testTableName,
205 'starttime' => time() + 99999,
210 'table_name' => $this->testTableName,
211 'endtime' => time() - 99999
214 $hiddenObject = $this->subject->findByUid(1);
215 $futureObject = $this->subject->findByUid(2);
216 $expiredObject = $this->subject->findByUid(3);
218 $this->assertInstanceOf(StaticRecordCollection::class, $hiddenObject);
219 $this->assertInstanceOf(StaticRecordCollection::class, $futureObject);
220 $this->assertInstanceOf(StaticRecordCollection::class, $expiredObject);
228 $this->subject->method(
'getEnvironmentMode')->willReturn(
'FE');
234 'table_name' => $this->testTableName,
241 $object = $this->subject->findByUid(1);
243 $this->assertInstanceOf(StaticRecordCollection::class, $object);
251 $this->subject->method(
'getEnvironmentMode')->willReturn(
'FE');
257 'table_name' => $this->testTableName,
263 'table_name' => $this->testTableName,
269 'table_name' => $this->testTableName,
270 'starttime' => time() + 99999,
275 'table_name' => $this->testTableName,
276 'endtime' => time() - 99999
279 $deletedObject = $this->subject->findByUid(1);
280 $hiddenObject = $this->subject->findByUid(2);
281 $futureObject = $this->subject->findByUid(3);
282 $expiredObject = $this->subject->findByUid(4);
284 $this->assertNull($deletedObject);
285 $this->assertNull($hiddenObject);
286 $this->assertNull($futureObject);
287 $this->assertNull($expiredObject);
297 $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable(
'sys_collection');
298 $platform = $connection->getDatabasePlatform();
299 $sqlServerIdentityDisabled =
false;
300 if ($platform instanceof SQLServerPlatform) {
302 $connection->exec(
'SET IDENTITY_INSERT sys_collection ON');
303 $sqlServerIdentityDisabled =
true;
304 }
catch (\Doctrine\DBAL\DBALException $e) {
312 $tableDetails = $connection->getSchemaManager()->listTableDetails(
'sys_collection');
313 foreach ($rows as $row) {
314 foreach ($row as $columnName => $columnValue) {
315 $types[] = $tableDetails->getColumn($columnName)->getType()->getBindingType();
320 foreach ($rows as $row) {
321 $connection->insert(
'sys_collection', $row, $types);
324 if ($sqlServerIdentityDisabled) {
326 $connection->exec(
'SET IDENTITY_INSERT sys_collection OFF');