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