‪TYPO3CMS  ‪main
DefaultUploadFolderResolverTest.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 Symfony\Component\DependencyInjection\Container;
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 final class ‪DefaultUploadFolderResolverTest extends FunctionalTestCase
28 {
29  public function ‪setUp(): void
30  {
31  parent::setUp();
32  $this->importCSVDataSet(__DIR__ . '/Fixtures/DefaultUploadFolderResolver/be_users.csv');
33  $this->importCSVDataSet(__DIR__ . '/Fixtures/DefaultUploadFolderResolver/pages.csv');
34  }
35 
36  public function ‪tearDown(): void
37  {
38  ‪GeneralUtility::rmdir($this->instancePath . '/fileadmin/admin_upload/', true);
39  ‪GeneralUtility::rmdir($this->instancePath . '/fileadmin/page_upload/', true);
40  parent::tearDown();
41  }
42 
46  public function ‪resolveWithUserAndPageConfigTest(): void
47  {
48  ‪GeneralUtility::mkdir($this->instancePath . '/fileadmin/page_upload/');
49  $backendUser = $this->setUpBackendUser(1);
50 
51  $subject = GeneralUtility::makeInstance(DefaultUploadFolderResolver::class);
52 
53  self::assertEquals(
54  '1:/page_upload/',
55  $subject->resolve($backendUser, 1)->getCombinedIdentifier()
56  );
57  }
58 
62  public function ‪resolveWithUserConfigTest(): void
63  {
64  ‪GeneralUtility::mkdir($this->instancePath . '/fileadmin/admin_upload/');
65  $backendUser = $this->setUpBackendUser(1);
66 
67  $subject = GeneralUtility::makeInstance(DefaultUploadFolderResolver::class);
68 
69  self::assertEquals(
70  '1:/admin_upload/',
71  $subject->resolve($backendUser)->getCombinedIdentifier()
72  );
73  }
74 
78  public function ‪resolveWithoutConfigTest(): void
79  {
80  $backendUser = $this->setUpBackendUser(2);
81 
82  $subject = GeneralUtility::makeInstance(DefaultUploadFolderResolver::class);
83 
84  self::assertEquals(
85  '1:/user_upload/',
86  $subject->resolve($backendUser)->getCombinedIdentifier()
87  );
88  }
89 
93  public function ‪getDefaultUploadFolderForUserTest(): void
94  {
95  ‪GeneralUtility::mkdir($this->instancePath . '/fileadmin/admin_upload/');
96  $backendUser = $this->setUpBackendUser(1);
97 
98  $subject = GeneralUtility::makeInstance(DefaultUploadFolderResolver::class);
99 
100  self::assertEquals('1:/admin_upload/', $subject->getDefaultUploadFolderForUser($backendUser)->getCombinedIdentifier());
101  }
102 
107  {
108  $backendUser = $this->setUpBackendUser(2);
109 
110  $subject = GeneralUtility::makeInstance(DefaultUploadFolderResolver::class);
111 
112  self::assertNull($subject->getDefaultUploadFolderForUser($backendUser));
113  }
114 
119  {
120  $backendUser = $this->setUpBackendUser(1);
121 
122  $subject = GeneralUtility::makeInstance(DefaultUploadFolderResolver::class);
123 
124  self::assertNull($subject->getDefaultUploadFolderForUser($backendUser));
125  }
126 
130  public function ‪getDefaultUploadFolderForPageTest(): void
131  {
132  ‪GeneralUtility::mkdir($this->instancePath . '/fileadmin/page_upload/');
133 
134  $subject = GeneralUtility::makeInstance(DefaultUploadFolderResolver::class);
135 
136  self::assertEquals('1:/page_upload/', $subject->getDefaultUploadFolderForPage(1)->getCombinedIdentifier());
137  }
138 
143  {
144  $subject = GeneralUtility::makeInstance(DefaultUploadFolderResolver::class);
145 
146  self::assertNull($subject->getDefaultUploadFolderForPage(1));
147  }
148 
153  {
154  ‪GeneralUtility::mkdir($this->instancePath . '/fileadmin/admin_upload/');
155  $backendUser = $this->setUpBackendUser(1);
156 
157  $subject = GeneralUtility::makeInstance(DefaultUploadFolderResolver::class);
158 
160  $container = $this->getContainer();
161  $container->set(
162  'after-default-upload-folder-was-resolved-listener',
163  static function (‪AfterDefaultUploadFolderWasResolvedEvent $event) use (&$afterDefaultUploadFolderWasResolvedEvent) {
164  $afterDefaultUploadFolderWasResolvedEvent = $event;
165  }
166  );
167 
168  $eventListener = $container->get(ListenerProvider::class);
169  $eventListener->addListener(AfterDefaultUploadFolderWasResolvedEvent::class, 'after-default-upload-folder-was-resolved-listener');
170 
171  $result = $subject->resolve($backendUser);
172  self::assertEquals($result, $afterDefaultUploadFolderWasResolvedEvent->getUploadFolder());
173  }
174 
179  {
180  ‪GeneralUtility::mkdir($this->instancePath . '/fileadmin/admin_upload/');
181  $backendUser = $this->setUpBackendUser(1);
182 
183  $subject = GeneralUtility::makeInstance(DefaultUploadFolderResolver::class);
184 
186  $container = $this->getContainer();
187  $container->set(
188  'after-default-upload-folder-was-resolved-listener',
189  static function (‪AfterDefaultUploadFolderWasResolvedEvent $event) {
190  $event->‪setUploadFolder($event->‪getUploadFolder()->getStorage()->getFolder('/'));
191  }
192  );
193 
194  $eventListener = $container->get(ListenerProvider::class);
195  $eventListener->addListener(AfterDefaultUploadFolderWasResolvedEvent::class, 'after-default-upload-folder-was-resolved-listener');
196 
197  $result = $subject->resolve($backendUser);
198  self::assertEquals('1:/', $result->getCombinedIdentifier());
199  }
200 }
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\setUp
‪setUp()
Definition: DefaultUploadFolderResolverTest.php:29
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\afterDefaultUploadFolderWasResolvedEventIsDispatched
‪afterDefaultUploadFolderWasResolvedEventIsDispatched()
Definition: DefaultUploadFolderResolverTest.php:152
‪TYPO3\CMS\Core\Utility\GeneralUtility\mkdir
‪static bool mkdir(string $newFolder)
Definition: GeneralUtility.php:1615
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\afterDefaultUploadFolderWasResolvedEventChangedResult
‪afterDefaultUploadFolderWasResolvedEventChangedResult()
Definition: DefaultUploadFolderResolverTest.php:178
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\getDefaultUploadFolderForPageWithoutExistingFolderTest
‪getDefaultUploadFolderForPageWithoutExistingFolderTest()
Definition: DefaultUploadFolderResolverTest.php:142
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\getDefaultUploadFolderForUserWithoutExistingFolderTest
‪getDefaultUploadFolderForUserWithoutExistingFolderTest()
Definition: DefaultUploadFolderResolverTest.php:118
‪TYPO3\CMS\Core\Resource\Event\AfterDefaultUploadFolderWasResolvedEvent\setUploadFolder
‪setUploadFolder(FolderInterface $uploadFolder)
Definition: AfterDefaultUploadFolderWasResolvedEvent.php:39
‪TYPO3\CMS\Core\Tests\Functional\Resource
Definition: DefaultUploadFolderResolverTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest
Definition: DefaultUploadFolderResolverTest.php:28
‪TYPO3\CMS\Core\Resource\Event\AfterDefaultUploadFolderWasResolvedEvent
Definition: AfterDefaultUploadFolderWasResolvedEvent.php:26
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\resolveWithoutConfigTest
‪resolveWithoutConfigTest()
Definition: DefaultUploadFolderResolverTest.php:78
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\getDefaultUploadFolderForUserTest
‪getDefaultUploadFolderForUserTest()
Definition: DefaultUploadFolderResolverTest.php:93
‪TYPO3\CMS\Core\Resource\DefaultUploadFolderResolver
Definition: DefaultUploadFolderResolver.php:31
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\resolveWithUserAndPageConfigTest
‪resolveWithUserAndPageConfigTest()
Definition: DefaultUploadFolderResolverTest.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility\rmdir
‪static bool rmdir(string $path, bool $removeNonEmpty=false)
Definition: GeneralUtility.php:1679
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\getDefaultUploadFolderForUserWithoutConfigTest
‪getDefaultUploadFolderForUserWithoutConfigTest()
Definition: DefaultUploadFolderResolverTest.php:106
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\resolveWithUserConfigTest
‪resolveWithUserConfigTest()
Definition: DefaultUploadFolderResolverTest.php:62
‪TYPO3\CMS\Core\Resource\Event\AfterDefaultUploadFolderWasResolvedEvent\getUploadFolder
‪getUploadFolder()
Definition: AfterDefaultUploadFolderWasResolvedEvent.php:34
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\tearDown
‪tearDown()
Definition: DefaultUploadFolderResolverTest.php:36
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:51
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30
‪TYPO3\CMS\Core\Tests\Functional\Resource\DefaultUploadFolderResolverTest\getDefaultUploadFolderForPageTest
‪getDefaultUploadFolderForPageTest()
Definition: DefaultUploadFolderResolverTest.php:130