‪TYPO3CMS  11.5
WorkspaceVersionRecordMigrationTest.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\MockObject\MockObject;
22 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
23 
24 class ‪WorkspaceVersionRecordMigrationTest extends FunctionalTestCase
25 {
26  private ‪$records;
27 
31  private ‪$subject;
32 
33  protected function ‪setUp(): void
34  {
35  parent::setUp();
36  $this->records = $this->‪fetchRecordsFromCsv();
37  $this->subject = $this->getMockBuilder(WorkspaceVersionRecordsMigration::class)
38  ->onlyMethods(['fetchPageId'])
39  ->getMock();
40  }
41 
42  protected function ‪tearDown(): void
43  {
44  unset($this->records, $this->subject);
45  parent::tearDown();
46  }
47 
51  public function ‪hasPotentialUpdateForTtContent(): void
52  {
53  $this->subject->expects(self::never())->method('fetchPageId');
54  self::assertTrue($this->subject->hasPotentialUpdateForTable('tt_content'));
55  }
56 
60  public function ‪recordsAreUpdated(): void
61  {
62  $this->subject->expects(self::atLeastOnce())
63  ->method('fetchPageId')
64  ->willReturnCallback(function ($tableName, $id) {
65  if ($tableName !== 'tt_content' || !isset($this->records[$id]['pid'])) {
66  return null;
67  }
68  return ['pid' => $this->records[$id]['pid']];
69  });
70  ‪$records = [];
71  foreach ($this->records as $record) {
72  ‪$records[] = $this->subject->updateTableRow('tt_content', $record);
73  }
74  $pageIds = array_column(‪$records, 'pid', 'uid');
75  $pageIds = array_map('intval', $pageIds);
76  self::assertNotContains(-1, $pageIds);
77 
78  $differences = array_diff_key(
79  [
80  21 => 20, // modified
81  22 => 20, // deleted
82  23 => 30, // moved
83  26 => 20, // created
84  28 => 20, // created & discarded
85  30 => 41, // created & moved
86  32 => 20, // localized
87  34 => 20, // localized
88  ],
89  $pageIds
90  );
91  self::assertEmpty(
92  $differences,
93  sprintf('Different values for record IDs %s', implode(', ', array_keys($differences)))
94  );
95  }
96 
101  private function ‪fetchRecordsFromCsv(): array
102  {
103  ‪$records = [];
104  $resource = fopen(dirname(__DIR__) . '/Fixtures/tt_content_versions.csv', 'r');
105  while (false !== ($record = fgetcsv($resource))) {
106  ‪$records[] = $record;
107  }
108  fclose($resource);
109 
110  $names = array_shift(‪$records);
111  ‪$records = array_map(
112  static function (array $values) use ($names) {
113  return array_combine($names, $values);
114  },
116  );
117  ‪$records = array_column(‪$records, null, 'uid');
118  return ‪$records;
119  }
120 }
‪TYPO3\CMS\Install\Updates\RowUpdater\WorkspaceVersionRecordsMigration
Definition: WorkspaceVersionRecordsMigration.php:33
‪TYPO3\CMS\Install\Tests\Functional\Updates\RowUpdater\WorkspaceVersionRecordMigrationTest\fetchRecordsFromCsv
‪array fetchRecordsFromCsv()
Definition: WorkspaceVersionRecordMigrationTest.php:100
‪TYPO3\CMS\Install\Tests\Functional\Updates\RowUpdater
Definition: WorkspaceNewPlaceholderRemovalTest.php:18
‪TYPO3\CMS\Install\Tests\Functional\Updates\RowUpdater\WorkspaceVersionRecordMigrationTest\setUp
‪setUp()
Definition: WorkspaceVersionRecordMigrationTest.php:32
‪TYPO3\CMS\Install\Tests\Functional\Updates\RowUpdater\WorkspaceVersionRecordMigrationTest\hasPotentialUpdateForTtContent
‪hasPotentialUpdateForTtContent()
Definition: WorkspaceVersionRecordMigrationTest.php:50
‪TYPO3\CMS\Install\Tests\Functional\Updates\RowUpdater\WorkspaceVersionRecordMigrationTest\$records
‪$records
Definition: WorkspaceVersionRecordMigrationTest.php:26
‪TYPO3\CMS\Install\Tests\Functional\Updates\RowUpdater\WorkspaceVersionRecordMigrationTest\recordsAreUpdated
‪recordsAreUpdated()
Definition: WorkspaceVersionRecordMigrationTest.php:59
‪TYPO3\CMS\Install\Tests\Functional\Updates\RowUpdater\WorkspaceVersionRecordMigrationTest
Definition: WorkspaceVersionRecordMigrationTest.php:25
‪TYPO3\CMS\Install\Tests\Functional\Updates\RowUpdater\WorkspaceVersionRecordMigrationTest\$subject
‪WorkspaceVersionRecordsMigration MockObject $subject
Definition: WorkspaceVersionRecordMigrationTest.php:30
‪TYPO3\CMS\Install\Tests\Functional\Updates\RowUpdater\WorkspaceVersionRecordMigrationTest\tearDown
‪tearDown()
Definition: WorkspaceVersionRecordMigrationTest.php:41