‪TYPO3CMS  11.5
RemoteServerTest.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 Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
32 class ‪RemoteServerTest extends UnitTestCase
33 {
34  use ProphecyTrait;
35 
39  protected ‪$resetSingletonInstances = true;
40 
44  protected array ‪$fileReferenceMocks;
45 
50  {
51  return [
52  // without thumbnails
53  'unchanged wo/thumbnails' => ['1,2,3,4', '1,2,3,4', false, null],
54  'front addition wo/thumbnails' => ['1,2,3,4', '99,1,2,3,4', false, [
55  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
56  'differences' => '<ins>/img/99.png </ins>/img/1.png /img/2.png /img/3.png /img/4.png',
57  ]],
58  'end addition wo/thumbnails' => ['1,2,3,4', '1,2,3,4,99', false, [
59  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
60  'differences' => '/img/1.png /img/2.png /img/3.png /img/4.png <ins>/img/99.png </ins>',
61  ]],
62  'reorder wo/thumbnails' => ['1,2,3,4', '1,3,2,4', false, [
63  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
64  'differences' => '/img/1.png <ins>/img/3.png </ins>/img/2.png <del>/img/3.png </del>/img/4.png',
65  ]],
66  'move to end wo/thumbnails' => ['1,2,3,4', '2,3,4,1', false, [
67  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
68  'differences' => '<del>/img/1.png </del>/img/2.png /img/3.png /img/4.png <ins>/img/1.png </ins>',
69  ]],
70  'move to front wo/thumbnails' => ['1,2,3,4', '4,1,2,3', false, [
71  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
72  'differences' => '<ins>/img/4.png </ins>/img/1.png /img/2.png /img/3.png <del>/img/4.png </del>',
73  ]],
74  'keep last wo/thumbnails' => ['1,2,3,4', '4', false, [
75  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
76  'differences' => '<del>/img/1.png /img/2.png /img/3.png </del>/img/4.png',
77  ]],
78  // with thumbnails
79  'unchanged w/thumbnails' => ['1,2,3,4', '1,2,3,4', true, null],
80  'front addition w/thumbnails' => ['1,2,3,4', '99,1,2,3,4', true, [
81  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
82  'differences' => '<ins><img src="/tmb/99.png" /> </ins><img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
83  ]],
84  'end addition w/thumbnails' => ['1,2,3,4', '1,2,3,4,99', true, [
85  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
86  'differences' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" /> <ins><img src="/tmb/99.png" /> </ins>',
87  ]],
88  'reorder w/thumbnails' => ['1,2,3,4', '1,3,2,4', true, [
89  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
90  'differences' => '<img src="/tmb/1.png" /> <ins><img src="/tmb/3.png" /> </ins><img src="/tmb/2.png" /> <del><img src="/tmb/3.png" /> </del><img src="/tmb/4.png" />',
91  ]],
92  'move to end w/thumbnails' => ['1,2,3,4', '2,3,4,1', true, [
93  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
94  'differences' => '<del><img src="/tmb/1.png" /> </del><img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" /> <ins><img src="/tmb/1.png" /> </ins>',
95  ]],
96  'move to front w/thumbnails' => ['1,2,3,4', '4,1,2,3', true, [
97  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
98  'differences' => '<ins><img src="/tmb/4.png" /> </ins><img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <del><img src="/tmb/4.png" /> </del>',
99  ]],
100  'keep last w/thumbnails' => ['1,2,3,4', '4', true, [
101  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
102  'differences' => '<del><img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> </del><img src="/tmb/4.png" />',
103  ]],
104  ];
105  }
106 
115  public function ‪prepareFileReferenceDifferencesAreCorrect(string $fileFileReferenceList, string $versionFileReferenceList, bool $useThumbnails, array $expected = null): void
116  {
117  $liveFileReferences = $this->getFileReferenceMocks($fileFileReferenceList);
118  $versionFileReferences = $this->getFileReferenceMocks($versionFileReferenceList);
119 
120  $subject = $this->getAccessibleMock(RemoteServer::class, ['__none'], [], '', false);
121  $result = $subject->_call(
122  'prepareFileReferenceDifferences',
123  $liveFileReferences,
124  $versionFileReferences,
125  $useThumbnails
126  );
127 
128  self::assertSame($expected, $result);
129  }
130 
135  protected function getFileReferenceMocks(string $idList): array
136  {
138  $ids = ‪GeneralUtility::trimExplode(',', $idList, true);
139 
140  foreach ($ids as $id) {
142  }
143 
145  }
146 
147  protected function ‪getFileReferenceMock(string $id): ‪FileReference
148  {
149  if (isset($this->fileReferenceMocks[$id])) {
150  return $this->fileReferenceMocks[$id];
151  }
152 
153  $processedFileProphecy = $this->prophesize(ProcessedFile::class);
154  $processedFileProphecy->getPublicUrl(Argument::cetera())->willReturn('/tmb/' . $id . '.png');
155 
156  $fileProphecy = $this->prophesize(File::class);
157  $fileProphecy->process(Argument::cetera())->willReturn($processedFileProphecy->reveal());
158 
159  $fileReferenceProphecy = $this->prophesize(FileReference::class);
160  $fileReferenceProphecy->getUid()->willReturn($id);
161  $fileReferenceProphecy->getOriginalFile()->willReturn($fileProphecy->reveal());
162  $fileReferenceProphecy->getPublicUrl(Argument::cetera())->willReturn('/img/' . $id . '.png');
163 
164  $this->fileReferenceMocks[$id] = $fileReferenceProphecy->reveal();
165  return $this->fileReferenceMocks[$id];
166  }
167 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest
Definition: RemoteServerTest.php:33
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\$fileReferenceProphecies
‪return $fileReferenceProphecies
Definition: RemoteServerTest.php:142
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\prepareFileReferenceDifferencesAreCorrectDataProvider
‪array prepareFileReferenceDifferencesAreCorrectDataProvider()
Definition: RemoteServerTest.php:47
‪TYPO3\CMS\Core\Resource\FileReference
Definition: FileReference.php:33
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\$fileReferenceMocks
‪array $fileReferenceMocks
Definition: RemoteServerTest.php:42
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\getFileReferenceMock
‪array< string, getFileReferenceMocks(string $idList):array { $fileReferenceProphecies=[];$ids=GeneralUtility::trimExplode(',', $idList, true);foreach( $ids as $id) { $fileReferenceProphecies[ $id]=$this-> getFileReferenceMock($id)
‪TYPO3\CMS\Workspaces\Controller\Remote\RemoteServer
Definition: RemoteServer.php:49
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\prepareFileReferenceDifferencesAreCorrect
‪prepareFileReferenceDifferencesAreCorrect(string $fileFileReferenceList, string $versionFileReferenceList, bool $useThumbnails, array $expected=null)
Definition: RemoteServerTest.php:113
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: RemoteServerTest.php:37
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:45
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote
Definition: RemoteServerTest.php:18
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\getFileReferenceMock
‪getFileReferenceMock(string $id)
Definition: RemoteServerTest.php:145
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50