TYPO3 CMS  TYPO3_7-6
ExtDirectServerTest.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 
23 
28 {
32  protected $subject;
33 
38 
42  protected function setUp()
43  {
44  parent::setUp();
45  $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Workspaces\ExtDirect\ExtDirectServer::class, ['__none']);
46  }
47 
51  protected function tearDown()
52  {
53  parent::tearDown();
54  unset($this->subject);
55  unset($this->fileReferenceProphecies);
56  }
57 
62  {
63  return [
64  // without thumbnails
65  'unchanged wo/thumbnails' => ['1,2,3,4', '1,2,3,4', false, null],
66  'front addition wo/thumbnails' => ['1,2,3,4', '99,1,2,3,4', false, [
67  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
68  'differences' => '<ins>/img/99.png </ins>/img/1.png /img/2.png /img/3.png /img/4.png',
69  ]],
70  'end addition wo/thumbnails' => ['1,2,3,4', '1,2,3,4,99', false, [
71  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
72  'differences' => '/img/1.png /img/2.png /img/3.png /img/4.png <ins>/img/99.png </ins>',
73  ]],
74  'reorder wo/thumbnails' => ['1,2,3,4', '1,3,2,4', false, [
75  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
76  'differences' => '/img/1.png <ins>/img/3.png </ins>/img/2.png <del>/img/3.png </del>/img/4.png',
77  ]],
78  'move to end wo/thumbnails' => ['1,2,3,4', '2,3,4,1', false, [
79  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
80  'differences' => '<del>/img/1.png </del>/img/2.png /img/3.png /img/4.png <ins>/img/1.png </ins>',
81  ]],
82  'move to front wo/thumbnails' => ['1,2,3,4', '4,1,2,3', false, [
83  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
84  'differences' => '<ins>/img/4.png </ins>/img/1.png /img/2.png /img/3.png <del>/img/4.png </del>',
85  ]],
86  'keep last wo/thumbnails' => ['1,2,3,4', '4', false, [
87  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
88  'differences' => '<del>/img/1.png /img/2.png /img/3.png </del>/img/4.png',
89  ]],
90  // with thumbnails
91  'unchanged w/thumbnails' => ['1,2,3,4', '1,2,3,4', true, null],
92  'front addition w/thumbnails' => ['1,2,3,4', '99,1,2,3,4', 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/99.png" /> </ins><img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
95  ]],
96  'end addition w/thumbnails' => ['1,2,3,4', '1,2,3,4,99', 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' => '<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>',
99  ]],
100  'reorder w/thumbnails' => ['1,2,3,4', '1,3,2,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' => '<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" />',
103  ]],
104  'move to end w/thumbnails' => ['1,2,3,4', '2,3,4,1', true, [
105  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
106  '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>',
107  ]],
108  'move to front w/thumbnails' => ['1,2,3,4', '4,1,2,3', true, [
109  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
110  '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>',
111  ]],
112  'keep last w/thumbnails' => ['1,2,3,4', '4', true, [
113  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
114  'differences' => '<del><img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> </del><img src="/tmb/4.png" />',
115  ]],
116  ];
117  }
118 
127  public function prepareFileReferenceDifferencesAreCorrect($fileFileReferenceList, $versionFileReferenceList, $useThumbnails, array $expected = null)
128  {
129  $liveFileReferences = $this->getFileReferenceProphecies($fileFileReferenceList);
130  $versionFileReferences = $this->getFileReferenceProphecies($versionFileReferenceList);
131 
132  $result = $this->subject->_call(
133  'prepareFileReferenceDifferences',
134  $liveFileReferences,
135  $versionFileReferences,
136  $useThumbnails
137  );
138 
139  $this->assertSame($expected, $result);
140  }
141 
146  protected function getFileReferenceProphecies($idList)
147  {
149  $ids = GeneralUtility::trimExplode(',', $idList, true);
150 
151  foreach ($ids as $id) {
153  }
154 
156  }
157 
162  protected function getFileReferenceProphecy($id)
163  {
164  if (isset($this->fileReferenceProphecies[$id])) {
165  return $this->fileReferenceProphecies[$id];
166  }
167 
168  $processedFileProphecy = $this->prophesize(ProcessedFile::class);
169  $processedFileProphecy->getPublicUrl(Argument::cetera())->willReturn('/tmb/' . $id . '.png');
170 
171  $fileProphecy = $this->prophesize(File::class);
172  $fileProphecy->process(Argument::cetera())->willReturn($processedFileProphecy->reveal());
173 
174  $fileReferenceProphecy = $this->prophesize(FileReference::class);
175  $fileReferenceProphecy->getUid()->willReturn($id);
176  $fileReferenceProphecy->getOriginalFile()->willReturn($fileProphecy->reveal());
177  $fileReferenceProphecy->getPublicUrl(Argument::cetera())->willReturn('/img/' . $id . '.png');
178 
179  $this->fileReferenceProphecies[$id] = $fileReferenceProphecy->reveal();
180  return $this->fileReferenceProphecies[$id];
181  }
182 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
prepareFileReferenceDifferencesAreCorrect($fileFileReferenceList, $versionFileReferenceList, $useThumbnails, array $expected=null)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)