‪TYPO3CMS  ‪main
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 PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
22 use PHPUnit\Framework\MockObject\MockObject;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
30 final class ‪RemoteServerTest extends UnitTestCase
31 {
32  protected bool ‪$resetSingletonInstances = true;
33 
37  protected array ‪$fileReferenceMocks;
38 
40  {
41  return [
42  // without thumbnails
43  'unchanged wo/thumbnails' => ['1,2,3,4', '1,2,3,4', false, null],
44  'front addition wo/thumbnails' => ['1,2,3,4', '99,1,2,3,4', false, [
45  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
46  'differences' => '<ins>/img/99.png </ins>/img/1.png /img/2.png /img/3.png /img/4.png',
47  ]],
48  'end addition wo/thumbnails' => ['1,2,3,4', '1,2,3,4,99', false, [
49  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
50  'differences' => '/img/1.png /img/2.png /img/3.png /img/4.png <ins>/img/99.png </ins>',
51  ]],
52  'reorder wo/thumbnails' => ['1,2,3,4', '1,3,2,4', false, [
53  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
54  'differences' => '/img/1.png <ins>/img/3.png </ins>/img/2.png <del>/img/3.png </del>/img/4.png',
55  ]],
56  'move to end wo/thumbnails' => ['1,2,3,4', '2,3,4,1', false, [
57  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
58  'differences' => '<del>/img/1.png </del>/img/2.png /img/3.png /img/4.png <ins>/img/1.png </ins>',
59  ]],
60  'move to front wo/thumbnails' => ['1,2,3,4', '4,1,2,3', false, [
61  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
62  'differences' => '<ins>/img/4.png </ins>/img/1.png /img/2.png /img/3.png <del>/img/4.png </del>',
63  ]],
64  'keep last wo/thumbnails' => ['1,2,3,4', '4', false, [
65  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
66  'differences' => '<del>/img/1.png /img/2.png /img/3.png </del>/img/4.png',
67  ]],
68  // with thumbnails
69  'unchanged w/thumbnails' => ['1,2,3,4', '1,2,3,4', true, null],
70  'front addition w/thumbnails' => ['1,2,3,4', '99,1,2,3,4', true, [
71  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
72  '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" />',
73  ]],
74  'end addition w/thumbnails' => ['1,2,3,4', '1,2,3,4,99', true, [
75  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
76  '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>',
77  ]],
78  'reorder w/thumbnails' => ['1,2,3,4', '1,3,2,4', true, [
79  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
80  '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" />',
81  ]],
82  'move to end w/thumbnails' => ['1,2,3,4', '2,3,4,1', true, [
83  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
84  '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>',
85  ]],
86  'move to front w/thumbnails' => ['1,2,3,4', '4,1,2,3', true, [
87  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
88  '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>',
89  ]],
90  'keep last w/thumbnails' => ['1,2,3,4', '4', true, [
91  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
92  'differences' => '<del><img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> </del><img src="/tmb/4.png" />',
93  ]],
94  ];
95  }
96 
100  #[DataProvider('prepareFileReferenceDifferencesAreCorrectDataProvider')]
101  #[Test]
102  public function ‪prepareFileReferenceDifferencesAreCorrect(string $fileFileReferenceList, string $versionFileReferenceList, bool $useThumbnails, array $expected = null): void
103  {
104  $liveFileReferences = $this->getFileReferenceMocks($fileFileReferenceList);
105  $versionFileReferences = $this->getFileReferenceMocks($versionFileReferenceList);
106 
107  $subject = $this->getAccessibleMock(RemoteServer::class, null, [], '', false);
108  $result = $subject->_call(
109  'prepareFileReferenceDifferences',
110  $liveFileReferences,
111  $versionFileReferences,
112  $useThumbnails
113  );
114 
115  self::assertSame($expected, $result);
116  }
117 
122  protected function getFileReferenceMocks(string $idList): array
123  {
125  $ids = ‪GeneralUtility::trimExplode(',', $idList, true);
126 
127  foreach ($ids as $id) {
129  }
130 
132  }
133 
137  protected function ‪getFileReferenceMock(string $id): ‪FileReference&MockObject
138  {
139  if (isset($this->fileReferenceMocks[$id])) {
140  return $this->fileReferenceMocks[$id];
141  }
142 
143  $processedFileMock = $this->getMockBuilder(ProcessedFile::class)->disableOriginalConstructor()->getMock();
144  $processedFileMock->expects(self::any())->method('getPublicUrl')->willReturn('/tmb/' . $id . '.png');
145 
146  $fileMock = $this->getMockBuilder(File::class)->disableOriginalConstructor()->getMock();
147  $fileMock->expects(self::any())->method('process')->willReturn($processedFileMock);
148 
149  $fileReferenceMock = $this->getMockBuilder(FileReference::class)->disableOriginalConstructor()->getMock();
150  $fileReferenceMock->method('getUid')->willReturn($id);
151  $fileReferenceMock->method('getOriginalFile')->willReturn($fileMock);
152  $fileReferenceMock->expects(self::any())->method('getPublicUrl')->willReturn('/img/' . $id . '.png');
153 
154  $this->fileReferenceMocks[$id] = $fileReferenceMock;
155  return $this->fileReferenceMocks[$id];
156  }
157 }
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest
Definition: RemoteServerTest.php:31
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\getFileReferenceMock
‪array< non-empty-string, getFileReferenceMocks(string $idList):array { $fileReferenceMocks=[];$ids=GeneralUtility::trimExplode(',', $idList, true);foreach( $ids as $id) { $fileReferenceMocks[ $id]=$this-> getFileReferenceMock($id)
‪TYPO3\CMS\Core\Resource\FileReference
Definition: FileReference.php:37
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\$fileReferenceMocks
‪array $fileReferenceMocks
Definition: RemoteServerTest.php:37
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\prepareFileReferenceDifferencesAreCorrectDataProvider
‪static prepareFileReferenceDifferencesAreCorrectDataProvider()
Definition: RemoteServerTest.php:39
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\$fileReferenceMocks
‪return $fileReferenceMocks
Definition: RemoteServerTest.php:131
‪TYPO3\CMS\Workspaces\Controller\Remote\RemoteServer
Definition: RemoteServer.php:56
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\prepareFileReferenceDifferencesAreCorrect
‪prepareFileReferenceDifferencesAreCorrect(string $fileFileReferenceList, string $versionFileReferenceList, bool $useThumbnails, array $expected=null)
Definition: RemoteServerTest.php:102
‪TYPO3\CMS\Workspaces\Tests\Unit\Controller\Remote\RemoteServerTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: RemoteServerTest.php:32
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:26
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:47
‪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:137
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822