‪TYPO3CMS  9.5
OpenDocumentServiceTest.php
Go to the documentation of this file.
1 <?php
2 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 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪OpenDocumentServiceTest extends UnitTestCase
26 {
30  protected ‪$subject;
31 
35  protected ‪$backendUser;
36 
40  protected function ‪setUp()
41  {
42  $this->backendUser = $this->prophesize(BackendUserAuthentication::class);
43  $this->subject = new ‪OpenDocumentService($this->backendUser->reveal());
44  }
45 
49  public function ‪getsOpenDocumentsFromUserSession()
50  {
51  $this->backendUser->getModuleData('FormEngine', 'ses')->willReturn([
52  [
53  'identifier1' => [ 'data1' ],
54  'identifier2' => [ 'data2' ],
55  ],
56  'identifier2',
57  ]);
58 
59  $openDocuments = $this->subject->getOpenDocuments();
60  $expected = [
61  'identifier1' => [ 'data1' ],
62  'identifier2' => [ 'data2' ],
63  ];
64 
65  $this->assertEquals($expected, $openDocuments);
66  }
67 
72  {
73  $this->backendUser->getModuleData('FormEngine', 'ses')->willReturn();
74 
75  $openDocuments = $this->subject->getOpenDocuments();
76 
77  $this->assertEquals([], $openDocuments);
78  }
79 
84  {
85  $this->backendUser->getModuleData('opendocs::recent')->willReturn([
86  'identifier1' => [ 'data1' ],
87  ]);
88 
89  $recentDocuments = $this->subject->getRecentDocuments();
90  $expected = [
91  'identifier1' => [ 'data1' ],
92  ];
93 
94  $this->assertEquals($expected, $recentDocuments);
95  }
96 
101  {
102  $this->backendUser->getModuleData('opendocs::recent')->willReturn();
103 
104  $recentDocuments = $this->subject->getRecentDocuments();
105 
106  $this->assertEquals([], $recentDocuments);
107  }
108 
112  public function ‪closesDocument()
113  {
114  $this->backendUser->getModuleData('FormEngine', 'ses')->willReturn([
115  [
116  'identifier8' => [ 'data8' ],
117  'identifier9' => [ 'data9' ],
118  ],
119  'identifier9',
120  ]);
121  $this->backendUser->getModuleData('opendocs::recent')->willReturn([
122  'identifier8' => [ 'data8' ],
123  'identifier7' => [ 'data7' ],
124  'identifier6' => [ 'data6' ],
125  'identifier5' => [ 'data5' ],
126  'identifier4' => [ 'data4' ],
127  'identifier3' => [ 'data3' ],
128  'identifier2' => [ 'data2' ],
129  'identifier1' => [ 'data1' ],
130  ]);
131 
132  $expectedOpenDocumentsData = [
133  [
134  'identifier8' => [ 'data8' ],
135  ],
136  'identifier9',
137  ];
138  $this->backendUser->pushModuleData('FormEngine', $expectedOpenDocumentsData)->shouldBeCalled();
139 
140  $expectedRecentDocumentsData = [
141  'identifier9' => [ 'data9' ],
142  'identifier8' => [ 'data8' ],
143  'identifier7' => [ 'data7' ],
144  'identifier6' => [ 'data6' ],
145  'identifier5' => [ 'data5' ],
146  'identifier4' => [ 'data4' ],
147  'identifier3' => [ 'data3' ],
148  'identifier2' => [ 'data2' ],
149  ];
150  $this->backendUser->pushModuleData('opendocs::recent', $expectedRecentDocumentsData)->shouldBeCalled();
151 
152  $this->subject->closeDocument('identifier9');
153  $this->subject->closeDocument('identifier9');
154  $this->subject->closeDocument('unknownIdentifier');
155  }
156 }
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\handlesUserSessionWithoutRecentDocuments
‪handlesUserSessionWithoutRecentDocuments()
Definition: OpenDocumentServiceTest.php:98
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\$backendUser
‪BackendUserAuthentication Prophecy Prophecy ObjectProphecy $backendUser
Definition: OpenDocumentServiceTest.php:33
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest
Definition: OpenDocumentServiceTest.php:26
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\handlesUserSessionWithoutOpenDocuments
‪handlesUserSessionWithoutOpenDocuments()
Definition: OpenDocumentServiceTest.php:69
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\setUp
‪setUp()
Definition: OpenDocumentServiceTest.php:38
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\getsOpenDocumentsFromUserSession
‪getsOpenDocumentsFromUserSession()
Definition: OpenDocumentServiceTest.php:47
‪TYPO3\CMS\Opendocs\Service\OpenDocumentService
Definition: OpenDocumentService.php:25
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\closesDocument
‪closesDocument()
Definition: OpenDocumentServiceTest.php:110
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\getsRecentDocumentsFromUserSession
‪getsRecentDocumentsFromUserSession()
Definition: OpenDocumentServiceTest.php:81
‪TYPO3\CMS\Opendocs\Tests\Unit\Service
Definition: OpenDocumentServiceTest.php:3
‪TYPO3\CMS\Opendocs\Tests\Unit\Service\OpenDocumentServiceTest\$subject
‪OpenDocumentService $subject
Definition: OpenDocumentServiceTest.php:29