‪TYPO3CMS  ‪main
RecordHistoryStoreTest.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;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 
25 final class ‪RecordHistoryStoreTest extends FunctionalTestCase
26 {
28 
32  protected function ‪setUp(): void
33  {
34  parent::setUp();
35  $this->subject = new ‪RecordHistoryStore();
36  }
37 
38  protected function ‪getRecordCountByCorrelationId(‪CorrelationId $correlationId): int
39  {
40  $queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable('sys_history');
41  return (int)$queryBuilder
42  ->count('uid')
43  ->from('sys_history')
44  ->where($queryBuilder->expr()->eq('correlation_id', $queryBuilder->createNamedParameter((string)$correlationId)))
45  ->executeQuery()
46  ->fetchOne();
47  }
48 
49  #[Test]
50  public function ‪addRecordAddsARecordToTheDatabase(): void
51  {
52  $correlationId = ‪CorrelationId::forSubject('092a640c-bd8c-490d-b993-ed4bcef1a1f2');
53  self::assertSame(0, $this->‪getRecordCountByCorrelationId($correlationId));
54  $this->subject->addRecord('foo', 1, [], $correlationId);
55  self::assertSame(1, $this->‪getRecordCountByCorrelationId($correlationId));
56  }
57 
58  #[Test]
60  {
61  $correlationId = ‪CorrelationId::forSubject('058f117c-5e21-4222-b308-085fc1113604');
62  self::assertSame(0, $this->‪getRecordCountByCorrelationId($correlationId));
63  $this->subject->modifyRecord('foo', 1, [], $correlationId);
64  self::assertSame(1, $this->‪getRecordCountByCorrelationId($correlationId));
65  }
66 
67  #[Test]
69  {
70  $correlationId = ‪CorrelationId::forSubject('e1a2ea91-fe2f-4a01-b50b-5c2924a27568');
71  self::assertSame(0, $this->‪getRecordCountByCorrelationId($correlationId));
72  $this->subject->deleteRecord('foo', 1, $correlationId);
73  self::assertSame(1, $this->‪getRecordCountByCorrelationId($correlationId));
74  }
75 
76  #[Test]
78  {
79  $correlationId = ‪CorrelationId::forSubject('ab902256-56f2-43bd-b857-f7a0b974e9db');
80  self::assertSame(0, $this->‪getRecordCountByCorrelationId($correlationId));
81  $this->subject->undeleteRecord('foo', 1, $correlationId);
82  self::assertSame(1, $this->‪getRecordCountByCorrelationId($correlationId));
83  }
84 
85  #[Test]
86  public function ‪moveRecordAddsARecordToTheDatabase(): void
87  {
88  $correlationId = ‪CorrelationId::forSubject('9d806d3a-1d7a-4e62-816f-9fa1a1b3fe5b');
89  self::assertSame(0, $this->‪getRecordCountByCorrelationId($correlationId));
90  $this->subject->moveRecord('foo', 1, [], $correlationId);
91  self::assertSame(1, $this->‪getRecordCountByCorrelationId($correlationId));
92  }
93 }
‪TYPO3\CMS\Backend\Tests\Functional\History\RecordHistoryStoreTest\moveRecordAddsARecordToTheDatabase
‪moveRecordAddsARecordToTheDatabase()
Definition: RecordHistoryStoreTest.php:86
‪TYPO3\CMS\Backend\Tests\Functional\History\RecordHistoryStoreTest
Definition: RecordHistoryStoreTest.php:26
‪TYPO3\CMS\Backend\Tests\Functional\History\RecordHistoryStoreTest\modifyRecordAddsARecordToTheDatabase
‪modifyRecordAddsARecordToTheDatabase()
Definition: RecordHistoryStoreTest.php:59
‪TYPO3\CMS\Backend\Tests\Functional\History
Definition: RecordHistoryStoreTest.php:18
‪TYPO3\CMS\Backend\Tests\Functional\History\RecordHistoryStoreTest\addRecordAddsARecordToTheDatabase
‪addRecordAddsARecordToTheDatabase()
Definition: RecordHistoryStoreTest.php:50
‪TYPO3\CMS\Backend\Tests\Functional\History\RecordHistoryStoreTest\undeleteRecordAddsARecordToTheDatabase
‪undeleteRecordAddsARecordToTheDatabase()
Definition: RecordHistoryStoreTest.php:77
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore
Definition: RecordHistoryStore.php:31
‪TYPO3\CMS\Backend\Tests\Functional\History\RecordHistoryStoreTest\$subject
‪RecordHistoryStore $subject
Definition: RecordHistoryStoreTest.php:27
‪TYPO3\CMS\Backend\Tests\Functional\History\RecordHistoryStoreTest\deleteRecordAddsARecordToTheDatabase
‪deleteRecordAddsARecordToTheDatabase()
Definition: RecordHistoryStoreTest.php:68
‪TYPO3\CMS\Core\DataHandling\Model\CorrelationId
Definition: CorrelationId.php:29
‪TYPO3\CMS\Backend\Tests\Functional\History\RecordHistoryStoreTest\getRecordCountByCorrelationId
‪getRecordCountByCorrelationId(CorrelationId $correlationId)
Definition: RecordHistoryStoreTest.php:38
‪TYPO3\CMS\Backend\Tests\Functional\History\RecordHistoryStoreTest\setUp
‪setUp()
Definition: RecordHistoryStoreTest.php:32
‪TYPO3\CMS\Core\DataHandling\Model\CorrelationId\forSubject
‪static forSubject(string $subject, string ... $aspects)
Definition: CorrelationId.php:49