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