‪TYPO3CMS  ‪main
SynchronizeFolderRelationsTest.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;
24 use TYPO3\CMS\Core\Resource\Driver\LocalDriver;
29 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
30 
31 final class ‪SynchronizeFolderRelationsTest extends FunctionalTestCase
32 {
34 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38 
39  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
40  $backendUser = $this->setUpBackendUser(1);
41  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
42 
43  $this->subject = new ‪SynchronizeFolderRelations(
44  $this->get(ConnectionPool::class),
45  $this->get(FlashMessageService::class)
46  );
47  }
48 
49  #[Test]
51  {
52  $this->importCSVDataSet(__DIR__ . '/Fixtures/FilemountsBase.csv');
53 
54  // Nothing should change if the renamed identifier is the same as the current one
55  $this->subject->synchronizeFilemountsAfterRename($this->‪getAfterFolderRenamedEvent('/foo/bar/'));
56  $this->assertCSVDataSet(__DIR__ . '/Fixtures/FilemountsBase.csv');
57 
58  // Relations should be changed if the renamed identifier differs from the current one
59  $this->subject->synchronizeFilemountsAfterRename($this->‪getAfterFolderRenamedEvent('/foo/renamed/'));
60  $this->assertCSVDataSet(__DIR__ . '/Fixtures/FilemountsResult.csv');
61 
62  // Check for generated flash messages
63  $flashMessages = $this->get(FlashMessageService::class)->getMessageQueueByIdentifier()->getAllMessages();
64  self::assertNotEmpty($flashMessages);
65 
66  // Check flash message content
67  $flashMessage = array_shift($flashMessages);
68  self::assertStringContainsString('6 Filemount records', $flashMessage->getMessage());
69  }
70 
71  #[Test]
73  {
74  $this->importCSVDataSet(__DIR__ . '/Fixtures/FileCollectionBase.csv');
75 
76  // Nothing should change if the renamed identifier is the same as the current one
77  $this->subject->synchronizeFileCollectionsAfterRename($this->‪getAfterFolderRenamedEvent('/foo/bar/'));
78  $this->assertCSVDataSet(__DIR__ . '/Fixtures/FileCollectionBase.csv');
79 
80  // Relations should be changed if the renamed identifier differs from the current one
81  $this->subject->synchronizeFileCollectionsAfterRename($this->‪getAfterFolderRenamedEvent('/foo/renamed/'));
82  $this->assertCSVDataSet(__DIR__ . '/Fixtures/FileCollectionResult.csv');
83 
84  // Check for generated flash messages
85  $flashMessages = $this->get(FlashMessageService::class)->getMessageQueueByIdentifier()->getAllMessages();
86  self::assertNotEmpty($flashMessages);
87 
88  // Check flash message content
89  $flashMessage = array_shift($flashMessages);
90  self::assertStringContainsString('5 File collection records', $flashMessage->getMessage());
91  }
92 
93  protected function ‪getAfterFolderRenamedEvent(string $targetIdentifier): ‪AfterFolderRenamedEvent
94  {
95  $sourceDriver = $this->createMock(LocalDriver::class);
96  $storage = new ‪ResourceStorage($sourceDriver, ['uid' => 1]);
97  $targetFolder = new ‪Folder($storage, $targetIdentifier, 'renamed folder');
98  $sourceFolder = new ‪Folder($storage, '/foo/bar/', 'some folder');
99  return new ‪AfterFolderRenamedEvent($targetFolder, $sourceFolder);
100  }
101 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Tests\Functional\Resource\SynchronizeFolderRelationsTest\$subject
‪SynchronizeFolderRelations $subject
Definition: SynchronizeFolderRelationsTest.php:33
‪TYPO3\CMS\Core\Tests\Functional\Resource
Definition: DefaultUploadFolderResolverTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\Resource\SynchronizeFolderRelationsTest\setUp
‪setUp()
Definition: SynchronizeFolderRelationsTest.php:35
‪TYPO3\CMS\Core\Resource\Event\AfterFolderRenamedEvent
Definition: AfterFolderRenamedEvent.php:28
‪TYPO3\CMS\Core\Tests\Functional\Resource\SynchronizeFolderRelationsTest\synchronizeFilemountsAfterRenameTest
‪synchronizeFilemountsAfterRenameTest()
Definition: SynchronizeFolderRelationsTest.php:50
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:38
‪TYPO3\CMS\Core\Tests\Functional\Resource\SynchronizeFolderRelationsTest\synchronizeFileCollectionsAfterRenameTest
‪synchronizeFileCollectionsAfterRenameTest()
Definition: SynchronizeFolderRelationsTest.php:72
‪TYPO3\CMS\Core\Tests\Functional\Resource\SynchronizeFolderRelationsTest
Definition: SynchronizeFolderRelationsTest.php:32
‪TYPO3\CMS\Core\Resource\ResourceStorage
Definition: ResourceStorage.php:129
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Tests\Functional\Resource\SynchronizeFolderRelationsTest\getAfterFolderRenamedEvent
‪getAfterFolderRenamedEvent(string $targetIdentifier)
Definition: SynchronizeFolderRelationsTest.php:93
‪TYPO3\CMS\Core\Resource\SynchronizeFolderRelations
Definition: SynchronizeFolderRelations.php:39
‪TYPO3\CMS\Core\Messaging\FlashMessageService
Definition: FlashMessageService.php:27