‪TYPO3CMS  10.4
RemoteServerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Prophecy\Argument;
19 use Prophecy\Prophecy\ObjectProphecy;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪RemoteServerTest extends UnitTestCase
31 {
35  protected ‪$resetSingletonInstances = true;
36 
41 
46  {
47  return [
48  // without thumbnails
49  'unchanged wo/thumbnails' => ['1,2,3,4', '1,2,3,4', false, null],
50  'front addition wo/thumbnails' => ['1,2,3,4', '99,1,2,3,4', false, [
51  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
52  'differences' => '<ins>/img/99.png </ins>/img/1.png /img/2.png /img/3.png /img/4.png',
53  ]],
54  'end addition wo/thumbnails' => ['1,2,3,4', '1,2,3,4,99', false, [
55  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
56  'differences' => '/img/1.png /img/2.png /img/3.png /img/4.png <ins>/img/99.png </ins>',
57  ]],
58  'reorder wo/thumbnails' => ['1,2,3,4', '1,3,2,4', false, [
59  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
60  'differences' => '/img/1.png <ins>/img/3.png </ins>/img/2.png <del>/img/3.png </del>/img/4.png',
61  ]],
62  'move to end wo/thumbnails' => ['1,2,3,4', '2,3,4,1', false, [
63  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
64  'differences' => '<del>/img/1.png </del>/img/2.png /img/3.png /img/4.png <ins>/img/1.png </ins>',
65  ]],
66  'move to front wo/thumbnails' => ['1,2,3,4', '4,1,2,3', false, [
67  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
68  'differences' => '<ins>/img/4.png </ins>/img/1.png /img/2.png /img/3.png <del>/img/4.png </del>',
69  ]],
70  'keep last wo/thumbnails' => ['1,2,3,4', '4', false, [
71  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
72  'differences' => '<del>/img/1.png /img/2.png /img/3.png </del>/img/4.png',
73  ]],
74  // with thumbnails
75  'unchanged w/thumbnails' => ['1,2,3,4', '1,2,3,4', true, null],
76  'front addition w/thumbnails' => ['1,2,3,4', '99,1,2,3,4', true, [
77  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
78  '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" />',
79  ]],
80  'end addition w/thumbnails' => ['1,2,3,4', '1,2,3,4,99', 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' => '<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>',
83  ]],
84  'reorder w/thumbnails' => ['1,2,3,4', '1,3,2,4', 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" /> <ins><img src="/tmb/3.png" /> </ins><img src="/tmb/2.png" /> <del><img src="/tmb/3.png" /> </del><img src="/tmb/4.png" />',
87  ]],
88  'move to end w/thumbnails' => ['1,2,3,4', '2,3,4,1', 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' => '<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>',
91  ]],
92  'move to front w/thumbnails' => ['1,2,3,4', '4,1,2,3', 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' => '<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>',
95  ]],
96  'keep last w/thumbnails' => ['1,2,3,4', '4', 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' => '<del><img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> </del><img src="/tmb/4.png" />',
99  ]],
100  ];
101  }
102 
111  public function ‪prepareFileReferenceDifferencesAreCorrect($fileFileReferenceList, $versionFileReferenceList, $useThumbnails, array $expected = null)
112  {
113  $liveFileReferences = $this->‪getFileReferenceProphecies($fileFileReferenceList);
114  $versionFileReferences = $this->‪getFileReferenceProphecies($versionFileReferenceList);
115 
116  $subject = $this->getAccessibleMock(RemoteServer::class, ['__none'], [], '', false);
117  $result = $subject->_call(
118  'prepareFileReferenceDifferences',
119  $liveFileReferences,
120  $versionFileReferences,
121  $useThumbnails
122  );
123 
124  self::assertSame($expected, $result);
125  }
126 
131  protected function ‪getFileReferenceProphecies($idList)
132  {
134  $ids = ‪GeneralUtility::trimExplode(',', $idList, true);
135 
136  foreach ($ids as $id) {
138  }
139 
141  }
142 
147  protected function ‪getFileReferenceProphecy($id)
148  {
149  if (isset($this->fileReferenceProphecies[$id])) {
150  return $this->fileReferenceProphecies[$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->fileReferenceProphecies[$id] = $fileReferenceProphecy->reveal();
165  return $this->fileReferenceProphecies[$id];
166  }
167 }
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest
Definition: RemoteServerTest.php:31
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\getFileReferenceProphecy
‪ObjectProphecy FileReference getFileReferenceProphecy($id)
Definition: RemoteServerTest.php:145
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\prepareFileReferenceDifferencesAreCorrectDataProvider
‪array prepareFileReferenceDifferencesAreCorrectDataProvider()
Definition: RemoteServerTest.php:43
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\getFileReferenceProphecies
‪FileReference[] ObjectProphecy[] getFileReferenceProphecies($idList)
Definition: RemoteServerTest.php:129
‪TYPO3\CMS\Core\Resource\FileReference
Definition: FileReference.php:33
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\prepareFileReferenceDifferencesAreCorrect
‪prepareFileReferenceDifferencesAreCorrect($fileFileReferenceList, $versionFileReferenceList, $useThumbnails, array $expected=null)
Definition: RemoteServerTest.php:109
‪TYPO3\CMS\Workspaces\Controller\Remote\RemoteServer
Definition: RemoteServer.php:48
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: RemoteServerTest.php:34
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:44
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote
Definition: RemoteServerTest.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\$fileReferenceProphecies
‪FileReference[] ObjectProphecy[] $fileReferenceProphecies
Definition: RemoteServerTest.php:38