‪TYPO3CMS  9.5
RemoteServerTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪RemoteServerTest extends UnitTestCase
30 {
34  protected ‪$resetSingletonInstances = true;
35 
40 
45  {
46  return [
47  // without thumbnails
48  'unchanged wo/thumbnails' => ['1,2,3,4', '1,2,3,4', false, null],
49  'front addition wo/thumbnails' => ['1,2,3,4', '99,1,2,3,4', false, [
50  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
51  'differences' => '<ins>/img/99.png </ins>/img/1.png /img/2.png /img/3.png /img/4.png',
52  ]],
53  'end addition wo/thumbnails' => ['1,2,3,4', '1,2,3,4,99', false, [
54  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
55  'differences' => '/img/1.png /img/2.png /img/3.png /img/4.png <ins>/img/99.png </ins>',
56  ]],
57  'reorder wo/thumbnails' => ['1,2,3,4', '1,3,2,4', false, [
58  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
59  'differences' => '/img/1.png <ins>/img/3.png </ins>/img/2.png <del>/img/3.png </del>/img/4.png',
60  ]],
61  'move to end wo/thumbnails' => ['1,2,3,4', '2,3,4,1', false, [
62  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
63  'differences' => '<del>/img/1.png </del>/img/2.png /img/3.png /img/4.png <ins>/img/1.png </ins>',
64  ]],
65  'move to front wo/thumbnails' => ['1,2,3,4', '4,1,2,3', false, [
66  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
67  'differences' => '<ins>/img/4.png </ins>/img/1.png /img/2.png /img/3.png <del>/img/4.png </del>',
68  ]],
69  'keep last wo/thumbnails' => ['1,2,3,4', '4', false, [
70  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
71  'differences' => '<del>/img/1.png /img/2.png /img/3.png </del>/img/4.png',
72  ]],
73  // with thumbnails
74  'unchanged w/thumbnails' => ['1,2,3,4', '1,2,3,4', true, null],
75  'front addition w/thumbnails' => ['1,2,3,4', '99,1,2,3,4', true, [
76  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
77  '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" />',
78  ]],
79  'end addition w/thumbnails' => ['1,2,3,4', '1,2,3,4,99', true, [
80  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
81  '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>',
82  ]],
83  'reorder w/thumbnails' => ['1,2,3,4', '1,3,2,4', true, [
84  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
85  '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" />',
86  ]],
87  'move to end w/thumbnails' => ['1,2,3,4', '2,3,4,1', true, [
88  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
89  '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>',
90  ]],
91  'move to front w/thumbnails' => ['1,2,3,4', '4,1,2,3', true, [
92  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
93  '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>',
94  ]],
95  'keep last w/thumbnails' => ['1,2,3,4', '4', true, [
96  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
97  'differences' => '<del><img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> </del><img src="/tmb/4.png" />',
98  ]],
99  ];
100  }
101 
110  public function ‪prepareFileReferenceDifferencesAreCorrect($fileFileReferenceList, $versionFileReferenceList, $useThumbnails, array $expected = null)
111  {
112  $liveFileReferences = $this->‪getFileReferenceProphecies($fileFileReferenceList);
113  $versionFileReferences = $this->‪getFileReferenceProphecies($versionFileReferenceList);
114 
115  $subject = $this->getAccessibleMock(RemoteServer::class, ['__none']);
116  $result = $subject->_call(
117  'prepareFileReferenceDifferences',
118  $liveFileReferences,
119  $versionFileReferences,
120  $useThumbnails
121  );
122 
123  $this->assertSame($expected, $result);
124  }
125 
130  protected function ‪getFileReferenceProphecies($idList)
131  {
133  $ids = GeneralUtility::trimExplode(',', $idList, true);
134 
135  foreach ($ids as $id) {
137  }
138 
140  }
141 
146  protected function ‪getFileReferenceProphecy($id)
147  {
148  if (isset($this->fileReferenceProphecies[$id])) {
149  return $this->fileReferenceProphecies[$id];
150  }
151 
152  $processedFileProphecy = $this->prophesize(ProcessedFile::class);
153  $processedFileProphecy->getPublicUrl(Argument::cetera())->willReturn('/tmb/' . $id . '.png');
154 
155  $fileProphecy = $this->prophesize(File::class);
156  $fileProphecy->process(Argument::cetera())->willReturn($processedFileProphecy->reveal());
157 
158  $fileReferenceProphecy = $this->prophesize(FileReference::class);
159  $fileReferenceProphecy->getUid()->willReturn($id);
160  $fileReferenceProphecy->getOriginalFile()->willReturn($fileProphecy->reveal());
161  $fileReferenceProphecy->getPublicUrl(Argument::cetera())->willReturn('/img/' . $id . '.png');
162 
163  $this->fileReferenceProphecies[$id] = $fileReferenceProphecy->reveal();
164  return $this->fileReferenceProphecies[$id];
165  }
166 }
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest
Definition: RemoteServerTest.php:30
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\getFileReferenceProphecy
‪ObjectProphecy FileReference getFileReferenceProphecy($id)
Definition: RemoteServerTest.php:144
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\prepareFileReferenceDifferencesAreCorrectDataProvider
‪array prepareFileReferenceDifferencesAreCorrectDataProvider()
Definition: RemoteServerTest.php:42
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\getFileReferenceProphecies
‪FileReference[] ObjectProphecy[] getFileReferenceProphecies($idList)
Definition: RemoteServerTest.php:128
‪TYPO3\CMS\Core\Resource\FileReference
Definition: FileReference.php:31
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\prepareFileReferenceDifferencesAreCorrect
‪prepareFileReferenceDifferencesAreCorrect($fileFileReferenceList, $versionFileReferenceList, $useThumbnails, array $expected=null)
Definition: RemoteServerTest.php:108
‪TYPO3\CMS\Workspaces\Controller\Remote\RemoteServer
Definition: RemoteServer.php:43
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: RemoteServerTest.php:33
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:42
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote
Definition: RemoteServerTest.php:2
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\$fileReferenceProphecies
‪FileReference[] ObjectProphecy[] $fileReferenceProphecies
Definition: RemoteServerTest.php:37