‪TYPO3CMS  ‪main
ClipboardTest.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\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
30 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
31 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
32 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
33 
37 final class ‪ClipboardTest extends FunctionalTestCase
38 {
40 
41  protected const ‪LANGUAGE_PRESETS = [
42  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
43  ];
44 
45  protected array ‪$coreExtensionsToLoad = ['workspaces'];
46 
49 
50  protected function ‪setUp(): void
51  {
52  parent::setUp();
53  $request = new ‪ServerRequest('https://localhost/typo3/');
54  $requestContextFactory = $this->get(RequestContextFactory::class);
55  $uriBuilder = $this->get(UriBuilder::class);
56  $uriBuilder->setRequestContext($requestContextFactory->fromBackendRequest($request));
57  $this->subject = GeneralUtility::makeInstance(Clipboard::class);
58  $this->withDatabaseSnapshot(
59  function () {
60  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
61  $this->backendUser = $this->setUpBackendUser(1);
62  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($this->backendUser);
63  $scenarioFile = __DIR__ . '/../Fixtures/CommonScenario.yaml';
64  $factory = DataHandlerFactory::fromYamlFile($scenarioFile);
65  $writer = DataHandlerWriter::withBackendUser($this->backendUser);
66  $writer->invokeFactory($factory);
67  static::failIfArrayIsNotEmpty($writer->getErrors());
68  },
69  function () {
70  $this->backendUser = $this->setUpBackendUser(1);
71  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($this->backendUser);
72  }
73  );
74  }
75 
76  protected function ‪tearDown(): void
77  {
78  unset($this->subject, $this->backendUser);
79  parent::tearDown();
80  }
81 
82  public static function ‪localizationsAreResolvedDataProvider(): array
83  {
84  return [
85  'live workspace with live & version localizations' => [
86  1100,
87  0,
88  'pages',
89  [
90  'FR: Welcome',
91  'FR-CA: Welcome',
92  ],
93  ],
94  'draft workspace with live & version localizations' => [
95  1100,
96  1,
97  'pages',
98  [
99  'FR: Welcome',
100  'FR-CA: Welcome',
101  'ES: Bienvenido',
102  ],
103  ],
104  'live workspace with live localizations only' => [
105  1400,
106  0,
107  'pages',
108  [
109  'FR: ACME in your Region',
110  'FR-CA: ACME in your Region',
111  ],
112  ],
113  'draft workspace with live localizations only' => [
114  1400,
115  1,
116  'pages',
117  [
118  'FR: ACME in your Region',
119  'FR-CA: ACME in your Region',
120  ],
121  ],
122  'live workspace with version localizations only' => [
123  1500,
124  0,
125  'pages',
126  [],
127  ],
128  'draft workspace with version localizations only' => [
129  1500,
130  1,
131  'pages',
132  [
133  'FR: Interne',
134  ],
135  ],
136  'Record is not of currently selected table' => [
137  1500,
138  1,
139  '_FILE',
140  [
141  '<span class="text-body-secondary">FR: Interne</span>',
142  ],
143  ],
144  ];
145  }
146 
147  #[DataProvider('localizationsAreResolvedDataProvider')]
148  #[Test]
149  public function ‪localizationsAreResolved(
150  int $pageId,
151  int $workspaceId,
152  string $table,
153  array $expectation
154  ): void {
155  $this->backendUser->workspace = $workspaceId;
156  $this->subject->clipData['normal']['el'] = ["pages|$pageId" => 'some value'];
157  $this->subject->current = 'normal';
158  $normalTab = $this->subject->getClipboardData($table)['tabs'][0];
159  array_shift($normalTab['items']);
160  $actualTitles = [];
161  foreach ($normalTab['items'] as $item) {
162  $actualTitles[] = $item['title'];
163  }
164 
165  self::assertEqualsCanonicalizing($expectation, $actualTitles);
166  }
167 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Backend\Tests\Functional\Clipboard\ClipboardTest\$backendUser
‪BackendUserAuthentication $backendUser
Definition: ClipboardTest.php:47
‪TYPO3\CMS\Backend\Tests\Functional\Clipboard
Definition: ClipboardTest.php:18
‪TYPO3\CMS\Backend\Clipboard\Clipboard
Definition: Clipboard.php:48
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Backend\Tests\Functional\Clipboard\ClipboardTest\$subject
‪Clipboard $subject
Definition: ClipboardTest.php:46
‪TYPO3\CMS\Backend\Tests\Functional\Clipboard\ClipboardTest\setUp
‪setUp()
Definition: ClipboardTest.php:49
‪TYPO3\CMS\Backend\Tests\Functional\Clipboard\ClipboardTest\localizationsAreResolved
‪localizationsAreResolved(int $pageId, int $workspaceId, string $table, array $expectation)
Definition: ClipboardTest.php:148
‪TYPO3\CMS\Backend\Tests\Functional\Clipboard\ClipboardTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: ClipboardTest.php:40
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Tests\Functional\Clipboard\ClipboardTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: ClipboardTest.php:44
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Tests\Functional\Clipboard\ClipboardTest\localizationsAreResolvedDataProvider
‪static localizationsAreResolvedDataProvider()
Definition: ClipboardTest.php:81
‪TYPO3\CMS\Backend\Tests\Functional\Clipboard\ClipboardTest
Definition: ClipboardTest.php:38
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Tests\Functional\Clipboard\ClipboardTest\tearDown
‪tearDown()
Definition: ClipboardTest.php:75
‪TYPO3\CMS\Core\Routing\RequestContextFactory
Definition: RequestContextFactory.php:30