TYPO3  7.6
ExtDirectServerTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Workspaces\Tests\Unit\ExtDirect;
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;
23 
27 class ExtDirectServerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
28 {
29 
33  protected $subject;
34 
39 
43  protected function setUp()
44  {
45  parent::setUp();
46  $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Workspaces\ExtDirect\ExtDirectServer::class, array('__none'));
47  }
48 
52  protected function tearDown() {
53  parent::tearDown();
54  unset($this->subject);
55  unset($this->fileReferenceProphecies);
56  }
57 
62  return array(
63  // without thumbnails
64  'unchanged wo/thumbnails' => array('1,2,3,4', '1,2,3,4', false, null),
65  'front addition wo/thumbnails' => array('1,2,3,4', '99,1,2,3,4', false, array(
66  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
67  'differences' => '<ins>/img/99.png </ins>/img/1.png /img/2.png /img/3.png /img/4.png',
68  )),
69  'end addition wo/thumbnails' => array('1,2,3,4', '1,2,3,4,99', false, array(
70  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
71  'differences' => '/img/1.png /img/2.png /img/3.png /img/4.png <ins>/img/99.png </ins>',
72  )),
73  'reorder wo/thumbnails' => array('1,2,3,4', '1,3,2,4', false, array(
74  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
75  'differences' => '/img/1.png <ins>/img/3.png </ins>/img/2.png <del>/img/3.png </del>/img/4.png',
76  )),
77  'move to end wo/thumbnails' => array('1,2,3,4', '2,3,4,1', false, array(
78  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
79  'differences' => '<del>/img/1.png </del>/img/2.png /img/3.png /img/4.png <ins>/img/1.png </ins>',
80  )),
81  'move to front wo/thumbnails' => array('1,2,3,4', '4,1,2,3', false, array(
82  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
83  'differences' => '<ins>/img/4.png </ins>/img/1.png /img/2.png /img/3.png <del>/img/4.png </del>',
84  )),
85  'keep last wo/thumbnails' => array('1,2,3,4', '4', false, array(
86  'live' => '/img/1.png /img/2.png /img/3.png /img/4.png',
87  'differences' => '<del>/img/1.png /img/2.png /img/3.png </del>/img/4.png',
88  )),
89  // with thumbnails
90  'unchanged w/thumbnails' => array('1,2,3,4', '1,2,3,4', true, null),
91  'front addition w/thumbnails' => array('1,2,3,4', '99,1,2,3,4', true, array(
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/99.png" /> </ins><img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
94  )),
95  'end addition w/thumbnails' => array('1,2,3,4', '1,2,3,4,99', true, array(
96  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
97  '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>',
98  )),
99  'reorder w/thumbnails' => array('1,2,3,4', '1,3,2,4', true, array(
100  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
101  '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" />',
102  )),
103  'move to end w/thumbnails' => array('1,2,3,4', '2,3,4,1', true, array(
104  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
105  '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>',
106  )),
107  'move to front w/thumbnails' => array('1,2,3,4', '4,1,2,3', true, array(
108  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
109  '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>',
110  )),
111  'keep last w/thumbnails' => array('1,2,3,4', '4', true, array(
112  'live' => '<img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> <img src="/tmb/4.png" />',
113  'differences' => '<del><img src="/tmb/1.png" /> <img src="/tmb/2.png" /> <img src="/tmb/3.png" /> </del><img src="/tmb/4.png" />',
114  )),
115  );
116  }
117 
126  public function prepareFileReferenceDifferencesAreCorrect($fileFileReferenceList, $versionFileReferenceList, $useThumbnails, array $expected = null) {
127  $liveFileReferences = $this->getFileReferenceProphecies($fileFileReferenceList);
128  $versionFileReferences = $this->getFileReferenceProphecies($versionFileReferenceList);
129 
130  $result = $this->subject->_call(
131  'prepareFileReferenceDifferences',
132  $liveFileReferences,
133  $versionFileReferences,
134  $useThumbnails
135  );
136 
137  $this->assertSame($expected, $result);
138  }
139 
144  protected function getFileReferenceProphecies($idList) {
145  $fileReferenceProphecies = array();
146  $ids = GeneralUtility::trimExplode(',', $idList, true);
147 
148  foreach ($ids as $id) {
150  }
151 
153  }
154 
159  protected function getFileReferenceProphecy($id) {
160  if (isset($this->fileReferenceProphecies[$id])) {
161  return $this->fileReferenceProphecies[$id];
162  }
163 
164  $processedFileProphecy = $this->prophesize(ProcessedFile::class);
165  $processedFileProphecy->getPublicUrl(Argument::cetera())->willReturn('/tmb/' . $id . '.png');
166 
167  $fileProphecy = $this->prophesize(File::class);
168  $fileProphecy->process(Argument::cetera())->willReturn($processedFileProphecy->reveal());
169 
170  $fileReferenceProphecy = $this->prophesize(FileReference::class);
171  $fileReferenceProphecy->getUid()->willReturn($id);
172  $fileReferenceProphecy->getOriginalFile()->willReturn($fileProphecy->reveal());
173  $fileReferenceProphecy->getPublicUrl(Argument::cetera())->willReturn('/img/' . $id . '.png');
174 
175  $this->fileReferenceProphecies[$id] = $fileReferenceProphecy->reveal();
176  return $this->fileReferenceProphecies[$id];
177  }
178 
179 }